-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo-seeking-everywhere.js
31 lines (28 loc) · 1.01 KB
/
video-seeking-everywhere.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
console.debug("💾 'Video Seeking Everywhere' plugin loaded.");
const params = new URLSearchParams(document.currentScript.src.split('?')[1]);
const config = {
rewindSec: params.get('rewindSec'),
seekForwardSec: params.get('seekForwardSec')
};
function onSeek(e) {
if (["INPUT", "TEXTAREA", "SELECT"].includes(document.activeElement?.tagName)) {
return;
}
[...document.querySelectorAll('video')].filter(vid => !vid.paused).forEach((player) => {
if (player) {
switch (e.key) {
case '<':
case ',':
console.debug(`⏪ Seeking backwards by ${config.rewindSec} second${config.rewindSec > 1 ? 's' : ''}`);
player.currentTime -= parseInt(config.rewindSec);
break;
case '>':
case '.':
console.debug(`⏩ Seeking forwards by ${config.seekForwardSec} second${config.seekForwardSec > 1 ? 's' : ''}`);
player.currentTime += parseInt(config.seekForwardSec);
break;
}
}
});
}
document.addEventListener('keydown', onSeek);