diff options
author | Alex Yatskov <alex@foosoft.net> | 2016-09-11 12:40:45 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2016-09-11 12:40:45 -0700 |
commit | 8eb43c93d920fb6d940cba2c1f46a9876d9087e9 (patch) | |
tree | 3a34db3a42c232568d77983eb164e42bd86fa8f5 | |
parent | d5ea03171ea997d6734e6d31197c7f233fff7084 (diff) |
Cleanup
-rw-r--r-- | ext/bg/js/translator.js | 40 | ||||
-rw-r--r-- | ext/bg/js/yomichan.js | 2 |
2 files changed, 15 insertions, 27 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js index 6b08f485..e18d5a3b 100644 --- a/ext/bg/js/translator.js +++ b/ext/bg/js/translator.js @@ -25,13 +25,12 @@ class Translator { this.deinflector = new Deinflector(); } - loadData({loadEnamDict=true}, callback) { + loadData() { if (this.loaded) { - callback(); - return; + return Promise.resolve(); } - loadJson('bg/data/rules.json').then(rules => { + return loadJson('bg/data/rules.json').then(rules => { this.deinflector.setRules(rules); return loadJson('bg/data/tags.json'); }).then(tagMeta => { @@ -39,18 +38,15 @@ class Translator { return this.dictionary.existsDb(); }).then(exists => { this.dictionary.initDb(); - if (exists) { - return Promise.resolve(); + if (!exists) { + return Promise.all([ + this.dictionary.importKanjiDict('bg/data/kanjidic/index.json'), + this.dictionary.importTermDict('bg/data/edict/index.json'), + this.dictionary.importTermDict('bg/data/enamdict/index.json') + ]); } - - return Promise.all([ - this.dictionary.importKanjiDict('bg/data/kanjidic/index.json'), - this.dictionary.importTermDict('bg/data/edict/index.json'), - this.dictionary.importTermDict('bg/data/enamdict/index.json') - ]); }).then(() => { this.loaded = true; - callback(); }); } @@ -194,12 +190,10 @@ class Translator { }); } - processKanji(entries) { - const results = []; - - for (const entry of entries) { + processKanji(definitions) { + for (const definition of definitions) { const tagItems = []; - for (const tag of entry.tags) { + for (const tag of definition.tags) { const tagItem = { name: tag, class: 'default', @@ -211,16 +205,10 @@ class Translator { tagItems.push(tagItem); } - results.push({ - character: entry.character, - kunyomi: entry.kunyomi, - onyomi: entry.onyomi, - glossary: entry.glossary, - tags: Translator.sortTags(tagItems) - }); + definition.tags = Translator.sortTags(tagItems); } - return results; + return definitions; } applyTagMeta(tag) { diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index 11f348bf..d9d4234d 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -101,7 +101,7 @@ class Yomichan { break; case 'loading': chrome.browserAction.setBadgeText({text: '...'}); - this.translator.loadData({loadEnamDict: this.options.loadEnamDict}, () => this.setState('enabled')); + this.translator.loadData().then(() => this.setState('enabled')); break; } |