-
Notifications
You must be signed in to change notification settings - Fork 3
/
blockmod.user.js
86 lines (80 loc) · 2.84 KB
/
blockmod.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
// ==UserScript==
// @name Block mod button
// @version 0.2
// @description Hides selected mods from Curseforge
// @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/blockmod.user.js
// @downloadURL https://github.com/comp500/Curseforge-Userscripts/raw/master/blockmod.user.js
// @homepageURL https://github.com/comp500/Curseforge-Userscripts/
// @supportURL https://github.com/comp500/Curseforge-Userscripts/issues/
// @source https://github.com/comp500/Curseforge-Userscripts/
// @grant GM_registerMenuCommand
// ==/UserScript==
(function() {
"use strict";
let storage = {};
if (localStorage.BlockMod != null) {
try {
storage = JSON.parse(localStorage.BlockMod);
} catch (e) {
console.error(e);
storage = {};
}
}
let modRegex = /\/minecraft\/mc-mods\/([a-z][\da-z\-_]{0,127})$/;
GM_registerMenuCommand("List blocked mods", () => {
alert(Object.keys(storage).join(", "));
});
GM_registerMenuCommand("Clear blocked mods", () => {
storage = {};
localStorage.BlockMod = JSON.stringify(storage);
location.reload();
});
Array.from(document.querySelectorAll(".project-listing-row")).map(row => {
for (let link of Array.from(row.getElementsByTagName("a")).filter(a => modRegex.test(a.href))) {
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] == "block") {
if (row.parentNode != null) {
row.parentNode.removeChild(row);
break;
}
} else {
if (link.querySelector(".text-lg") == null && link.querySelector(".font-bold") == null) {
continue;
}
let blockLink = document.createElement("a");
blockLink.href = "#";
blockLink.innerText = "Block";
blockLink.style.paddingLeft = "5px";
blockLink.addEventListener("click", e => {
storage[stored] = "block";
localStorage.BlockMod = JSON.stringify(storage);
e.preventDefault();
row.parentNode.removeChild(row);
return false;
}, false);
link.addEventListener("mouseenter", () => {
link.parentNode.insertBefore(blockLink, link.nextSibling);
}, false);
let timeout = -1;
link.addEventListener("mouseleave", () => {
if (timeout > -1) {
window.clearTimeout(timeout);
}
timeout = window.setTimeout(() => {
link.parentNode.removeChild(blockLink);
}, 1000);
}, false);
}
}
});
})();