diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..897bbc2 Binary files /dev/null and b/.DS_Store differ diff --git a/commands/README.md b/commands/README.md new file mode 100644 index 0000000..0160906 --- /dev/null +++ b/commands/README.md @@ -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. diff --git a/commands/background.js b/commands/background.js new file mode 100644 index 0000000..0e4d361 --- /dev/null +++ b/commands/background.js @@ -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); +}); \ No newline at end of file diff --git a/commands/manifest.json b/commands/manifest.json new file mode 100644 index 0000000..d2e8d58 --- /dev/null +++ b/commands/manifest.json @@ -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" + } + } +}