aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/yomichan.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/yomichan.js')
-rw-r--r--ext/bg/js/yomichan.js22
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}) {