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 pathutils.js
More file actions
70 lines (66 loc) · 2.56 KB
/
Copy pathutils.js
File metadata and controls
70 lines (66 loc) · 2.56 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
const pathChangeEvent = new Event("pathChange");
let lastPath = location.pathname;
setInterval(() => {
if (lastPath === location.pathname) return;
lastPath = location.pathname;
document.dispatchEvent(pathChangeEvent);
}, 100);
let routes = {
HOMEPAGE: "HOMEPAGE",
DIRECTORY_ALL: "DIRECTORY_ALL",
DIRECTORY_CATEGORY: "DIRECTORY_CATEGORY",
DIRECTORY_COLLECTION: "DIRECTORY_COLLECTION",
DIRECTORY_FOLLOWING: "DIRECTORY_FOLLOWING",
DIRECTORY_FOLLOWING_LIVE: "DIRECTORY_FOLLOWING_LIVE",
DIRECTORY_FOLLOWING_VIDEOS: "DIRECTORY_FOLLOWING_VIDEOS",
};
let pathRegex = {
[routes.HOMEPAGE]: /^\/$/,
[routes.DIRECTORY_ALL]: /^\/directory\/all(?:\/.+)?/,
[routes.DIRECTORY_CATEGORY]: /^\/directory\/category\/.+/,
[routes.DIRECTORY_COLLECTION]: /^\/directory\/collection\/.+/,
[routes.DIRECTORY_FOLLOWING]: /^\/directory\/following\/?$/,
[routes.DIRECTORY_FOLLOWING_LIVE]: /^\/directory\/following\/live\/?$/,
[routes.DIRECTORY_FOLLOWING_VIDEOS]: /^\/directory\/following\/videos\/?$/,
};
let pureTwitch = {
URL: `https://puretwitch.tv/api/streamers/`,
usernameBlocklist: [],
getRouteFromPath(path) {
let route = null;
for (const name of Object.keys(pathRegex)) {
const regex = pathRegex[name];
if (!regex.test(path)) continue;
route = name;
break;
}
return route;
},
fetchBlockedUsernames() {
fetch(pureTwitch.URL)
.then((response) => response.json())
.then(({ data }) => {
pureTwitch.usernameBlocklist = Object.values(data);
pureTwitch.log("Blocked usernames fetched!");
}).catch((error) => {
pureTwitch.error("Failed to fetch blocked usernames:", error);
});
},
isUsernameBlocked(username) {
return pureTwitch.usernameBlocklist.includes(username.toLowerCase().trim());
},
batchBlockCheck(usernames) {
return usernames.map((username) => {
return {
username: username,
blocked: pureTwitch.isUsernameBlocked(username),
};
});
},
log(...message) {
console.log(`%cPure Twitch`, "color: #252529; background-color: rgb(145, 70, 255); padding: 2px 4px; font-weight: 600; font-family: 'Arial'; border-radius: 2px;", ...message);
},
error(...message) {
console.error(`%cPure Twitch`, "color: #252529; background-color: rgb(255, 53, 53); padding: 2px 4px; font-weight: 600; font-family: 'Arial'; border-radius: 2px;", ...message);
}
};