forked from igrigorik/videospeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
74 lines (65 loc) · 2.45 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
72
73
74
let keyBindings = [];
// misc functions (input element manipulation etc.) {{{
function updateShortcutInputText(inputId, keyCode) {
document.getElementById(inputId).value = KEY_CODES[keyCode] || String.fromCharCode(keyCode);
document.getElementById(inputId).keyCode = keyCode;
}
function show_experimental() {
document
.querySelectorAll('.customForce')
.forEach((item) => (item.style.display = 'inline-block'));
}
function forgetAll() {
chrome.storage.sync.remove(['speeds']);
forgetStatus = document.querySelector('#forgetStatus');
forgetStatus.classList.toggle('hidden');
setTimeout(() => forgetStatus.classList.toggle('hidden'), 1500);
}
// }}}
// DOMContentLoaded; entry point basically {{{
document.addEventListener('DOMContentLoaded', function () {
restoreOptions();
document.getElementById('save').addEventListener('click', saveOptions);
document.getElementById('add').addEventListener('click', addBinding);
document.getElementById('restore').addEventListener('click', restoreDefaults);
document.getElementById('experimental').addEventListener('click', show_experimental);
document.getElementById('forgetAll').addEventListener('click', forgetAll);
document.getElementById('toggleSpeeds').addEventListener('click', toggleSpeeds);
function eventCaller(event, className, funcName) {
if (!event.target.classList.contains(className)) {
return;
}
funcName(event);
}
document.addEventListener('keypress', (event) => {
eventCaller(event, 'customValue', inputFilterNumbersOnly);
});
document.addEventListener('focus', (event) => {
eventCaller(event, 'customKey', inputFocus);
});
document.addEventListener('blur', (event) => {
eventCaller(event, 'customKey', inputBlur);
});
document.addEventListener('keydown', (event) => {
eventCaller(event, 'customKey', recordKeyPress);
});
document.addEventListener('click', (event) => {
eventCaller(event, 'removeParent', function () {
event.target.parentNode.parentNode.remove();
});
});
document.addEventListener('change', (event) => {
eventCaller(event, 'customDo', function () {
const parent = event.target.parentNode;
const customValue = parent.querySelector('.customValue');
if (NO_VALUE_ACTIONS.includes(event.target.value)) {
customValue.style.display = 'none';
customValue.value = 0;
} else {
customValue.style.display = 'inline-block';
}
});
});
});
// }}}
// vim: foldmethod=marker