-
Notifications
You must be signed in to change notification settings - Fork 357
/
SuppressUserMentions.plugin.js
102 lines (79 loc) · 3.29 KB
/
SuppressUserMentions.plugin.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
//META{"name":"SuppressUserMentions","website":"https://metalloriff.github.io/toms-discord-stuff/","source":"https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/SuppressUserMentions.plugin.js"}*//
class SuppressUserMentions {
getName() { return "SuppressUserMentions"; }
getDescription() { return "Allows you to suppress mentions from specified users without blocking them."; }
getVersion() { return "0.0.2"; }
getAuthor() { return "Metalloriff"; }
getChanges() {
return {
};
}
load() {}
start() {
const libLoadedEvent = () => {
try{ this.onLibLoaded(); }
catch(err) { console.error(this.getName(), "fatal error, plugin could not be started!", err); try { this.stop(); } catch(err) { console.error(this.getName() + ".stop()", err); } }
};
let lib = document.getElementById("NeatoBurritoLibrary");
if (!lib) {
lib = document.createElement("script");
lib.id = "NeatoBurritoLibrary";
lib.type = "text/javascript";
lib.src = "https://rawgit.com/Metalloriff/BetterDiscordPlugins/master/Lib/NeatoBurritoLibrary.js";
document.head.appendChild(lib);
}
this.forceLoadTimeout = setTimeout(libLoadedEvent, 30000);
if (typeof window.NeatoLib !== "undefined") libLoadedEvent();
else lib.addEventListener("load", libLoadedEvent);
}
get settingFields() {
return {
suppressedUsers: { title: "Suppressed user IDs", description: "You can also add and remove suppressed users from the context menu", type: "string", array: true }
};
}
get defaultSettings() {
return {
displayUpdateNotes: true,
suppressedUsers: ["454465635972284428"]
};
}
getSettingsPanel() {
return NeatoLib.Settings.createPanel(this);
}
saveSettings() {
NeatoLib.Settings.save(this);
}
onLibLoaded() {
this.settings = NeatoLib.Settings.load(this);
NeatoLib.Updates.check(this);
//if (this.settings.displayUpdateNotes) NeatoLib.Changelog.compareVersions(this.getName(), this.getChanges());
this.unpatch = NeatoLib.monkeyPatchInternal(NeatoLib.Modules.get("isMentioned"), "isMentioned", e => {
if (this.settings.suppressedUsers.includes(e.args[0].author.id)) return false;
else return e.callDefault();
});
document.addEventListener("contextmenu", this.contextEvent = e => this.onContextMenu(e));
NeatoLib.Events.onPluginLoaded(this);
}
onContextMenu(e) {
if (!e.target.className.includes("username") && !e.target.className.includes("large")) return;
const contextMenu = NeatoLib.ContextMenu.get();
if (!contextMenu) return;
const uid = NeatoLib.ReactData.get(contextMenu).return.return.return.return.memoizedProps.user.id;
contextMenu.insertAdjacentElement("afterBegin", NeatoLib.ContextMenu.createGroup([
!this.settings.suppressedUsers.includes(uid) ? NeatoLib.ContextMenu.createItem("Suppress User Mentions", () => {
this.settings.suppressedUsers.push(uid);
this.saveSettings();
NeatoLib.ContextMenu.close();
}) :
NeatoLib.ContextMenu.createItem("Unsuppress User Mentions", () => {
this.settings.suppressedUsers.splice(this.settings.suppressedUsers.indexOf(uid), 1);
this.saveSettings();
NeatoLib.ContextMenu.close();
})
]));
}
stop() {
this.unpatch();
document.removeEventListener("contextmenu", this.contextEvent);
}
}