forked from KeyZox71/seekersrealcolor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
requests-override.js
68 lines (59 loc) · 1.66 KB
/
requests-override.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
class OverrideTarget {
constructor(targetData) {
this.type = targetData.type;
this.value = targetData.value;
this.grabTypes = targetData.grabTypes;
}
get url() {
if (this.type == "userProfile") {
return "https://cdn.intra.42.fr/users/*/*" + this.value + "*";
}
return this.value;
}
get types() {
if (this.type === "userProfile") {
return ["image"];
}
if (this.type === "pattern") {
if (this.url.endsWith(".jpg") || this.url.endsWith(".png") || this.url.endsWith(".jpeg") || this.url.endsWith(".gif") || this.url.endsWith(".webp")) {
return ["image"];
}
}
if (this.grabTypes !== null && this.grabTypes !== undefined) {
return this.grabTypes;
}
return null;
}
get filter() {
if (this.types === null) {
return { urls: [this.url] };
}
return { urls: [this.url], types: this.types };
}
}
class Override {
constructor(overrideData) {
this.target = new OverrideTarget(overrideData.target);
this.replaceBy = overrideData.replaceBy;
}
apply() {
browser.webRequest.onBeforeRequest.addListener(
(req) => {
if (req.url === this.replaceBy) return {};
return { redirectUrl: this.replaceBy };
},
this.target.filter,
["blocking"],
);
}
}
async function applyWebFilters() {
const requestURL = "https://raw.githubusercontent.com/seekrs/improved-seekrs/main/data/requests-overrides.json";
const request = new Request(requestURL);
const response = await fetch(request);
const overrides = await response.json();
for (override in overrides) {
new Override(overrides[override]).apply();
}
}
applyWebFilters();