-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
88 lines (78 loc) · 2.46 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
console.log("YT Shorts Blocker loaded");
function hideShortsButtons(sections) {
for (const section of sections) {
let aElements = section.getElementsByTagName("a");
if (aElements.length == 0) {
continue;
}
if (aElements[0].title.toLowerCase() == "shorts") {
section.style.display = "none";
}
}
}
function hideShortsButtonsInSidebar() {
let shortButtonSectionsMaximized = document.getElementsByTagName(
"ytd-guide-entry-renderer"
);
hideShortsButtons(shortButtonSectionsMaximized);
let shortButtonSectionsMinimized = document.getElementsByTagName(
"ytd-mini-guide-entry-renderer"
);
hideShortsButtons(shortButtonSectionsMinimized);
}
function hideShortsSectionsOnHomepage() {
let shortsSections = document.getElementsByTagName(
"ytd-rich-section-renderer"
);
for (const section of shortsSections) {
section.style.display = "none";
}
}
function hideShortsVideosInFeed() {
let shortVideos = document.getElementsByTagName("ytd-grid-video-renderer");
for (const video of shortVideos) {
let aElements = video.getElementsByTagName("a");
if (aElements.length == 0) {
continue;
}
if (aElements[0].href.includes("shorts")) {
video.style.display = "none";
}
}
}
function hideShortsVideosInSearchResults() {
let shortsSections = document.getElementsByTagName(
"ytd-reel-shelf-renderer"
);
for (const section of shortsSections) {
section.style.display = "none";
}
}
function hideShortsTabOnAccountPage() {
let tabs = document.getElementsByTagName("yt-tab-shape");
for (const tab of tabs) {
let divs = tab.getElementsByTagName("div");
for (const div of divs) {
if (div.innerText.toLowerCase() == "shorts") {
tab.style.display = "none";
break;
}
}
}
}
function hideShortsPage() {
if (!window.location.pathname.startsWith("/shorts")) return;
const shortsContainer = document.getElementById("shorts-container");
if (shortsContainer) {
shortsContainer.style.display = "none";
}
}
// Add an interval to check for new sections
setInterval(function () {
hideShortsButtonsInSidebar();
hideShortsSectionsOnHomepage();
hideShortsVideosInFeed();
hideShortsVideosInSearchResults();
hideShortsTabOnAccountPage();
hideShortsPage();
}, 1000);