diff options
-rw-r--r-- | ext/jp/api.js | 12 | ||||
-rw-r--r-- | ext/jp/translator.js | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/ext/jp/api.js b/ext/jp/api.js index 95c2f7e3..216b961f 100644 --- a/ext/jp/api.js +++ b/ext/jp/api.js @@ -36,6 +36,13 @@ function onMessage(request, sender, callback) { } } +function onInit() { + chrome.runtime.onMessage.addListener(onMessage); + + const res1 = window.trans.findTerm('食べられない'); + const res2 = window.trans.findTerm('作られている'); +} + (() => { const res = { rules: 'jp/data/rules.json', @@ -44,8 +51,5 @@ function onMessage(request, sender, callback) { kanjidic: 'jp/data/kanjidic.json' }; - window.trans = new Translator( - res, - () => chrome.runtime.onMessage.addListener(onMessage) - ); + window.trans = new Translator(res, onInit); })(); diff --git a/ext/jp/translator.js b/ext/jp/translator.js index b3e96538..79f8515a 100644 --- a/ext/jp/translator.js +++ b/ext/jp/translator.js @@ -98,6 +98,10 @@ class Translator { processTerm(groups, source, rules=[], root='') { for (const entry of this.dictionary.findTerm(root || source)) { + if (entry.id in groups) { + continue; + } + groups[entry.id] = { expression: entry.expression, reading: entry.reading, |