BetterDiscordAddons/Plugins/BetterNsfwTag/BetterNsfwTag.plugin.js

77 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-02-27 08:44:03 +01:00
//META{"name":"BetterNsfwTag","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","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-09-19 20:49:33 +02:00
module.exports = (_ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info": {
"name": "BetterNsfwTag",
"author": "DevilBro",
2020-09-26 18:24:16 +02:00
"version": "1.2.6",
2020-09-19 20:49:33 +02:00
"description": "Adds a more noticeable tag to NSFW channels."
2019-05-26 13:55:26 +02:00
}
2020-09-19 20:49:33 +02:00
};
2020-10-09 21:09:35 +02:00
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
2020-09-19 20:49:33 +02:00
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
getDescription () {return config.info.description;}
2020-10-09 21:09:35 +02:00
load() {
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue:[]});
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click "Download Now" to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
2020-09-20 08:15:13 +02:00
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
if (!e && b && b.indexOf(`//META{"name":"`) > -1) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => {});
else BdApi.alert("Error", "Could not download BDFDB library plugin, try again some time later.");
});
}
2020-09-19 20:49:33 +02:00
});
}
if (!window.BDFDB_Global.pluginQueue.includes(config.info.name)) window.BDFDB_Global.pluginQueue.push(config.info.name);
2020-10-09 21:09:35 +02:00
}
start() {this.load();}
stop() {}
} : (([Plugin, BDFDB]) => {
return class BetterNsfwTag extends Plugin {
2020-09-19 20:49:33 +02:00
onLoad() {
this.patchedModules = {
after: {
ChannelItem: "render"
}
};
}
onStart() {
2020-09-11 19:31:36 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-02-11 17:11:59 +01:00
}
2020-09-19 20:49:33 +02:00
onStop() {
2020-09-11 19:31:36 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-02-11 17:11:59 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
processChannelItem (e) {
if (e.instance.props.channel && e.instance.props.channel.nsfw) {
2020-09-25 17:43:12 +02:00
let children = BDFDB.ReactUtils.findChild(e.returnvalue, {props:[["className", BDFDB.disCN.channelchildren]]});
2020-09-26 18:24:16 +02:00
let childrenChilds = children && BDFDB.ArrayUtils.is(children.props.children) ? children.props.children : BDFDB.ObjectUtils.get(children, "props.children.props.children");
2020-09-25 17:43:12 +02:00
if (BDFDB.ArrayUtils.is(childrenChilds)) {
let [oldTagParent, oldTagIndex] = BDFDB.ReactUtils.findParent(childrenChilds, {key: "NSFW-badge"});
2020-09-19 20:49:33 +02:00
if (oldTagIndex > -1) oldTagParent.splice(oldTagIndex, 1);
2020-09-25 17:43:12 +02:00
childrenChilds.push(BDFDB.ReactUtils.createElement("div", {
2020-09-19 20:49:33 +02:00
className: BDFDB.disCNS._betternsfwtagtag + BDFDB.disCN.channelchildiconbase,
key: "NSFW-badge",
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
}
2020-09-19 20:49:33 +02:00
};
2020-10-09 21:09:35 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
2020-09-19 20:49:33 +02:00
})();