Sample chrome.commands.extension

This commit is contained in:
Matthew Wein
2016-03-07 15:21:01 -08:00
parent 02f0ea533d
commit 657178340d
4 changed files with 62 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

13
commands/README.md Normal file
View File

@@ -0,0 +1,13 @@
# commands
This extension includes:
* a background script, "background.js"
All it does is:
* register a shortcut (Ctrl+Shift+Y) to send a command to the extension (Command+Shift+Y on a Mac).",
It shows:
* how to use chrome.commands to register keyboard shortcuts for your extension.

27
commands/background.js Normal file
View File

@@ -0,0 +1,27 @@
/**
* 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+Y"
* }]
*/
chrome.commands.getAll(function(commandsArray) {
commands.forEach(function(command) {
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+Y".
* On Mac, this command will automatically be converted to "Command+Shift+Y".
*/
chrome.commands.onCommand.addListener(function(command) {
console.log("onCommand event received for message: ", command);
});

22
commands/manifest.json Normal file
View File

@@ -0,0 +1,22 @@
{
"name": "Sample Commands Extension",
"description": "Press Ctrl+Shift+Y to send an event (Command+Shift+Y on a Mac).",
"homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/commands",
"manifest_version": 2,
"version": "1.0",
"strict_min_version": "48.0a1",
"background": {
"scripts": ["background.js"]
},
"applications": {
"gecko": {
"id": "commands@mozilla.org"
}
},
"commands": {
"toggle-feature": {
"suggested_key": { "default": "Ctrl+Shift+Y" },
"description": "Send a 'toggle-feature' event to the extension"
}
}
}