-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (31 loc) · 1.02 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Returns all of the registered extension commands for this extension
* and their shortcut (if active).
*
*/
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.
*
* Commands of type "Ctrl+Shift+1" will automatically be converted to
* "Command+Shift+U" on Mac;
*/
browser.commands.onCommand.addListener((command) => {
// console.log("Got a command", command);
// `command` will be "play-soldier", "play-spear", etc. as in manifest
browser.tabs.query({currentWindow: true, active: true})
.then((tabArray) => {
let tabId = tabArray[0].id;
browser.tabs.sendMessage(tabId, {
command: "play-card",
rank: command.substring(5)
});
});
});