diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-03-18 13:00:29 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-03-18 13:00:29 -0700 |
commit | 57697ee2a09dd5ad0a567b7104e4a5ac9a4f1b23 (patch) | |
tree | 9b67ed5633c598eea26e1a2afb686f79bd682fdf /ext/bg/js/yomichan.js | |
parent | e782a4343251bb76c3b7d0bb4b788d7a6ac7756e (diff) |
polish and initial command support
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r-- | ext/bg/js/yomichan.js | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index a61be8be..3a42c594 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -25,12 +25,13 @@ window.yomichan = new class { this.anki = new AnkiNull(); this.options = null; - chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); - if (chrome.runtime.onInstalled) { - chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); - } - - this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)); + this.translator.prepare().then(optionsLoad).then(this.optionsSet.bind(this)).then(() => { + chrome.commands.onCommand.addListener(this.onCommand.bind(this)); + chrome.runtime.onMessage.addListener(this.onMessage.bind(this)); + if (chrome.runtime.onInstalled) { + chrome.runtime.onInstalled.addListener(this.onInstalled.bind(this)); + } + }); } optionsSet(options) { @@ -153,6 +154,15 @@ window.yomichan = new class { } } + onCommand(command) { + if (command === 'search') { + window.open(chrome.extension.getURL('/bg/search.html')); + } else if (command === 'toggle') { + this.options.general.enable = !this.options.general.enable; + optionsSave(this.options).then(() => this.optionsSet(this.options)); + } + } + onMessage(request, sender, callback) { const handlers = new class { api_optionsGet({callback}) { |