BetterDiscordAddons/Plugins/BetterNsfwTag/BetterNsfwTag.plugin.js

91 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"BetterNsfwTag","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BetterNsfwTag","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/BetterNsfwTag/BetterNsfwTag.plugin.js"}*//
2018-10-11 10:21:26 +02:00
2020-02-11 17:11:59 +01:00
var BetterNsfwTag = (_ => {
return class BetterNsfwTag {
getName () {return "BetterNsfwTag";}
2019-01-17 23:48:29 +01:00
2020-02-12 15:19:33 +01:00
getVersion () {return "1.2.4";}
2019-01-17 23:48:29 +01:00
2020-02-11 17:11:59 +01:00
getAuthor () {return "DevilBro";}
2019-01-17 23:48:29 +01:00
2020-02-11 17:11:59 +01:00
getDescription () {return "Adds a more noticeable tag to NSFW channels.";}
2019-01-26 22:45:19 +01:00
2020-02-11 17:11:59 +01:00
constructor () {
this.changelog = {
2020-02-12 15:19:33 +01:00
"improved":[["Position","Tag was repositioned similar to the mentions badge"],["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
2020-02-11 17:11:59 +01:00
};
this.patchedModules = {
after: {
ChannelItem: "render"
}
};
}
2018-10-11 10:21:26 +02:00
2020-02-11 17:11:59 +01:00
//legacy
load () {}
2018-10-11 10:21:26 +02:00
2020-02-11 17:11:59 +01:00
start () {
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("id", "BDFDBLibraryScript");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", _ => {this.initialize();});
document.head.appendChild(libraryScript);
}
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(_ => {
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
2019-05-26 13:55:26 +02:00
}
2018-10-11 10:21:26 +02:00
2020-02-11 17:11:59 +01:00
initialize () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.PluginUtils.init(this);
2019-01-26 22:45:19 +01:00
2020-02-11 17:11:59 +01:00
BDFDB.ModuleUtils.forceAllUpdates(this);
}
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
2018-10-11 10:21:26 +02:00
}
2020-02-11 17:11:59 +01:00
stop () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
this.stopping = true;
2019-10-22 11:37:23 +02:00
2020-02-11 17:11:59 +01:00
BDFDB.ModuleUtils.forceAllUpdates(this);
BDFDB.PluginUtils.clear(this);
}
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2020-02-11 17:11:59 +01:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2020-02-11 17:11:59 +01:00
processChannelItem (e) {
if (e.instance.props.channel && e.instance.props.channel.nsfw) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props:[["className", BDFDB.disCN.channelchildren]]});
if (index > -1 && children[index].props && children[index].props.children) {
let [oldTagParent, oldTagIndex] = BDFDB.ReactUtils.findChildren(children[index], {key: "NSFW-badge"});
if (oldTagIndex > -1) oldTagParent.splice(oldTagIndex, 1);
2020-02-12 15:19:33 +01:00
children[index].props.children.push(BDFDB.ReactUtils.createElement("div", {
2020-02-12 15:20:52 +01:00
className: BDFDB.disCNS._betternsfwtagtag + BDFDB.disCN.channelchildiconbase,
2020-02-11 17:11:59 +01:00
key: "NSFW-badge",
2020-02-12 15:19:33 +01:00
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.TextBadge, {
style: {borderRadius: "3px"},
text: "NSFW"
})
2020-02-11 17:11:59 +01:00
}));
}
2019-10-29 18:55:11 +01:00
}
2018-10-11 10:21:26 +02:00
}
}
2020-02-11 17:13:08 +01:00
})();