diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index ee4f5946..14f90d29 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -110,6 +110,32 @@ function dictTermsUndupe(definitions) { return definitionsUnique; } +function dictTermsCompressTags(definitions) { + let lastDictionary = ''; + let lastPos = ''; + + for (const definition of definitions) { + const dictionary = JSON.stringify(definition.tags.filter(tag => tag.category === 'dictionary').map(tag => tag.name).sort()); + const pos = JSON.stringify(definition.tags.filter(tag => tag.category === 'pos').map(tag => tag.name).sort()); + + const filterOutCategories = []; + + if (lastDictionary === dictionary) { + filterOutCategories.push('dictionary'); + } else { + lastDictionary = dictionary; + } + + if (lastPos === pos) { + filterOutCategories.push('pos'); + } else { + lastPos = pos; + } + + definition.tags = definition.tags.filter(tag => !filterOutCategories.includes(tag.category)); + } +} + function dictTermsGroup(definitions, dictionaries) { const groups = {}; for (const definition of definitions) { diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index b49c32da..eef893c7 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -139,7 +139,8 @@ function optionsSetDefaults(options) { popupWidth: 400, popupHeight: 250, popupOffset: 10, - showGuide: true + showGuide: true, + compactTags: false }, scanning: { diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js index 6016b38a..f59c3ad0 100644 --- a/ext/bg/js/settings.js +++ b/ext/bg/js/settings.js @@ -22,6 +22,7 @@ async function formRead() { const optionsNew = $.extend(true, {}, optionsOld); optionsNew.general.showGuide = $('#show-usage-guide').prop('checked'); + optionsNew.general.compactTags = $('#compact-tags').prop('checked'); optionsNew.general.resultOutputMode = $('#result-output-mode').val(); optionsNew.general.audioSource = $('#audio-playback-source').val(); optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val()); @@ -125,6 +126,7 @@ async function onReady() { const options = await optionsLoad(); $('#show-usage-guide').prop('checked', options.general.showGuide); + $('#compact-tags').prop('checked', options.general.compactTags); $('#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/templates.js b/ext/bg/js/templates.js index 19c49337..e8bd43e9 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -206,30 +206,16 @@ templates['model.html'] = template({"1":function(container,depth0,helpers,partia templates['terms.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : (container.nullContext || {}); - return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.only : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + return ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.only : depth0),{"name":"if","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : ""); },"2":function(container,depth0,helpers,partials,data) { var stack1; - return "
\n (" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.only : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + " only)\n
\n"; -},"3":function(container,depth0,helpers,partials,data) { - var stack1; - - return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "") - + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "\n"; -},"4":function(container,depth0,helpers,partials,data) { - return ", "; -},"6":function(container,depth0,helpers,partials,data) { - var stack1; - return "
\n" - + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; -},"7":function(container,depth0,helpers,partials,data) { +},"3":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; return " " + alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper))) + "\n"; +},"5":function(container,depth0,helpers,partials,data) { + var stack1; + + return "
\n (" + + ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.only : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + " only)\n
\n"; +},"6":function(container,depth0,helpers,partials,data) { + var stack1; + + return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "") + + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.last),{"name":"unless","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "\n"; +},"7":function(container,depth0,helpers,partials,data) { + return ", "; },"9":function(container,depth0,helpers,partials,data) { var stack1; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 99344b95..e307efc0 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -37,6 +37,7 @@ class Translator { } async findTermsGrouped(text, dictionaries, alphanumeric) { + const options = await apiOptionsGet(); const titles = Object.keys(dictionaries); const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric); @@ -45,6 +46,12 @@ class Translator { await this.buildTermFrequencies(definition, titles); } + if (options.general.compactTags) { + for (const definition of definitionsGrouped) { + dictTermsCompressTags(definition.definitions); + } + } + return {length, definitions: definitionsGrouped}; } @@ -120,6 +127,12 @@ class Translator { await this.buildTermFrequencies(definition, titles); } + if (options.general.compactTags) { + for (const definition of definitionsMerged) { + dictTermsCompressTags(definition.definitions); + } + } + return {length, definitions: dictTermsSort(definitionsMerged)}; } diff --git a/ext/bg/settings.html b/ext/bg/settings.html index 6274f3cb..d4b71932 100644 --- a/ext/bg/settings.html +++ b/ext/bg/settings.html @@ -35,6 +35,10 @@ +
+ +
+
diff --git a/tmpl/terms.html b/tmpl/terms.html index 72bf9824..e037c544 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -1,4 +1,11 @@ {{#*inline "definition"}} +{{#if tags}} +
+ {{#each tags}} + {{name}} + {{/each}} +
+{{/if}} {{#if only}}
( @@ -8,13 +15,6 @@ only)
{{/if}} -{{#if tags}} -
- {{#each tags}} - {{name}} - {{/each}} -
-{{/if}} {{#if glossary.[1]}}