diff --git a/commands/background.js b/commands/background.js index ea53455..df72174 100644 --- a/commands/background.js +++ b/commands/background.js @@ -10,7 +10,7 @@ * shortcut: "Ctrl+Shift+U" * }] */ -var gettingAllCommands = browser.commands.getAll(); +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 diff --git a/commands/manifest.json b/commands/manifest.json index 785b9f0..9ac26cd 100644 --- a/commands/manifest.json +++ b/commands/manifest.json @@ -13,5 +13,10 @@ "suggested_key": { "default": "Ctrl+Shift+U" }, "description": "Send a 'toggle-feature' event to the extension" } + }, + + "options_ui": { + "page": "options.html", + "browser_style": true } } diff --git a/commands/options.html b/commands/options.html new file mode 100644 index 0000000..618ab46 --- /dev/null +++ b/commands/options.html @@ -0,0 +1,18 @@ + + + + + + + + +
+ + + + +
+ + + + diff --git a/commands/options.js b/commands/options.js new file mode 100644 index 0000000..884e48f --- /dev/null +++ b/commands/options.js @@ -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)