-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
107 lines (90 loc) · 3.81 KB
/
script.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const thumbnailSwapper = function () {
document.querySelectorAll("#dismissible").forEach(function (thumbnail) {
if (
["style-scope ytd-rich-grid-media", "style-scope ytd-grid-video-renderer"].includes(thumbnail.className) &&
thumbnail.childElementCount === 3
) {
thumbnail.id = "addedIframe";
let vid = document.createElement("iframe");
vid.id = "playbackView";
vid.height = "100%";
vid.width = "100%";
vid.src = `https://www.youtube.com/embed/${thumbnail.children[0].children[0].href.slice(32)}`;
vid.frameborder = "0";
vid.style = "display: none";
thumbnail.prepend(vid);
thumbnail.children[1].onmouseover = function () {
let videoLink = this.parentElement.children[0].src;
if (!sessionStorage.getItem(videoLink)) {
sessionStorage.setItem(videoLink, 0);
}
this.style = "display: none";
this.parentElement.children[0].style = "";
this.parentElement.children[0].src += `?autoplay=1&start=${Math.trunc(
sessionStorage.getItem(videoLink)
)}`;
};
thumbnail.children[0].onmouseout = function () {
let videoLink = this.src.split("?")[0];
sessionStorage.setItem(videoLink, this.contentDocument.querySelector("video").currentTime);
this.src = videoLink;
this.style = "display: none";
this.parentElement.children[1].style = "";
};
}
});
};
const changeSpeed = function () {
const ytVideo = document.querySelector("video");
const speedInput = document.createElement("input");
speedInput.setAttribute("type", "number");
speedInput.setAttribute("value", "1");
speedInput.setAttribute("min", "0.05");
speedInput.setAttribute("max", "16");
speedInput.setAttribute("step", "0.05");
speedInput.setAttribute("id", "speedInput");
speedInput.style =
"width: 50px; height: 25px; border: 0; padding: 0; margin-left: 10px; margin-block: auto; text-align: center; background-color: rgb(240, 240, 240)";
speedInput.addEventListener("click", function () {
ytVideo.playbackRate = this.value;
this.blur();
});
document.querySelector(".ytp-left-controls").appendChild(speedInput);
document.addEventListener("keydown", function (k) {
if (k.key === "ArrowUp" && k.ctrlKey) {
speedInput.stepUp();
ytVideo.playbackRate = speedInput.value;
ytVideo.parentElement.parentElement.classList.remove("ytp-autohide");
} else if (k.key === "ArrowDown" && k.ctrlKey) {
speedInput.stepDown();
ytVideo.playbackRate = speedInput.value;
ytVideo.parentElement.parentElement.classList.remove("ytp-autohide");
}
});
setInterval(() => {
if (ytVideo.playbackRate !== speedInput.value) {
ytVideo.playbackRate = speedInput.value;
}
}, 1000);
};
const adBlocker = function () {
setInterval(() => {
if (document.querySelector(".ytp-ad-persistent-progress-bar-container").style.display === "") {
document.querySelector("video").playbackRate = 16;
setTimeout(() => {
try {
document.querySelector(".ytp-ad-skip-button.ytp-button").click();
} catch (e) {}
}, 200);
console.log("Ad Cleared!");
}
}, 100);
};
if (location.pathname === "/watch") {
window.onpageshow = function () {
changeSpeed();
// adBlocker();
};
} else if ((location.pathname === "/") | location.pathname.includes("/videos")) {
setInterval(thumbnailSwapper, 5000);
}