如何让Firefox热键打开扩展程序?

时间:2017-10-09 04:09:24

标签: javascript firefox firefox-webextensions

我想使用热键在Firefox上打开扩展程序。但是我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

您可以使用命令API

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/commands https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands

在manifest.json

中像这样
"commands": {
  "my-shortcut-was-hit": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    },
    "description": "Send a 'my-shortcut-was-hit' event to the background script"
  }
}

并在后台脚本中:

browser.commands.onCommand.addListener(function(command) {
  if (command == "my-shortcut-was-hit") {
    console.log("my shortcut was hit!");
  }
});

另见https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/commands/onCommand