/
YTskip.user.js
45 lines (36 loc) · 1.24 KB
/
YTskip.user.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
// ==UserScript==
// @name YTskip
// @namespace https://github.com/petruchito/YTskip
// @version 0.4
// @updateURL https://github.com/petruchito/YTskip/raw/main/YTskip.user.js
// @downloadURL https://github.com/petruchito/YTskip/raw/main/YTskip.user.js
// @description Ctrl-,. to skip 1 sec
// @author petruchito <freeglider@gmail.com>
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?domain=youtube.com
// @grant none
// ==/UserScript==
const V_SECONDS = 1;
document.addEventListener('yt-navigate-finish',onNavigate);
var onKeyDown;
function onNavigate() {
if (window.location.toString().match(/\/watch/)) {
var V_YOUTUBE_PLAYER = document.querySelector('ytd-player').getPlayer();
try {
window.removeEventListener('keydown', onKeyDown);
} catch (e) {}
onKeyDown = function(e) {
if (e.code === 'Comma' && e.ctrlKey) {
V_YOUTUBE_PLAYER.seekBy(-V_SECONDS);
} else if (e.code === 'Period' && e.ctrlKey) {
V_YOUTUBE_PLAYER.seekBy(V_SECONDS);
}
}
window.addEventListener('keydown', onKeyDown);
} else {
if (onKeyDown) {
window.removeEventListener('keydown', onKeyDown);
onKeyDown = null;
}
}
}