summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-07-23 15:14:13 -0700
committerAlex Yatskov <alex@foosoft.net>2016-07-23 15:14:13 -0700
commit22d73228ca2899047bcf39a6a2e7146d68c69e0a (patch)
tree51a95db8157688e16d6f877b9417a33ac68386b2 /ext/bg/js
parent6d9b4392e2cd78b5e76e3b47cc3b8ca76d37129b (diff)
Cleanup
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/yomichan.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index e8bd07b6..5be24622 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -40,6 +40,8 @@ class Yomichan {
chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this));
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this));
+ chrome.tabs.onCreated.addListener(this.onTabReady.bind(this));
+ chrome.tabs.onUpdated.addListener(this.onTabReady.bind(this));
loadOptions((opts) => {
this.setOptions(opts);
@@ -66,6 +68,11 @@ class Yomichan {
return true;
}
+ onTabReady(tab) {
+ this.tabInvoke(tab, 'setOptions', this.options);
+ this.tabInvoke(tab, 'setEnabled', this.state === 'enabled');
+ }
+
onBrowserAction(tab) {
switch (this.state) {
case 'disabled':
@@ -97,26 +104,30 @@ class Yomichan {
break;
}
- this.notifyTabs('state', this.state);
+ this.tabInvokeAll('setEnabled', this.state === 'enabled');
}
setOptions(options) {
this.options = options;
- this.notifyTabs('options', this.options);
+ this.tabInvokeAll('setOptions', this.options);
}
getApiVersion() {
return 1;
}
- notifyTabs(name, value) {
+ tabInvokeAll(action, params) {
chrome.tabs.query({}, (tabs) => {
for (let tab of tabs) {
- chrome.tabs.sendMessage(tab.id, {name, value}, () => null);
+ this.tabInvoke(tab.id, action, params);
}
});
}
+ tabInvoke(tabId, action, params) {
+ chrome.tabs.sendMessage(tabId, {action, params}, () => null);
+ }
+
ankiInvokeSafe(action, params, pool, callback) {
this.api_getVersion({callback: (version) => {
if (version === this.getApiVersion()) {