diff options
| -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/util.js | 9 | ||||
| -rw-r--r-- | ext/bg/js/yomichan.js | 22 | ||||
| -rw-r--r-- | ext/bg/search.html | 2 | ||||
| -rw-r--r-- | ext/manifest.json | 14 | 
6 files changed, 49 insertions, 14 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/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}) { diff --git a/ext/bg/search.html b/ext/bg/search.html index e9c25e15..2fd44fc7 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -20,7 +20,7 @@                  <form class="input-group">                      <input type="text" class="form-control" placeholder="Search for..." id="query" autofocus>                      <span class="input-group-btn"> -                        <input type="submit" class="btn btn-default form-control" id="search" value="Search"> +                        <input type="submit" class="btn btn-default form-control" id="search" value="Search" disabled>                      </span>                  </form>              </p> diff --git a/ext/manifest.json b/ext/manifest.json index 30f33975..3357e661 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -31,6 +31,20 @@          "<all_urls>",          "storage"      ], +    "commands": { +        "toggle": { +            "suggested_key": { +                "default": "Alt+Delete" +            }, +            "description": "Toggle text scanning" +        }, +        "search": { +            "suggested_key": { +                "default": "Alt+Insert" +            }, +            "description": "Open search window" +        } +    },      "web_accessible_resources": ["fg/frame.html"],      "applications": {          "gecko": { |