summaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-05 22:18:55 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-05 22:18:55 -0700
commit721a4dc661fe85768ebdb57b7d4caa5f9c485372 (patch)
tree74224c9138e91f34d720f3e9815cae1da291affe /ext/bg/js/yomichan.js
parent8774c783f6cb3e72e837ad335f78df0ca08f24e5 (diff)
WIP
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js26
1 files changed, 20 insertions, 6 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 2e4552a1..5f330e24 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -23,9 +23,12 @@ class Yomichan {
this.translator = new Translator();
this.updateState('disabled');
+ this.updateOptions({});
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this));
+
+ loadOptions((opts) => this.updateOptions(opts));
}
onMessage(request, sender, callback) {
@@ -37,11 +40,9 @@ class Yomichan {
renderTemplate: ({data, template}) => Handlebars.templates[template](data)
}[action];
- if (handler !== null) {
- const result = handler.call(this, data);
- if (callback !== null) {
- callback(result);
- }
+ const result = handler.call(this, data);
+ if (callback !== null) {
+ callback(result);
}
}
@@ -57,6 +58,10 @@ class Yomichan {
}
updateState(state) {
+ if (this.state === state) {
+ return;
+ }
+
this.state = state;
switch (state) {
@@ -72,9 +77,18 @@ class Yomichan {
break;
}
+ Yomichan.notifyChange('state', this.state);
+ }
+
+ updateOptions(options) {
+ this.options = sanitizeOptions(options);
+ Yomichan.notifyChange('options', this.options);
+ }
+
+ static notifyChange(name, value) {
chrome.tabs.query({}, (tabs) => {
for (const tab of tabs) {
- chrome.tabs.sendMessage(tab.id, this.state, () => null);
+ chrome.tabs.sendMessage(tab.id, {name: name, value: value}, () => null);
}
});
}