-
Notifications
You must be signed in to change notification settings - Fork 5
/
content.js
121 lines (108 loc) · 3.71 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var mainSection = document.getElementsByTagName("ytd-rich-item-renderer");
var videos = document.getElementsByTagName("ytd-rich-grid-media");
var sideMenu = document.getElementsByTagName("ytd-guide-section-renderer");
var sideMenuLinks = document.getElementsByTagName("ytd-guide-entry-renderer");
var sideRecommendedSection = document.getElementsByTagName(
"ytd-compact-video-renderer"
);
var comments = document.getElementsByTagName("ytd-comments");
var hideAllVideos = function () {
for (var i = 0; i < mainSection.length; i++) {
mainSection[i].style.cursor = "not-allowed";
}
for (var i = 0; i < videos.length; i++) {
videos[i].style.pointerEvents = "none";
videos[i].style.textDecoration = "none";
videos[i].style.filter = "blur(5px)";
}
/* side recommended section */
for (var i = 0; i < sideRecommendedSection.length; i++) {
sideRecommendedSection[i].style.pointerEvents = "none";
sideRecommendedSection[i].style.textDecoration = "none";
sideRecommendedSection[i].style.filter = "blur(5px)";
}
// auto playing videos
let autoPlayingVideos = document.getElementsByClassName(
"ytd-compact-autoplay-renderer"
);
for (var i = 0; i < autoPlayingVideos.length; i++) {
if (autoPlayingVideos[i].tagName == "YTD-COMPACT-VIDEO-RENDERER") {
autoPlayingVideos[i].style.pointerEvents = "auto";
autoPlayingVideos[i].style.textDecoration = "initial";
autoPlayingVideos[i].style.filter = "blur(0px)";
}
}
};
var productiveModeOn = function () {
hideAllVideos();
for (var i = 0; i < sideMenu.length; i++) {
sideMenu[i].style.cursor = "not-allowed";
}
for (var i = 0; i < sideMenuLinks.length; i++) {
sideMenuLinks[i].style.pointerEvents = "none";
sideMenuLinks[i].style.textDecoration = "none";
sideMenuLinks[i].style.filter = "blur(5px)";
}
/* comment section */
for (var i = 0; i < comments.length; i++) {
comments[i].style.pointerEvents = "none";
comments[i].style.textDecoration = "none";
comments[i].style.filter = "blur(5px)";
}
};
var productiveModeOff = function () {
for (var i = 0; i < mainSection.length; i++) {
mainSection[i].style.cursor = "default";
}
for (var i = 0; i < videos.length; i++) {
videos[i].style.pointerEvents = "auto";
videos[i].style.textDecoration = "initial";
videos[i].style.filter = "blur(0px)";
}
for (var i = 0; i < sideMenu.length; i++) {
sideMenu[i].style.cursor = "default";
}
for (var i = 0; i < sideMenuLinks.length; i++) {
sideMenuLinks[i].style.pointerEvents = "auto";
sideMenuLinks[i].style.textDecoration = "initial";
sideMenuLinks[i].style.filter = "blur(0px)";
}
/* side recommended section */
for (var i = 0; i < sideRecommendedSection.length; i++) {
sideRecommendedSection[i].style.pointerEvents = "auto";
sideRecommendedSection[i].style.textDecoration = "initial";
sideRecommendedSection[i].style.filter = "blur(0px)";
}
/* comment section */
for (var i = 0; i < comments.length; i++) {
comments[i].style.pointerEvents = "auto";
comments[i].style.textDecoration = "initial";
comments[i].style.filter = "blur(0px)";
}
};
var init = function () {
chrome.storage.sync.get("hide", function (data) {
if (data.hide) {
productiveModeOn();
} else {
productiveModeOff();
}
});
};
//incoming message from popup
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.command === "hideVids") {
productiveModeOn();
} else if (request.command === "showVids") {
productiveModeOff();
} else {
init();
}
sendResponse({ result: "success" });
});
window.addEventListener("load", (event) => {
init();
});
window.addEventListener("scroll", () => {
init();
});