summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/dictionary.js24
-rw-r--r--ext/bg/js/options.js1
-rw-r--r--ext/bg/js/settings.js2
-rw-r--r--ext/bg/js/translator.js22
-rw-r--r--ext/bg/settings.html4
5 files changed, 34 insertions, 19 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index fea5f3e5..368bb18d 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -245,22 +245,26 @@ function dictTermsMergeByGloss(result, definitions, appendTo, mergedIndices) {
result.expression.add(definition.expression);
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) {
if (!definitionsByGloss[gloss].definitionTags.find(existingTag => existingTag.name === tag.name)) {
definitionsByGloss[gloss].definitionTags.push(tag);
}
}
- for (const tag of definition.termTags) {
- result.expressions.get(definition.expression).get(definition.reading).add(tag);
+ if (!appendTo) {
+ // 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);
+ }
+ }
}
}
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 925c8432..373a1a6b 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -185,6 +185,7 @@ function optionsSetDefaults(options) {
enable: true,
audioSource: 'jpod101',
audioVolume: 100,
+ autoPlayAudio: false,
resultOutputMode: 'group',
debugInfo: false,
maxResults: 32,
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index dcc9c43d..7bc6a651 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -24,6 +24,7 @@ async function formRead() {
optionsNew.general.showGuide = $('#show-usage-guide').prop('checked');
optionsNew.general.compactTags = $('#compact-tags').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.audioSource = $('#audio-playback-source').val();
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
@@ -153,6 +154,7 @@ async function onReady() {
$('#show-usage-guide').prop('checked', options.general.showGuide);
$('#compact-tags').prop('checked', options.general.compactTags);
$('#compact-glossaries').prop('checked', options.general.compactGlossaries);
+ $('#auto-play-audio').prop('checked', options.general.autoPlayAudio);
$('#result-output-mode').val(options.general.resultOutputMode);
$('#audio-playback-source').val(options.general.audioSource);
$('#audio-playback-volume').val(options.general.audioVolume);
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 005dd5de..c6af1f4e 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -75,9 +75,11 @@ class Translator {
const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary);
for (const definition of rawDefinitionsBySequence) {
- const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
- tags.push(dictTagBuildSource(definition.dictionary));
- definition.definitionTags = tags;
+ const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
+ definitionTags.push(dictTagBuildSource(definition.dictionary));
+ definition.definitionTags = definitionTags;
+ const termTags = await this.expandTags(definition.termTags, definition.dictionary);
+ definition.termTags = termTags;
}
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
@@ -91,9 +93,11 @@ class Translator {
for (const reading of result.expressions.get(expression).keys()) {
for (const definition of await this.database.findTermsExact(expression, reading, secondarySearchTitles)) {
- const tags = await this.expandTags(definition.definitionTags, definition.dictionary);
- tags.push(dictTagBuildSource(definition.dictionary));
- definition.definitionTags = tags;
+ const definitionTags = await this.expandTags(definition.definitionTags, definition.dictionary);
+ definitionTags.push(dictTagBuildSource(definition.dictionary));
+ definition.definitionTags = definitionTags;
+ const termTags = await this.expandTags(definition.termTags, definition.dictionary);
+ definition.termTags = termTags;
secondarySearchResults.push(definition);
}
}
@@ -113,11 +117,11 @@ class Translator {
const expressions = [];
for (const expression of result.expressions.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({
expression: expression,
reading: reading,
- termTags: dictTagsSort(tags),
+ termTags: dictTagsSort(termTags),
termFrequency: (score => {
if (score > 0) {
return 'popular';
@@ -126,7 +130,7 @@ class Translator {
} else {
return 'normal';
}
- })(tags.map(tag => tag.score).reduce((p, v) => p + v, 0))
+ })(termTags.map(tag => tag.score).reduce((p, v) => p + v, 0))
});
}
}
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index 65043d44..c77f550c 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -44,6 +44,10 @@
</div>
<div class="checkbox">
+ <label><input type="checkbox" id="auto-play-audio"> Play audio automatically</label>
+ </div>
+
+ <div class="checkbox">
<label><input type="checkbox" id="show-advanced-options"> Show advanced options</label>
</div>