Demonstrate changing keyboard shortcut values (#347)

* Demonstrate changing keyboard shortcut values

* Add applications key

* Update README
This commit is contained in:
wbamberg
2018-03-22 14:21:50 -07:00
committed by GitHub
parent 3267c485c2
commit 3a89962a2f
5 changed files with 76 additions and 1 deletions

42
commands/options.js Normal file
View File

@@ -0,0 +1,42 @@
const commandName = 'toggle-feature';
/**
* Update the UI: set the value of the shortcut textbox.
*/
async function updateUI() {
let commands = await browser.commands.getAll();
for (command of commands) {
if (command.name === commandName) {
document.querySelector('#shortcut').value = command.shortcut;
}
}
}
/**
* Update the shortcut based on the value in the textbox.
*/
async function updateShortcut() {
await browser.commands.update({
name: commandName,
shortcut: document.querySelector('#shortcut').value
});
}
/**
* Reset the shortcut and update the textbox.
*/
async function resetShortcut() {
await browser.commands.reset(commandName);
updateUI();
}
/**
* Update the UI when the page loads.
*/
document.addEventListener('DOMContentLoaded', updateUI);
/**
* Handle update and reset button clicks
*/
document.querySelector('#update').addEventListener('click', updateShortcut)
document.querySelector('#reset').addEventListener('click', resetShortcut)