diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-03-25 16:28:15 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-03-25 16:28:15 -0700 |
commit | bc2bf51a072af45ddc61a7f6b1c5cc3b94f8ad3e (patch) | |
tree | c05b144049f5bb9fcf89cb1b891980b27ea8bd80 /ext/bg | |
parent | b8d0788144974daab8d55c8de1af7515a291ba4f (diff) |
wip
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/popup.js | 4 | ||||
-rw-r--r-- | ext/bg/js/yomichan.js | 27 |
2 files changed, 24 insertions, 7 deletions
diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 5bc7def4..8577dd96 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -19,8 +19,8 @@ $(document).ready(() => { $('#open-search').click(() => commandExec('search')); - $('#open-options').click(() => chrome.runtime.openOptionsPage()); - $('#open-help').click(() => window.open('http://foosoft.net/projects/yomichan')); + $('#open-options').click(() => commandExec('options')); + $('#open-help').click(() => commandExec('help')); optionsLoad().then(options => { const toggle = $('#enable-search'); diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index e2deb2cd..1a34aba4 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -165,11 +165,28 @@ 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)); + const handlers = { + search: () => { + chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')}); + }, + + help: () => { + chrome.tabs.create({url: 'https://foosoft.net/projects/yomichan/'}); + }, + + options: () => { + chrome.runtime.openOptionsPage(); + }, + + toggle: () => { + this.options.general.enable = !this.options.general.enable; + optionsSave(this.options).then(() => this.optionsSet(this.options)); + } + }; + + const handler = handlers[command]; + if (handler) { + handler(); } } |