-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
202 lines (174 loc) · 5.19 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
chrome.storage.sync.get(["extensionEnabled"], (result) => {
const youtubeHost =
window.location.hostname === "www.youtube.com" ||
window.location.hostname === "youtube.com";
const extensionEnabled = result.extensionEnabled ?? true;
if (youtubeHost && extensionEnabled) {
function removeNavItems(itemName) {
const item = Array.from(
document.querySelectorAll("ytd-guide-entry-renderer")
).find(
(element) =>
element.querySelector("yt-formatted-string")?.textContent === itemName
);
if (item) {
item.remove();
return true;
}
return false;
}
const shortsObserver = new MutationObserver(() => {
if (removeNavItems("Shorts")) {
shortsObserver.disconnect();
}
});
shortsObserver.observe(document.body, {
childList: true,
subtree: true,
});
const homeObserver = new MutationObserver(() => {
if (removeNavItems("Home")) {
homeObserver.disconnect();
}
});
homeObserver.observe(document.body, {
childList: true,
subtree: true,
});
const yourClipsObserver = new MutationObserver(() => {
if (removeNavItems("Your clips")) {
yourClipsObserver.disconnect();
}
});
yourClipsObserver.observe(document.body, {
childList: true,
subtree: true,
});
const yourVideosObserver = new MutationObserver(() => {
if (removeNavItems("Your videos")) {
yourVideosObserver.disconnect();
}
});
yourVideosObserver.observe(document.body, {
childList: true,
subtree: true,
});
const subscriptionsObserver = new MutationObserver(() => {
if (removeNavItems("Subscriptions")) {
subscriptionsObserver.disconnect();
}
});
subscriptionsObserver.observe(document.body, {
childList: true,
subtree: true,
});
function removeGuideSection(sectionName) {
const section = Array.from(
document.querySelectorAll("ytd-guide-section-renderer")
).find(
(element) =>
element.querySelector("yt-formatted-string")?.textContent ===
sectionName
);
if (section) {
section.remove();
return true;
}
return false;
}
const exploreSectionObserver = new MutationObserver(() => {
if (removeGuideSection("Explore")) {
exploreSectionObserver.disconnect();
}
});
exploreSectionObserver.observe(document.body, {
childList: true,
subtree: true,
});
const moreFromYouTubeSectionObserver = new MutationObserver(() => {
if (removeGuideSection("More from YouTube")) {
moreFromYouTubeSectionObserver.disconnect();
}
});
moreFromYouTubeSectionObserver.observe(document.body, {
childList: true,
subtree: true,
});
const settingsSectionObserver = new MutationObserver(() => {
const settingsSection = Array.from(
document.querySelectorAll("ytd-guide-section-renderer")
).find(
(element) => element.querySelector("a[title='Settings']") !== null
);
if (settingsSection) {
settingsSection.remove();
settingsSectionObserver.disconnect();
}
});
settingsSectionObserver.observe(document.body, {
childList: true,
subtree: true,
});
const feedObserver = new MutationObserver(() => {
const feed = document.querySelector(
"ytd-two-column-browse-results-renderer[page-subtype='home']"
);
if (feed) {
feed.remove();
feedObserver.disconnect();
}
});
feedObserver.observe(document.body, {
childList: true,
subtree: true,
});
const footerObserver = new MutationObserver(() => {
const footer = document.querySelector("div#footer");
if (footer) {
footer.remove();
footerObserver.disconnect();
}
});
footerObserver.observe(document.body, {
childList: true,
subtree: true,
});
const shortsSectionObserver = new MutationObserver(() => {
const shortsSection = Array.from(
document.querySelectorAll("ytd-rich-section-renderer")
).find(
(element) =>
element.querySelector("span#title")?.textContent.trim() === "Shorts"
);
if (shortsSection) {
shortsSection.remove();
shortsSectionObserver.disconnect();
}
});
shortsSectionObserver.observe(document.body, {
childList: true,
subtree: true,
});
const relatedVideosObserver = new MutationObserver(() => {
const relatedVideosSection = document.querySelector(
"#columns #secondary #related"
);
if (relatedVideosSection) {
relatedVideosSection.remove();
relatedVideosObserver.disconnect();
}
});
relatedVideosObserver.observe(document.body, {
childList: true,
subtree: true,
});
const commentObserver = new MutationObserver(() => {
const commentsSection = document.querySelector("ytd-comments");
if (commentsSection) {
commentsSection.remove();
commentObserver.disconnect();
}
});
commentObserver.observe(document.body, { childList: true, subtree: true });
}
});