2019-01-31 17:06:48 +01: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
|
|
|
|
|
|
|
class BetterNsfwTag {
|
2019-01-17 23:48:29 +01:00
|
|
|
getName () {return "BetterNsfwTag";}
|
|
|
|
|
2019-04-22 20:31:28 +02:00
|
|
|
getVersion () {return "1.1.9";}
|
2019-01-17 23:48:29 +01:00
|
|
|
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
|
|
|
getDescription () {return "Adds a more noticeable tag to NSFW channels.";}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
initConstructor () {
|
2019-04-22 20:31:28 +02:00
|
|
|
this.changelog = {
|
|
|
|
"improved":[["Tag Width","Now forces a min-width to avoid the tag of being cut off on long channel names"]]
|
|
|
|
};
|
|
|
|
|
2018-12-27 11:38:05 +01:00
|
|
|
this.patchModules = {
|
|
|
|
"ChannelItem":"componentDidMount"
|
|
|
|
};
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//legacy
|
|
|
|
load () {}
|
|
|
|
|
|
|
|
start () {
|
2019-02-04 09:13:15 +01:00
|
|
|
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
|
|
|
|
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
|
2019-05-26 13:55:26 +02:00
|
|
|
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
|
|
|
|
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
2018-10-11 10:21:26 +02:00
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.addEventListener("load", () => {this.initialize();});
|
2018-10-11 10:21:26 +02:00
|
|
|
document.head.appendChild(libraryScript);
|
2019-05-26 13:55:26 +02:00
|
|
|
this.libLoadTimeout = setTimeout(() => {
|
|
|
|
libraryScript.remove();
|
|
|
|
require("request")("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => {
|
|
|
|
if (body) {
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.innerText = body;
|
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
|
|
|
this.initialize();
|
|
|
|
});
|
|
|
|
}, 15000);
|
|
|
|
}
|
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2018-10-11 10:21:26 +02:00
|
|
|
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-22 11:05:54 +01:00
|
|
|
if (this.started) return;
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.loadMessage(this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-12-27 11:38:05 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-02-12 21:56:34 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-26 22:45:19 +01:00
|
|
|
BDFDB.removeEles(".NSFW-tag");
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.unloadMessage(this);
|
|
|
|
}
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
// begin of own functions
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-12-27 11:38:05 +01:00
|
|
|
processChannelItem (instance, wrapper) {
|
|
|
|
if (instance.props && instance.props.channel && instance.props.channel.nsfw) {
|
2019-01-17 23:48:29 +01:00
|
|
|
let channelname = wrapper.querySelector(BDFDB.dotCN.channelname);
|
2019-04-22 20:31:28 +02:00
|
|
|
if (channelname) channelname.parentElement.insertBefore(BDFDB.htmlToElement(`<span class="NSFW-tag ${BDFDB.disCNS.bottag + BDFDB.disCNS.bottagregular + BDFDB.disCN.bottagnametag}" style="background-color: rgb(241, 71, 71) !important; color: white !important; top: 0px; min-width: 28px;">NSFW</span>`), channelname.nextElementSibling);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|