Merge branch 'dev'
This commit is contained in:
commit
68cdd7d85b
@ -245,22 +245,26 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
|
|||||||
result.expression.add(definition.expression);
|
result.expression.add(definition.expression);
|
||||||
result.reading.add(definition.reading);
|
result.reading.add(definition.reading);
|
||||||
|
|
||||||
// result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ]
|
|
||||||
if (!result.expressions.has(definition.expression)) {
|
|
||||||
result.expressions.set(definition.expression, new Map());
|
|
||||||
}
|
|
||||||
if (!result.expressions.get(definition.expression).has(definition.reading)) {
|
|
||||||
result.expressions.get(definition.expression).set(definition.reading, new Set());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const tag of definition.definitionTags) {
|
for (const tag of definition.definitionTags) {
|
||||||
if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) {
|
if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) {
|
||||||
definitionsByGloss[gloss].definitionTags.push(tag);
|
definitionsByGloss[gloss].definitionTags.push(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const tag of definition.termTags) {
|
if (!appendTo) {
|
||||||
result.expressions.get(definition.expression).get(definition.reading).add(tag);
|
// result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ]
|
||||||
|
if (!result.expressions.has(definition.expression)) {
|
||||||
|
result.expressions.set(definition.expression, new Map());
|
||||||
|
}
|
||||||
|
if (!result.expressions.get(definition.expression).has(definition.reading)) {
|
||||||
|
result.expressions.get(definition.expression).set(definition.reading, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const tag of definition.termTags) {
|
||||||
|
if (!result.expressions.get(definition.expression).get(definition.reading).find(existingTag => existingTag.name === tag.name)) {
|
||||||
|
result.expressions.get(definition.expression).get(definition.reading).push(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +185,7 @@ function optionsSetDefaults(options) {
|
|||||||
enable: true,
|
enable: true,
|
||||||
audioSource: 'jpod101',
|
audioSource: 'jpod101',
|
||||||
audioVolume: 100,
|
audioVolume: 100,
|
||||||
|
autoPlayAudio: false,
|
||||||
resultOutputMode: 'group',
|
resultOutputMode: 'group',
|
||||||
debugInfo: false,
|
debugInfo: false,
|
||||||
maxResults: 32,
|
maxResults: 32,
|
||||||
|
@ -24,6 +24,7 @@ async function formRead() {
|
|||||||
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
|
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
|
||||||
optionsNew.general.compactTags = $('#compact-tags').prop('checked');
|
optionsNew.general.compactTags = $('#compact-tags').prop('checked');
|
||||||
optionsNew.general.compactGlossaries = $('#compact-glossaries').prop('checked');
|
optionsNew.general.compactGlossaries = $('#compact-glossaries').prop('checked');
|
||||||
|
optionsNew.general.autoPlayAudio = $('#auto-play-audio').prop('checked');
|
||||||
optionsNew.general.resultOutputMode = $('#result-output-mode').val();
|
optionsNew.general.resultOutputMode = $('#result-output-mode').val();
|
||||||
optionsNew.general.audioSource = $('#audio-playback-source').val();
|
optionsNew.general.audioSource = $('#audio-playback-source').val();
|
||||||
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
|
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
|
||||||
@ -153,6 +154,7 @@ async function onReady() {
|
|||||||
$('#show-usage-guide').prop('checked', options.general.showGuide);
|
$('#show-usage-guide').prop('checked', options.general.showGuide);
|
||||||
$('#compact-tags').prop('checked', options.general.compactTags);
|
$('#compact-tags').prop('checked', options.general.compactTags);
|
||||||
$('#compact-glossaries').prop('checked', options.general.compactGlossaries);
|
$('#compact-glossaries').prop('checked', options.general.compactGlossaries);
|
||||||
|
$('#auto-play-audio').prop('checked', options.general.autoPlayAudio);
|
||||||
$('#result-output-mode').val(options.general.resultOutputMode);
|
$('#result-output-mode').val(options.general.resultOutputMode);
|
||||||
$('#audio-playback-source').val(options.general.audioSource);
|
$('#audio-playback-source').val(options.general.audioSource);
|
||||||
$('#audio-playback-volume').val(options.general.audioVolume);
|
$('#audio-playback-volume').val(options.general.audioVolume);
|
||||||
|
@ -75,9 +75,11 @@ class Translator {
|
|||||||
const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary);
|
const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary);
|
||||||
|
|
||||||
for (const definition of rawDefinitionsBySequence) {
|
for (const definition of rawDefinitionsBySequence) {
|
||||||
const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
|
const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
|
||||||
tags.push(dictTagBuildSource(definition.dictionary));
|
definitionTags.push(dictTagBuildSource(definition.dictionary));
|
||||||
definition.definitionTags = tags;
|
definition.definitionTags = definitionTags;
|
||||||
|
const termTags = await this.expandTags(definition.termTags, definition.dictionary);
|
||||||
|
definition.termTags = termTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
|
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
|
||||||
@ -91,9 +93,11 @@ class Translator {
|
|||||||
|
|
||||||
for (const reading of result.expressions.get(expression).keys()) {
|
for (const reading of result.expressions.get(expression).keys()) {
|
||||||
for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) {
|
for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) {
|
||||||
const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
|
const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
|
||||||
tags.push(dictTagBuildSource(definition.dictionary));
|
definitionTags.push(dictTagBuildSource(definition.dictionary));
|
||||||
definition.definitionTags = tags;
|
definition.definitionTags = definitionTags;
|
||||||
|
const termTags = await this.expandTags(definition.termTags, definition.dictionary);
|
||||||
|
definition.termTags = termTags;
|
||||||
secondarySearchResults.push(definition);
|
secondarySearchResults.push(definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,11 +117,11 @@ class Translator {
|
|||||||
const expressions = [];
|
const expressions = [];
|
||||||
for (const expression of result.expressions.keys()) {
|
for (const expression of result.expressions.keys()) {
|
||||||
for (const reading of result.expressions.get(expression).keys()) {
|
for (const reading of result.expressions.get(expression).keys()) {
|
||||||
const tags = await this.expandTags(result.expressions.get(expression).get(reading), result.dictionary);
|
const termTags = result.expressions.get(expression).get(reading);
|
||||||
expressions.push({
|
expressions.push({
|
||||||
expression: expression,
|
expression: expression,
|
||||||
reading: reading,
|
reading: reading,
|
||||||
termTags: dictTagsSort(tags),
|
termTags: dictTagsSort(termTags),
|
||||||
termFrequency: (score => {
|
termFrequency: (score => {
|
||||||
if (score > 0) {
|
if (score > 0) {
|
||||||
return 'popular';
|
return 'popular';
|
||||||
@ -126,7 +130,7 @@ class Translator {
|
|||||||
} else {
|
} else {
|
||||||
return 'normal';
|
return 'normal';
|
||||||
}
|
}
|
||||||
})(tags.map(tag => tag.score).reduce((p, v) => p + v, 0))
|
})(termTags.map(tag => tag.score).reduce((p, v) => p + v, 0))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,10 @@
|
|||||||
<label><input type="checkbox" id="compact-glossaries"> Compact glossaries</label>
|
<label><input type="checkbox" id="compact-glossaries"> Compact glossaries</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="checkbox">
|
||||||
|
<label><input type="checkbox" id="auto-play-audio"> Play audio automatically</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
|
<label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
class DisplayFloat extends Display {
|
class DisplayFloat extends Display {
|
||||||
constructor() {
|
constructor() {
|
||||||
super($('#spinner'), $('#definitions'));
|
super($('#spinner'), $('#definitions'));
|
||||||
|
this.autoPlayAudioTimer = null;
|
||||||
|
|
||||||
$(window).on('message', utilAsync(this.onMessage.bind(this)));
|
$(window).on('message', utilAsync(this.onMessage.bind(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +56,10 @@ class DisplayFloat extends Display {
|
|||||||
this.kanjiShow(definitions, options, context);
|
this.kanjiShow(definitions, options, context);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearAutoPlayTimer: () => {
|
||||||
|
this.clearAutoPlayTimer();
|
||||||
|
},
|
||||||
|
|
||||||
orphaned: () => {
|
orphaned: () => {
|
||||||
this.onOrphaned();
|
this.onOrphaned();
|
||||||
}
|
}
|
||||||
@ -83,6 +89,18 @@ class DisplayFloat extends Display {
|
|||||||
super.onKeyDown(e);
|
super.onKeyDown(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoPlayAudio() {
|
||||||
|
this.clearAutoPlayTimer();
|
||||||
|
this.autoPlayAudioTimer = window.setTimeout(() => super.autoPlayAudio(), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearAutoPlayTimer() {
|
||||||
|
if (this.autoPlayAudioTimer) {
|
||||||
|
window.clearTimeout(this.autoPlayAudioTimer);
|
||||||
|
this.autoPlayAudioTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.yomichan_display = new DisplayFloat();
|
window.yomichan_display = new DisplayFloat();
|
||||||
|
@ -254,6 +254,7 @@ class Frontend {
|
|||||||
searchClear() {
|
searchClear() {
|
||||||
docImposterDestroy();
|
docImposterDestroy();
|
||||||
this.popup.hide();
|
this.popup.hide();
|
||||||
|
this.popup.clearAutoPlayTimer();
|
||||||
|
|
||||||
if (this.options.scanning.selectText && this.textSourceLast) {
|
if (this.options.scanning.selectText && this.textSourceLast) {
|
||||||
this.textSourceLast.deselect();
|
this.textSourceLast.deselect();
|
||||||
|
@ -125,6 +125,12 @@ class Popup {
|
|||||||
this.invokeApi('kanjiShow', {definitions, options, context});
|
this.invokeApi('kanjiShow', {definitions, options, context});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearAutoPlayTimer() {
|
||||||
|
if (this.injected) {
|
||||||
|
this.invokeApi('clearAutoPlayTimer');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
invokeApi(action, params={}) {
|
invokeApi(action, params={}) {
|
||||||
this.container.contentWindow.postMessage({action, params}, '*');
|
this.container.contentWindow.postMessage({action, params}, '*');
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,7 @@ class Display {
|
|||||||
80: /* p */ () => {
|
80: /* p */ () => {
|
||||||
if (e.altKey) {
|
if (e.altKey) {
|
||||||
if ($('.entry').eq(this.index).data('type') === 'term') {
|
if ($('.entry').eq(this.index).data('type') === 'term') {
|
||||||
const expressionIndex = this.options.general.resultOutputMode === 'merge' ? 0 : -1;
|
this.audioPlay(this.definitions[this.index], this.firstExpressionIndex);
|
||||||
this.audioPlay(this.definitions[this.index], expressionIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -258,6 +257,10 @@ class Display {
|
|||||||
this.container.html(content);
|
this.container.html(content);
|
||||||
this.entryScrollIntoView(context && context.index || 0);
|
this.entryScrollIntoView(context && context.index || 0);
|
||||||
|
|
||||||
|
if (this.options.general.autoPlayAudio && this.options.general.audioSource !== 'disabled') {
|
||||||
|
this.autoPlayAudio();
|
||||||
|
}
|
||||||
|
|
||||||
$('.action-add-note').click(this.onNoteAdd.bind(this));
|
$('.action-add-note').click(this.onNoteAdd.bind(this));
|
||||||
$('.action-view-note').click(this.onNoteView.bind(this));
|
$('.action-view-note').click(this.onNoteView.bind(this));
|
||||||
$('.action-play-audio').click(this.onAudioPlay.bind(this));
|
$('.action-play-audio').click(this.onAudioPlay.bind(this));
|
||||||
@ -309,6 +312,10 @@ class Display {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoPlayAudio() {
|
||||||
|
this.audioPlay(this.definitions[0], this.firstExpressionIndex);
|
||||||
|
}
|
||||||
|
|
||||||
async adderButtonUpdate(modes, sequence) {
|
async adderButtonUpdate(modes, sequence) {
|
||||||
try {
|
try {
|
||||||
const states = await apiDefinitionsAddable(this.definitions, modes);
|
const states = await apiDefinitionsAddable(this.definitions, modes);
|
||||||
@ -422,6 +429,10 @@ class Display {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get firstExpressionIndex() {
|
||||||
|
return this.options.general.resultOutputMode === 'merge' ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
static clozeBuild(sentence, source) {
|
static clozeBuild(sentence, source) {
|
||||||
const result = {
|
const result = {
|
||||||
sentence: sentence.text.trim()
|
sentence: sentence.text.trim()
|
||||||
|
Loading…
Reference in New Issue
Block a user