From f079db0471424a873f22315c7911571d467e97ad Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 17 Apr 2016 18:13:20 -0700 Subject: [PATCH] Support switching between edict and enamdict --- ext/bg/js/dictionary.js | 37 +++++++++++++------------------------ ext/bg/js/templates.js | 2 +- ext/bg/js/translator.js | 14 +++++++------- ext/bg/js/yomichan.js | 4 ++-- ext/fg/js/api.js | 4 ++-- ext/fg/js/client.js | 38 +++++++++++++++++++------------------- ext/fg/js/popup.js | 22 ++++++++++++++++++++++ util/tmpl/defs.html | 2 +- 8 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 ext/fg/js/popup.js diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 6870601e..b91e53bf 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -31,35 +31,24 @@ class Dictionary { this.kanjiDicts[name] = dict; } - findTerm(term) { - let results = []; + findTerm(term, dict) { + const db = this.termDicts[dict]; + const indices = db.indices[term] || []; - 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; + return indices.map(index => { + const [e, r, t, ...g] = db.defs[index]; + return {id: index, expression: e, reading: r, glossary: g, tags: t.split(' ')}; + }); } - findKanji(kanji) { - const results = []; + findKanji(kanji, dict) { + const def = this.termDicts[dict][kanji]; - 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}); - } + if (def) { + const [c, k, o, g] = def; + return {id: index, character: c, kunyomi: k, onyomi: o, glossary: g}; } - return results; + return null; } } diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 3388ec9b..46a4001f 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -11,7 +11,7 @@ templates['defs.html'] = template({"1":function(container,depth0,helpers,partial return "\n\n \n \n \n \n \n \n
\n \n
\n\n" + + "/css/popup.css\">\n \n \n
\n \n
\n\n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.defs : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n