forked from Claymont/detach-tab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
51 lines (46 loc) · 1.39 KB
/
options.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const commandDetach = 'detach-tab';
const commandReattach = 'reattach-tab';
/**
* 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 === commandDetach) {
document.querySelector('#shortcut-detach').value = command.shortcut;
}
if (command.name === commandReattach) {
document.querySelector('#shortcut-reattach').value = command.shortcut;
}
}
}
/**
* Update the shortcut based on the value in the textbox.
*/
async function applyShortcut() {
await browser.commands.update({
name: commandDetach,
shortcut: document.querySelector('#shortcut-detach').value
});
await browser.commands.update({
name: commandReattach,
shortcut: document.querySelector('#shortcut-reattach').value
});
}
/**
* Reset the shortcut and update the textbox.
*/
async function resetShortcut() {
await browser.commands.reset(commandDetach);
await browser.commands.reset(commandReattach);
updateUI();
}
/**
* Update the UI when the page loads.
*/
document.addEventListener('DOMContentLoaded', updateUI);
/**
* Handle update and reset button clicks
*/
document.querySelector('#apply').addEventListener('click', applyShortcut)
document.querySelector('#reset').addEventListener('click', resetShortcut)