-
Notifications
You must be signed in to change notification settings - Fork 3
/
banhammer.user.js
165 lines (157 loc) · 5.86 KB
/
banhammer.user.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
// ==UserScript==
// @name No More MCreator Mods
// @version 0.10
// @description you weren't gonna use them anyway
// @author comp500
// @namespace https://infra.link/
// @match https://www.curseforge.com/minecraft/*
// @match https://www.curseforge.com/Minecraft/*
// @match https://legacy.curseforge.com/minecraft/*
// @match https://legacy.curseforge.com/Minecraft/*
// @updateURL https://github.com/comp500/Curseforge-Userscripts/raw/master/banhammer.user.js
// @downloadURL https://github.com/comp500/Curseforge-Userscripts/raw/master/banhammer.user.js
// @homepageURL https://github.com/comp500/Curseforge-Userscripts/
// @supportURL https://github.com/comp500/Curseforge-Userscripts/issues/
// @source https://github.com/comp500/Curseforge-Userscripts/
// @run-at document-end
// @grant GM_xmlhttpRequest
// @connect addons-ecs.forgesvc.net
// @connect edge.forgecdn.net
// @connect media.forgecdn.net
// @require https://unpkg.com/[email protected]/dist/jszip.min.js
// ==/UserScript==
(function() {
"use strict";
if (!JSZip) {
console.log("NoMoreMCreatorMods: JSZip did not load properly!");
return;
}
let storage = {};
if (localStorage.NoMoreMCreatorMods != null) {
try {
storage = JSON.parse(localStorage.NoMoreMCreatorMods);
} catch (e) {
console.error(e);
storage = {};
}
}
let modRegex = /\/minecraft\/mc-mods\/([a-z][\da-z\-_]{0,127})$/;
let mCreatorDescRegex = /<div class="box p-4 pb-2 project-detail__content" data-user-content>[\w\W]*MCreator[\w\W]*?<\/div>/i;
let openSourceRegex = /Source<svg class="icon icon-offsite-nav" viewBox="0 0 20 20" width="20" height="20"><use xlink:href="\/Content\/2-0-7166-24694\/Skins\/CurseForge\/images\/twitch\/Action\/Popout.svg#Action\/Popout\"\/><\/svg>/;
// haha nice try
let hahaSourceRegex = /<a href="https?:\/\/(www.)?mcreator.(net|com)\/?[^"\n]*" ?class="text-gray-500 hover:no-underline" ?>\s*<span class="b-list-label">\s*Source/i;
let projectIDRegex = /<span>Project ID<\/span>\s*<span>(\d+)<\/span>/;
let greaseMonkeyXHR = details => {
details.method = details.method ? details.method : "GET";
details.anonymous = true;
details.responseType = details.responseType ? details.responseType : "arraybuffer";
return new Promise((resolve, reject) => {
details.onload = resolve;
details.onerror = reject;
GM_xmlhttpRequest(details);
});
};
Promise.all(
Array.from(document.querySelectorAll(".project-listing-row")).map(async row => {
let link = Array.from(row.getElementsByTagName("a")).find(a => modRegex.test(a.href));
if (link != undefined) {
let stored = (link.href
.replace("https://legacy.curseforge.com/minecraft/mc-mods/", "")
.replace("https://legacy.curseforge.com/Minecraft/mc-mods/", "")
.replace("https://www.curseforge.com/minecraft/mc-mods/", "")
.replace("https://www.curseforge.com/Minecraft/mc-mods/", ""));
if (storage[stored] == "mcreator") {
row.parentNode.removeChild(row);
return null;
} else if (storage[stored] == "normal" || stored == "thanos-skin") {
return null;
}
let res = await fetch(link.href);
if (res.status !== 200) {
console.error("NoMoreMCreatorMods: failed to get mod page " + link.href);
console.log(res);
return null;
}
let text = await res.text();
// Exclude mods with MCreator in the description
if (mCreatorDescRegex.test(text)) {
storage[stored] = "mcreator";
row.parentNode.removeChild(row);
return null;
}
// Allow OSS mods
if (openSourceRegex.test(text) && !hahaSourceRegex.test(text)) {
storage[stored] = "normal";
return null;
}
let projectIDMatches = projectIDRegex.exec(text);
if (projectIDMatches != null && projectIDMatches.length > 0) {
return [parseInt(projectIDMatches[1], 10), row, stored];
}
}
})
)
.then(async ids => {
let validIDs = ids.filter(id => id != null);
if (validIDs.length > 0) {
// Request the mod data from CurseForge's API
let res = await greaseMonkeyXHR({
url: "https://addons-ecs.forgesvc.net/api/v2/addon/",
method: "POST",
data: JSON.stringify(validIDs.map(i => i[0])),
responseType: "json",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
});
if (res.status != 200) {
console.error("NoMoreMCreatorMods: failed to get addon info: " + res.status + " " + res.statusText);
return;
}
if (res.response == null) {
console.error("NoMoreMCreatorMods: failed to get addon info: null response");
return;
}
await Promise.all(
res.response.map(async mod => {
if (mod.latestFiles == null) {
console.error("NoMoreMCreatorMods: failed to get addon info: null latestFiles");
return;
}
if (mod.latestFiles.length > 0) {
// Download the mod
let url = mod.latestFiles[0].downloadUrl;
if (url == null) {
console.error("NoMoreMCreatorMods: failed to get addon info: null download url");
return;
}
let downloadRes = await greaseMonkeyXHR({ url: url });
if (downloadRes.status != 200) {
console.error("NoMoreMCreatorMods: failed to get mod download: " + res.status);
return;
}
let zip = await JSZip.loadAsync(downloadRes.response);
let row = validIDs.find(i => i[0] == mod.id)[1];
let stored = validIDs.find(i => i[0] == mod.id)[2];
// Check for a folder called net/mcreator
if (zip.files["net/mcreator/"] != null || zip.files["mod/mcreator/"] != null) {
storage[stored] = "mcreator";
row.parentNode.removeChild(row);
return;
} else {
storage[stored] = "normal";
return;
}
}
})
);
}
})
.then(a => {
localStorage.NoMoreMCreatorMods = JSON.stringify(storage);
})
.catch(e => {
console.error(e);
});
})();