diff options
Diffstat (limited to 'ext/bg/js')
-rw-r--r-- | ext/bg/js/display-window.js | 9 | ||||
-rw-r--r-- | ext/bg/js/popup.js | 7 | ||||
-rw-r--r-- | ext/bg/js/templates.js | 12 | ||||
-rw-r--r-- | ext/bg/js/util.js | 9 | ||||
-rw-r--r-- | ext/bg/js/yomichan.js | 22 |
5 files changed, 40 insertions, 19 deletions
diff --git a/ext/bg/js/display-window.js b/ext/bg/js/display-window.js index ad193c5b..8c732ddd 100644 --- a/ext/bg/js/display-window.js +++ b/ext/bg/js/display-window.js @@ -20,8 +20,13 @@ window.displayWindow = new class extends Display { constructor() { super($('#spinner'), $('#content')); - $('#search').click(this.onSearch.bind(this)); - window.wanakana.bind($('#query').get(0)); + + const search = $('#search'); + search.click(this.onSearch.bind(this)); + + const query = $('#query'); + query.on('input', () => search.prop('disabled', query.val().length === 0)); + window.wanakana.bind(query.get(0)); } definitionAdd(definition, mode) { diff --git a/ext/bg/js/popup.js b/ext/bg/js/popup.js index 9f2567df..5bc7def4 100644 --- a/ext/bg/js/popup.js +++ b/ext/bg/js/popup.js @@ -18,7 +18,7 @@ $(document).ready(() => { - $('#open-search').click(() => window.open(chrome.extension.getURL('/bg/search.html'))); + $('#open-search').click(() => commandExec('search')); $('#open-options').click(() => chrome.runtime.openOptionsPage()); $('#open-help').click(() => window.open('http://foosoft.net/projects/yomichan')); @@ -26,9 +26,6 @@ $(document).ready(() => { const toggle = $('#enable-search'); toggle.prop('checked', options.general.enable).change(); toggle.bootstrapToggle(); - toggle.change(() => { - options.general.enable = toggle.prop('checked'); - optionsSave(options).then(() => instYomi().optionsSet(options)); - }); + toggle.change(() => commandExec('toggle')); }); }); diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index 91518e84..f267da80 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -284,7 +284,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "<div class=\"entry\">\n <div class=\"actions\">\n" + return "<div class=\"entry\">\n <div class=\"actions\">\n <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (arrows / home / end)\" alt>\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " </div>\n\n <div class=\"glyph\">" @@ -299,9 +299,9 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : "") + " </div>\n</div>\n"; },"2":function(container,depth0,helpers,partials,data) { - return " <a href=\"#\" title=\"Add Kanji\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" alt></a>\n"; + return " <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" title=\"Add Kanji ([)\" alt></a>\n"; },"4":function(container,depth0,helpers,partials,data) { - return " <a href=\"#\" title=\"Source term\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" alt></a>\n"; + return " <a href=\"#\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" title=\"Source term (Backspace)\" alt></a>\n"; },"6":function(container,depth0,helpers,partials,data) { var stack1; @@ -442,7 +442,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "<div class=\"entry\">\n <div class=\"actions\">\n" + return "<div class=\"entry\">\n <div class=\"actions\">\n <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (arrows / home / end)\" alt>\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + " </div>\n\n" @@ -453,9 +453,9 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : "") + " </div>\n</div>\n"; },"13":function(container,depth0,helpers,partials,data) { - return " <a href=\"#\" title=\"Add expression\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" alt></a>\n <a href=\"#\" title=\"Add reading\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" alt></a>\n"; + return " <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" title=\"Add expression ([)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" title=\"Add reading (])\" alt></a>\n"; },"15":function(container,depth0,helpers,partials,data) { - return " <a href=\"#\" title=\"Play audio\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" alt></a>\n"; + return " <a href=\"#\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" title=\"Play audio (\\)\" alt></a>\n"; },"17":function(container,depth0,helpers,partials,data) { var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer = " <div class=\"expression\"><ruby>"; diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 59eb9269..6999cae3 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -34,6 +34,15 @@ function promiseCallback(promise, callback) { /* + * Commands + */ + +function commandExec(command) { + instYomi().onCommand(command); +} + + +/* * Instance */ 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}) { |