forked from fireattack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutube_global_volume_control.user.js
More file actions
41 lines (36 loc) · 1018 Bytes
/
youtube_global_volume_control.user.js
File metadata and controls
41 lines (36 loc) · 1018 Bytes
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
// ==UserScript==
// @name YouTube global volume control
// @version 1.0
// @author Dovahkiin
// @icon https://www.youtube.com/favicon.ico
// @match https://www.youtube.com/watch?*
// ==/UserScript==
const reBind = ev => {
ev.stopPropagation()
const { code } = ev
if (['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft'].includes(code) &&
(checkPath(ev.path) || isProgressBar(ev.path))
) {
const eventClone = new KeyboardEvent(ev.type, ev)
document.querySelector('#movie_player').dispatchEvent(eventClone)
return false
};
}
function isProgressBar(path) {
for (let dom of path) {
if (dom.className && dom.className.includes('ytp-progress-bar')) {
return true
}
};
return false
}
function checkPath(path) {
for (let dom of path) {
if (dom.className && dom.className.includes('ytd-player')) {
return false
}
};
return true
}
document.onkeydown = reBind;
document.querySelector('.ytp-progress-bar').onkeydown = reBind;