diff options
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/translator.js | 17 | ||||
-rw-r--r-- | ext/bg/yomichan.js | 11 |
2 files changed, 14 insertions, 14 deletions
diff --git a/ext/bg/translator.js b/ext/bg/translator.js index 23d5d964..e8224320 100644 --- a/ext/bg/translator.js +++ b/ext/bg/translator.js @@ -19,13 +19,20 @@ class Translator { constructor() { + this.loaded = false; + this.paths = { + rules: 'bg/data/rules.json', + edict: 'bg/data/edict.csv', + enamdict: 'bg/data/enamdict.csv', + kanjidic: 'bg/data/kanjidic.csv' + }; + this.dictionary = new Dictionary(); this.deinflector = new Deinflector(); - this.initialized = false; } - loadData(paths, callback) { - if (this.initialized) { + loadData(callback) { + if (this.loaded) { callback(); return; } @@ -33,7 +40,7 @@ class Translator { const pendingLoads = []; for (const key of ['rules', 'edict', 'enamdict', 'kanjidic']) { pendingLoads.push(key); - Translator.loadData(paths[key], (response) => { + Translator.loadData(this.paths[key], (response) => { switch (key) { case 'rules': this.deinflector.setRules(JSON.parse(response)); @@ -49,7 +56,7 @@ class Translator { pendingLoads.splice(pendingLoads.indexOf(key), 1); if (pendingLoads.length === 0) { - this.initialized = true; + this.loaded = true; callback(); } }); diff --git a/ext/bg/yomichan.js b/ext/bg/yomichan.js index 43ee8761..2e4552a1 100644 --- a/ext/bg/yomichan.js +++ b/ext/bg/yomichan.js @@ -19,20 +19,13 @@ class Yomichan { constructor() { - this.res = { - rules: 'bg/data/rules.json', - edict: 'bg/data/edict.csv', - enamdict: 'bg/data/enamdict.csv', - kanjidic: 'bg/data/kanjidic.csv' - }; + Handlebars.partials = Handlebars.templates; this.translator = new Translator(); this.updateState('disabled'); chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this)); - - Handlebars.partials = Handlebars.templates; } onMessage(request, sender, callback) { @@ -75,7 +68,7 @@ class Yomichan { break; case 'loading': chrome.browserAction.setBadgeText({text: '...'}); - this.translator.loadData(this.res, () => this.updateState('enabled')); + this.translator.loadData(() => this.updateState('enabled')); break; } |