aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-04-06 20:48:36 -0700
committerAlex Yatskov <alex@foosoft.net>2016-04-06 20:48:36 -0700
commit7c9d64e95f19528f4618432ff6fa8632e4027b6f (patch)
tree83a371bf4a8f64beef711c23b718bb00ad46b573 /ext/bg/js
parent721a4dc661fe85768ebdb57b7d4caa5f9c485372 (diff)
Options now work
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/yomichan.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js
index 5f330e24..fe7007eb 100644
--- a/ext/bg/js/yomichan.js
+++ b/ext/bg/js/yomichan.js
@@ -23,24 +23,26 @@ 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);
- loadOptions((opts) => this.updateOptions(opts));
+ chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
+ chrome.browserAction.onClicked.addListener(this.onBrowserAction.bind(this));
+ });
}
onMessage(request, sender, callback) {
const {action, data} = request;
- const handler = {
- findKanji: ({text}) => this.translator.onFindKanji(text),
- findTerm: ({text}) => this.translator.findTerm(text),
- getState: () => this.state,
- renderTemplate: ({data, template}) => Handlebars.templates[template](data)
- }[action];
+ const handlers = {
+ findKanji: ({text}) => this.translator.onFindKanji(text),
+ findTerm: ({text}) => this.translator.findTerm(text),
+ getState: () => this.state,
+ getOptions: () => this.options,
+ renderText: ({data, template}) => Handlebars.templates[template](data)
+ };
- const result = handler.call(this, data);
+ const result = handlers[action].call(this, data);
if (callback !== null) {
callback(result);
}