From 3feec32b67ecee65f8a52ab0f3d0f208a3449ccb Mon Sep 17 00:00:00 2001 From: Matthew Wein Date: Mon, 7 Mar 2016 15:21:01 -0800 Subject: [PATCH] Sample chrome.commands.extension --- commands/README.md | 11 +++++++++++ commands/background.js | 10 ++++++++++ commands/manifest.json | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 commands/README.md create mode 100644 commands/background.js create mode 100644 commands/manifest.json diff --git a/commands/README.md b/commands/README.md new file mode 100644 index 0000000..e99d685 --- /dev/null +++ b/commands/README.md @@ -0,0 +1,11 @@ +# open-my-page + +This extension includes: + +* a background script, "background.js" + +All it does is: registers a shortcut (Ctrl+Shift+Y) to send an onCommand event (Command+Shift+Y on a Mac).", + +It shows: + +* how to use chrome.commands to register a keyboard shortcut for your extension. diff --git a/commands/background.js b/commands/background.js new file mode 100644 index 0000000..0bd9fd7 --- /dev/null +++ b/commands/background.js @@ -0,0 +1,10 @@ + +browser.commands.getAll(function(commands) { + commands.forEach(function(command) { + console.log(command); + }); +}); + +browser.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..95153ed --- /dev/null +++ b/commands/manifest.json @@ -0,0 +1,21 @@ +{ + "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", + "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" + } + } +}