-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
60 lines (49 loc) · 1.31 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
let loc = window.location.href;
const frontPageUrl = new RegExp("youtube.com/?$", "g");
const watchPageURrl = new RegExp("youtube.com/watch", "g");
cancel(loc);
setInterval(() => {
if (window.location.href !== loc) {
loc = window.location.href;
setTimeout(() => {
cancel(loc);
}, 1000);
}
}, 1000);
function cancel(location) {
//chrome.runtime.sendMessage("showPageAction");
if (isFrontPage(location)) {
console.log("p will be gone");
displayNone("#primary");
displayNone(".style-scope .ytd-page-manager");
} else if (isWatchPage(location)) {
displayNone("#secondary");
displayNone("#related");
displayNone("#chat");
displayNone("#comments");
removeEndScreen();
}
}
function displayNone(query) {
const node = document.querySelector(query);
if (node) {
node.style.display = "none";
}
}
function isFrontPage(location) {
return frontPageUrl.test(location);
}
function isWatchPage(location) {
return watchPageURrl.test(location);
}
function removeEndScreen() {
const domVideo = document.querySelector("video");
if (domVideo) {
domVideo.addEventListener("ended", function (e) {
const videoEndscreen = document.querySelector(".html5-endscreen");
if (videoEndscreen) {
videoEndscreen.style.display = "none";
}
});
}
}