-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyouslow.js
70 lines (55 loc) · 1.62 KB
/
youslow.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
(() => {
let currentSpeed = 2;
let enabled = false;
let button;
let video;
function getVideo() {
if (!video) {
video = document.querySelector('video');
}
return video;
}
function applySpeed() {
const speed = enabled ? currentSpeed : 1;
if (button) {
button.innerHTML = `${speed.toFixed(1)}x`;
}
const video = getVideo();
if (video) {
video.playbackRate = speed;
}
}
function addControls() {
const rightControlsElement = document.querySelector(".ytp-right-controls");
button = document.createElement("button");
button.classList.add("ytp-button");
button.classList.add("ytp-time-display");
button.style.textAlign = "right";
applySpeed();
button.addEventListener("click", () => {
enabled = !enabled;
applySpeed();
});
rightControlsElement.prepend(button);
};
document.addEventListener('keyup', (e) => {
if (e.code === "KeyZ") {
currentSpeed -= 0.1;
enabled = true;
applySpeed();
} else if (e.code === "KeyX") {
currentSpeed += 0.1;
enabled = true;
applySpeed();
} else if (e.code === "KeyV") {
enabled = !enabled;
applySpeed();
}
});
const checkExist = setInterval(function () {
if (document.querySelector('.ytp-right-controls')) {
addControls();
clearInterval(checkExist);
}
}, 100);
})();