Files
webextensions-examples/commands/background.js
wbamberg 3a89962a2f Demonstrate changing keyboard shortcut values (#347)
* Demonstrate changing keyboard shortcut values

* Add applications key

* Update README
2018-03-22 14:21:50 -07:00

31 lines
1.1 KiB
JavaScript

/**
* Returns all of the registered extension commands for this extension
* and their shortcut (if active).
*
* Since there is only one registered command in this sample extension,
* the returned `commandsArray` will look like the following:
* [{
* name: "toggle-feature",
* description: "Send a 'toggle-feature' event to the extension"
* shortcut: "Ctrl+Shift+U"
* }]
*/
let gettingAllCommands = browser.commands.getAll();
gettingAllCommands.then((commands) => {
for (let command of commands) {
// Note that this logs to the Add-on Debugger's console: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Debugging
// not the regular Web console.
console.log(command);
}
});
/**
* Fired when a registered command is activated using a keyboard shortcut.
*
* In this sample extension, there is only one registered command: "Ctrl+Shift+U".
* On Mac, this command will automatically be converted to "Command+Shift+U".
*/
browser.commands.onCommand.addListener((command) => {
browser.tabs.create({url: "https://developer.mozilla.org"});
});