diff options
-rw-r--r-- | ext/bg/js/yomichan.js | 42 | ||||
-rw-r--r-- | ext/fg/js/driver.js | 8 |
2 files changed, 13 insertions, 37 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index f6b1e611..d97dc586 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -26,16 +26,16 @@ class Yomichan { this.translator = new Translator(); this.anki = new AnkiNull(); this.options = null; - this.setState('disabled'); + this.setEnabled(false); chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this)); chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); - optionsLoad().then(options => { + this.translator.prepare().then(optionsLoad).then(options => { this.setOptions(options); if (this.options.general.autoStart) { - this.setState('loading'); + this.setEnabled(true); } }); } @@ -58,37 +58,13 @@ class Yomichan { } onBrowserAction() { - switch (this.state) { - case 'disabled': - this.setState('loading'); - break; - case 'enabled': - this.setState('disabled'); - break; - } + this.setEnabled(!this.enabled); } - setState(state) { - if (this.state === state) { - return; - } - - this.state = state; - - switch (state) { - case 'disabled': - chrome.browserAction.setBadgeText({text: 'off'}); - break; - case 'enabled': - chrome.browserAction.setBadgeText({text: ''}); - break; - case 'loading': - chrome.browserAction.setBadgeText({text: '...'}); - this.translator.prepare().then(this.setState('enabled')); - break; - } - - this.tabInvokeAll('setEnabled', this.state === 'enabled'); + setEnabled(enabled) { + this.enabled = enabled; + this.tabInvokeAll('setEnabled', this.enabled); + chrome.browserAction.setBadgeText({text: enabled ? '' : 'off'}); } setOptions(options) { @@ -154,7 +130,7 @@ class Yomichan { } api_getEnabled({callback}) { - callback({result: this.state === 'enabled'}); + callback({result: this.enabled}); } api_getOptions({callback}) { diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js index e595b350..974c4f28 100644 --- a/ext/fg/js/driver.js +++ b/ext/fg/js/driver.js @@ -34,8 +34,8 @@ class Driver { window.addEventListener('keydown', this.onKeyDown.bind(this)); window.addEventListener('resize', e => this.searchClear()); - getOptions().then(opts => { - this.options = opts; + getOptions().then(options => { + this.options = options; return isEnabled(); }).then(enabled => { this.enabled = enabled; @@ -208,8 +208,8 @@ class Driver { this.lastTextSource = null; } - api_setOptions(opts) { - this.options = opts; + api_setOptions(options) { + this.options = options; } api_setEnabled(enabled) { |