mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-05-06 07:37:53 +02:00
Sample chrome.commands.extension
This commit is contained in:
@@ -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.
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user