This repository was archived by the owner on Jun 6, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
131 lines (116 loc) · 6.1 KB
/
Copy pathscript.js
File metadata and controls
131 lines (116 loc) · 6.1 KB
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
pureTwitch.log("Loaded!");
pureTwitch.fetchBlockedUsernames();
setInterval(() => {
pureTwitch.fetchBlockedUsernames();
}, 1000 * 60 * 10); // 10 minutes
document.addEventListener("pathChange", main);
let watchers = {
sidebar: null,
directories: null,
followingOverview: null,
};
async function main() {
const route = pureTwitch.getRouteFromPath(location.pathname);
Object.keys(watchers).forEach((key) => {
if (watchers[key]) {
watchers[key].disconnect();
watchers[key] = null;
}
});
// Global Sidebar Blocking
watchers.sidebar = new MutationObserver(() => {
const sidebarLinks = document.querySelectorAll(".side-nav-section a");
let usernames = new Set();
for (const link of sidebarLinks) {
const username = link.href.split("/").pop();
usernames.add(username);
}
const blockedUsernames = pureTwitch.batchBlockCheck([...usernames]);
for (const { username, blocked } of blockedUsernames) {
if (!blocked) continue;
const link = document.querySelector(`.side-nav-section .tw-transition:not([style*='display: none']) a[href$="${username}"]`);
if (!link) continue;
const parent = link.closest(".tw-transition");
if (link && parent && parent.style.display !== "none") {
parent.style.display = "none";
pureTwitch.log(`Removed ${username} from sidebar`);
}
}
});
watchers.sidebar.observe(document.getElementById("side-nav"), { childList: true, subtree: true });
if (!route) return;
pureTwitch.log(`Interpreting ${location.pathname} as ${route}`);
switch (route) {
case routes.HOMEPAGE:
break;
case routes.DIRECTORY_ALL:
case routes.DIRECTORY_CATEGORY:
case routes.DIRECTORY_COLLECTION:
watchers.directories = new MutationObserver(() => {
const directoryLinks = document.querySelectorAll(".tw-tower [data-target='']:not([style*='display: none']) a[data-test-selector='TitleAndChannel']:not([data-pt-processed]), .tw-tower [data-target='directory-first-item']:not([style*='display: none']) a[data-test-selector='TitleAndChannel']:not([data-pt-processed])");
let usernames = new Set();
for (const link of directoryLinks) {
const username = link.href.split("/").pop();
usernames.add(username);
}
const blockedUsernames = pureTwitch.batchBlockCheck([...usernames]);
for (const { username, blocked } of blockedUsernames) {
const link = document.querySelector(`.tw-tower a[href$="${username}"]`);
if (!link) continue;
if (!link.hasAttribute("data-pt-processed")) link.setAttribute("data-pt-processed", "");
if (!blocked) continue;
const parent = link.closest("[data-target=''], [data-target='directory-first-item']");
if (link && parent && parent.style.display !== "none") {
if (parent.getAttribute("data-target") === "directory-first-item") {
let next = parent.nextElementSibling;
while (next && next.style.display === "none") {
next = next.nextElementSibling;
}
if (next) {
next.setAttribute("data-target", "directory-first-item");
}
parent.setAttribute("data-target", "");
}
parent.style.display = "none";
pureTwitch.log(`Removed ${username} from directory`);
}
}
});
watchers.directories.observe(document.querySelector("[data-a-target='root-scroller']"), { childList: true, subtree: true });
break;
case routes.DIRECTORY_FOLLOWING:
watchers.followingOverview = new MutationObserver(() => {
const followingLiveLinks = document.querySelectorAll("#following-page-main-content > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > .tw-tower .live-channel-card a[data-test-selector='TitleAndChannel']:not([data-pt-processed])");
// TODO: Add support for recommended channels section
// const recommendedChannelLinks = document.querySelectorAll(".find-me > div:nth-child(2) > div:nth-child(1) > .tw-tower .shelf-card__impression-wrapper a[data-test-selector='TitleAndChannel']:not([data-pt-processed])");
let usernames = new Set();
for (const link of followingLiveLinks) {
const username = link.href.split("/").pop();
usernames.add(username);
}
const blockedUsernames = pureTwitch.batchBlockCheck([...usernames]);
for (const { username, blocked } of blockedUsernames) {
const link = document.querySelector(`#following-page-main-content .tw-tower a[href$="${username}"]`);
if (!link) continue;
if (!link.hasAttribute("data-pt-processed")) link.setAttribute("data-pt-processed", "");
if (!blocked) continue;
const parent = link.closest(".live-channel-card").parentElement;
if (link && parent && parent.style.display !== "none") {
parent.style.display = "none";
pureTwitch.log(`Removed ${username} from following overview live section`);
}
}
});
watchers.followingOverview.observe(document.querySelector("[data-a-target='root-scroller']"), { childList: true, subtree: true });
break;
case routes.DIRECTORY_FOLLOWING_LIVE:
// TODO: Implement
break;
case routes.DIRECTORY_FOLLOWING_VIDEOS:
// TODO: Implement
break;
default:
break;
}
}
main();