From 5bebf3ed2cff5c460afe6f0d3df56f26f12ae240 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Apr 2016 18:38:29 -0700 Subject: Revert "Support switching between edict and enamdict" This reverts commit f079db0471424a873f22315c7911571d467e97ad. --- ext/bg/js/dictionary.js | 39 +++++++++++++++++++++++++-------------- ext/bg/js/templates.js | 2 +- ext/bg/js/translator.js | 14 +++++++------- ext/bg/js/yomichan.js | 4 ++-- 4 files changed, 35 insertions(+), 24 deletions(-) (limited to 'ext/bg') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index b91e53bf..6870601e 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -31,24 +31,35 @@ class Dictionary { this.kanjiDicts[name] = dict; } - findTerm(term, dict) { - const db = this.termDicts[dict]; - const indices = db.indices[term] || []; - - return indices.map(index => { - const [e, r, t, ...g] = db.defs[index]; - return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')}; - }); + findTerm(term) { + let results = []; + + for (const name in this.termDicts) { + const dict = this.termDicts[name]; + const indices = dict.indices[term] || []; + + results = results.concat( + indices.map(index => { + const [e, r, t, ...g] = dict.defs[index]; + return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')}; + }) + ); + } + + return results; } - findKanji(kanji, dict) { - const def = this.termDicts[dict][kanji]; + findKanji(kanji) { + const results = []; - if (def) { - const [c, k, o, g] = def; - return {id: index, character: c, kunyomi: k, onyomi: o, glossary: g}; + for (const name in this.termDicts) { + const def = this.termDicts[name][kanji]; + if (def) { + const [c, k, o, g] = def; + results.push({id: index, character: c, kunyomi: k, onyomi: o, glossary: g}); + } } - return null; + return results; } } diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 0d32b7da..ca743e00 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -12,7 +12,7 @@ templates['header.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(c return "\n\n \n \n \n \n \n \n
\n \n
\n"; + + "/css/popup.css\">\n \n \n
\n \n
\n"; },"useData":true}); templates['kanji.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 454d5079..46d63ed0 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -63,14 +63,14 @@ class Translator { } } - findTerm(text, dict) { + findTerm(text) { const groups = {}; for (let i = text.length; i > 0; --i) { const term = text.slice(0, i); const dfs = this.deinflector.deinflect(term, t => { const tags = []; - for (const d of this.dictionary.findTerm(t, dict)) { + for (const d of this.dictionary.findTerm(t)) { tags.push(d.tags); } @@ -79,7 +79,7 @@ class Translator { if (dfs !== null) { for (const df of dfs) { - this.processTerm(dict, groups, df.source, df.tags, df.rules, df.root); + this.processTerm(groups, df.source, df.tags, df.rules, df.root); } } } @@ -125,13 +125,13 @@ class Translator { return {results: results, length: length}; } - findKanji(text, dict) { + findKanji(text) { let results = []; const processed = {}; for (const c of text) { if (!processed.has(c)) { - results = results.concat(this.dictionary.findKanji(c, dict)); + results = results.concat(this.dictionary.findKanji(c)); processed[c] = true; } } @@ -139,8 +139,8 @@ class Translator { return results; } - processTerm(dict, groups, source, tags, rules=[], root='') { - for (const entry of this.dictionary.findTerm(root, dict)) { + processTerm(groups, source, tags, rules=[], root='') { + for (const entry of this.dictionary.findTerm(root)) { if (entry.id in groups) { continue; } diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 719aaed8..a66c1244 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -39,8 +39,8 @@ class Yomichan { onMessage(request, sender, callback) { const {action, data} = request; const handlers = { - findKanji: ({text, dict}) => this.translator.onFindKanji(text, dict), - findTerm: ({text, dict}) => this.translator.findTerm(text, dict), + findKanji: ({text}) => this.translator.onFindKanji(text), + findTerm: ({text}) => this.translator.findTerm(text), getState: () => this.state, getOptions: () => this.options, renderText: ({data, template}) => Handlebars.templates[template](data) -- cgit v1.2.3