-
Notifications
You must be signed in to change notification settings - Fork 7
/
toggle-keys-and-gestures.js
68 lines (66 loc) · 2.26 KB
/
toggle-keys-and-gestures.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
// Toggle Keys and Gestures
// version 2023.5.0
// https://forum.vivaldi.net/post/622831
// Button for toggling keyboard shortcuts and mouse gestures. Highlight
// indicates whether something is disabled. Can be toggled together or
// individually (shift‐click/alt‐click). See instructions on the forum for
// creating a custom icon.
(function toggleKeysAndGestures() {
function run(e, el) {
vivaldi.prefs.get(sk, (k) => {
vivaldi.prefs.get(sm, (m) => {
if (e !== null && !e.ctrlKey) {
if (e.shiftKey) {
if (k === true) k = false;
else k = true;
} else if (e.altKey) {
if (m === true) m = false;
else m = true;
} else {
if (k === true) k = false;
else k = true;
if (m === true) m = false;
else m = true;
}
vivaldi.prefs.set({ path: sk, value: k });
vivaldi.prefs.set({ path: sm, value: m });
}
if (k === false || m === false) {
el.style = "color: var(--colorHighlightBg)";
} else {
el.style = "color: unset";
}
el.title = "Toggle Keys and Gestures";
if (k === true) el.title += "\n\u{2022} Keys enabled (shift)";
else el.title += "\n\u{2022} Keys disabled (shift)";
if (m === true) el.title += "\n\u{2022} Gestures enabled (alt)";
else el.title += "\n\u{2022} Gestures disabled (alt)";
});
});
}
const sk = "vivaldi.keyboard.shortcuts.enable";
const sm = "vivaldi.mouse_gestures.enabled";
let check = 0
let appendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function () {
if (this.tagName === "BUTTON") {
setTimeout(
function () {
if (
this.title === "Toggle Keys and Gestures") {
run(null, this);
const toggle = (event) => run(event, this);
this.addEventListener("click", toggle);
if (check === 0) {
vivaldi.prefs.onChanged.addListener((e) => {
if (e.path === sk || e.path === sm) run(null, this);
});
check = 1;
}
}
}.bind(this, arguments[0])
);
}
return appendChild.apply(this, arguments);
};
})();