-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathytspeed.js
More file actions
56 lines (52 loc) · 1.57 KB
/
ytspeed.js
File metadata and controls
56 lines (52 loc) · 1.57 KB
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
function getCurrentVideo() {
var videos = Array.from(document.getElementsByTagName("video"));
videos.sort((a, b) => !b.paused - !a.paused);
for (var v of videos) {
if (v.paused && !videos[0].paused) {
break;
}
var vbox = v.getBoundingClientRect();
if (vbox.bottom > 0 && vbox.top < innerHeight) {
return v;
}
}
return videos[0];
}
function initDash() {
var dash = document.createElement("div");
dash.style.position = "fixed";
dash.style.right = "0";
dash.style.bottom = "0";
dash.style.zIndex = "4999";
var x = document.createElement("div");
x.textContent = "❌";
x.addEventListener("click", function () {
dash.remove();
});
dash.appendChild(x);
var range = document.createElement("input");
range.type = "range";
range.min = 0;
range.max = 1;
range.step = 0.1;
range.value = 0.7;
range.addEventListener("input", function () {
var video = getCurrentVideo();
video.style.filter = "brightness(" + this.value + ")";
});
dash.appendChild(range);
var speed = document.createElement("div");
for (var i of [1, 2, 3, 5, 10]) {
var button = document.createElement("button");
button.value = i;
button.textContent = "x" + i;
speed.appendChild(button);
}
speed.addEventListener("click", function (e) {
var video = getCurrentVideo();
video.playbackRate = parseInt(e.target.value);
});
dash.appendChild(speed);
document.body.appendChild(dash);
}
initDash();