-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptions-firefox.js
54 lines (50 loc) · 1.35 KB
/
options-firefox.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
52
53
54
'use strict';
/* global browser */
var commands = [];
var shortcuts = document.getElementById('shortcuts');
function commandsUpdate() {
commands.forEach(async command => {
const id = command.name + 'shortcut';
const element = document.getElementById(id);
if (element.value !== command.shortcut) {
try {
await browser.commands.update({
name: command.name,
shortcut: element.value
});
} catch {
alert('Invalid shortcut used.');
}
getCommands();
}
});
}
window.addEventListener('keyup', event => {
if (event.keyCode === 13) {
event.preventDefault();
commandsUpdate();
}
});
getCommands();
async function getCommands() {
commands = await browser.commands.getAll();
commands.forEach(command => {
const id = command.name + 'shortcut';
const element = document.getElementById(id);
if (element) {
element.value = command.shortcut;
return
}
const label = document.createElement('label');
label.innerText = command.description + ' ';
label.setAttribute('for', id);
const input = document.createElement('input');
input.type = 'text'
input.id = id;
input.value = command.shortcut;
label.appendChild(input);
shortcuts.appendChild(label);
const br = document.createElement('br');
shortcuts.appendChild(br);
});
};