-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.js
71 lines (58 loc) · 2.55 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
document.addEventListener("DOMContentLoaded", init);
async function init() {
const options = await getOptions();
for (const actionSelectionElement of document.querySelectorAll('.action-selection')) {
actionSelectionElement.innerHTML = `
<option value="none">do nothing</option>
<option value="navigateBack">navigate back</option>
<option value="navigateForward">navigate forward</option>
<option value="reload">reload current page</option>
<option value="createNewTab">create a new tab</option>
<option value="closeCurrentTab">close current tab</option>
<option value="undoCloseTab">restore last closed tab</option>
<option value="activateLeftTab">switch to left tab</option>
<option value="activateLeftTabSkipSpecial">switch to left tab (skip special pages)</option>
<option value="activateRightTab">switch to right tab</option>
<option value="activateRightTabSkipSpecial">switch to right tab (skip special pages)</option>`
}
const getElementById = (id) => document.getElementById(id);
for (optionName in options) {
if (optionName.endsWith('Enabled')) {
getElementById(optionName).checked = options[optionName];
} else if (optionName.endsWith('Action') || optionName === 'minDelta') {
getElementById(optionName).value = options[optionName];
}
}
getElementById('minDelta-display-value').textContent = options.minDelta + "px";
function updateActivationForCheckboxElement(checkboxElement) {
if (checkboxElement.classList.contains('enableGestureCheckbox')) {
const selectElement = document.querySelector(`label[for="${checkboxElement.id}"] select`);
if (selectElement) {
selectElement.disabled = !checkboxElement.checked;
}
}
}
for (const checkboxElement of document.querySelectorAll('input[type="checkbox"]')) {
checkboxElement.onchange = async function (event) {
const targetElement = event.target;
updateActivationForCheckboxElement(targetElement);
options[targetElement.id] = targetElement.checked;
await setOptions(options);
}
updateActivationForCheckboxElement(checkboxElement);
}
for (const selectElement of document.querySelectorAll('select')) {
selectElement.onchange = async function (event) {
const targetElement = event.target;
options[targetElement.id] = targetElement.value;
await setOptions(options);
}
}
getElementById('minDelta').oninput = (event) => {
getElementById('minDelta-display-value').textContent = event.target.value + "px";
}
getElementById('minDelta').onchange = async (event) => {
options.minDelta = event.target.value;
await setOptions(options);
}
}