-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
84 lines (70 loc) · 2.14 KB
/
content.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
window.onload = () => {
const targetNode = document.getElementById("movie_player") || document.body;
selfObserver(targetNode);
};
function selfObserver(documentNode) {
const observer = new MutationObserver(function () {
adFunction();
});
const config = {
subtree: true,
childList: true,
};
// Start observing
observer.observe(documentNode, config);
}
function adFunction() {
const mainDocument = document.getElementsByClassName(
"video-ads ytp-ad-module"
);
const playerOverlay = document.getElementsByClassName(
"ytp-ad-player-overlay"
);
const imageOverlay = document.getElementsByClassName(
"ytp-ad-image-overlay"
);
const skipBtn = document.getElementsByClassName(
"ytp-ad-skip-button ytp-button"
);
const newSkipBtn = document.getElementsByClassName(
"ytp-ad-skip-button-modern ytp-button"
);
const videoDocument = document.getElementsByClassName(
"video-stream html5-main-video"
);
const textOverlay = document.getElementsByClassName("ytp-ad-text-overlay");
const playerAds = document.getElementById("player-ads");
function handleSkipBtn() {
if (skipBtn.length > 0) {
skipBtn[0].click();
}
}
function handleNewSkipBtn() {
if (newSkipBtn.length > 0) {
newSkipBtn[0].click();
}
}
if (mainDocument.length > 0) {
handleSkipBtn();
handleNewSkipBtn();
if (playerOverlay.length > 0) {
playerOverlay[0].style.visibility = "hidden";
for (let i = 0; i < videoDocument.length; i++) {
if (videoDocument[i] && videoDocument[i].duration) {
videoDocument[i].currentTime = videoDocument[i].duration;
}
}
handleSkipBtn();
handleNewSkipBtn();
}
if (imageOverlay.length > 0) {
imageOverlay[0].style.visibility = "hidden";
}
}
if (playerAds) {
playerAds.style.display = "none";
}
if (textOverlay.length > 0) {
textOverlay[0].style.display = "none";
}
}