summaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js39
1 files changed, 18 insertions, 21 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 4c70bf0f..b1bf710f 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -26,18 +26,12 @@ class Yomichan {
this.translator = new Translator();
this.anki = new AnkiNull();
this.options = null;
- 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));
+ chrome.browserAction.onClicked.addListener(e => chrome.runtime.openOptionsPage());
- this.translator.prepare().then(optionsLoad).then(options => {
- this.setOptions(options);
- if (this.options.general.autoStart) {
- this.setEnabled(true);
- }
- });
+ this.translator.prepare().then(optionsLoad).then(this.setOptions.bind(this));
}
onInstalled(details) {
@@ -57,19 +51,26 @@ class Yomichan {
return true;
}
- onBrowserAction() {
- this.setEnabled(!this.enabled);
- }
-
- setEnabled(enabled) {
- this.enabled = enabled;
- this.tabInvokeAll('setEnabled', this.enabled);
- chrome.browserAction.setBadgeText({text: enabled ? '' : 'off'});
- }
+ // setEnabled(enabled) {
+ // this.enabled = enabled;
+ // this.tabInvokeAll('setEnabled', this.enabled);
+ // chrome.browserAction.setBadgeText({text: enabled ? '' : 'off'});
+ // }
setOptions(options) {
this.options = options;
+ let usable = false;
+ for (const title in options.dictionaries) {
+ if (options.dictionaries[title].enabled) {
+ usable = true;
+ break;
+ }
+ }
+
+ chrome.browserAction.setBadgeBackgroundColor({color: '#f0ad4e'});
+ chrome.browserAction.setBadgeText({text: usable ? '' : '!'});
+
if (options.anki.enable) {
this.anki = new AnkiConnect(this.options.anki.server);
} else {
@@ -132,10 +133,6 @@ class Yomichan {
return note;
}
- api_getEnabled({callback}) {
- callback({result: this.enabled});
- }
-
api_getOptions({callback}) {
promiseCallback(optionsLoad(), callback);
}