BetterDiscordAddons/Plugins/BetterNsfwTag/BetterNsfwTag.plugin.js

103 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-10-20 23:25:34 +02:00
/**
* @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
2020-10-20 23:25:34 +02:00
*/
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-10-30 22:12:58 +01:00
"version": "1.2.7",
2020-10-16 10:25:30 +02:00
"description": "Add a more noticeable tag to NSFW channels"
2020-10-30 22:12:58 +01:00
},
"changeLog": {
"fixed": {
"Works again": "Yes"
}
2019-05-26 13:55:26 +02:00
}
2020-09-19 20:49:33 +02:00
};
2020-12-20 12:24:46 +01: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-11-19 16:51:14 +01:00
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
2020-09-19 20:49:33 +02:00
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) => {
2020-10-20 23:25:34 +02:00
if (!e && b && b.indexOf(`* @name BDFDB`) > -1) require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => {});
2020-09-20 08:15:13 +02:00
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() {}
2020-11-28 23:12:09 +01:00
getSettingsPanel() {
let template = document.createElement("template");
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The library plugin needed for ${config.info.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
template.content.firstElementChild.querySelector("a").addEventListener("click", _ => {
require("request").get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (e, r, b) => {
if (!e && b && b.indexOf(`* @name BDFDB`) > -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.");
});
});
return template.content.firstElementChild;
}
2020-10-09 21:09:35 +02:00
} : (([Plugin, BDFDB]) => {
return class BetterNsfwTag extends Plugin {
2020-09-19 20:49:33 +02:00
onLoad() {
this.patchedModules = {
after: {
2020-10-30 22:12:58 +01:00
ChannelItem: "default"
2020-09-19 20:49:33 +02:00
}
};
}
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-11-19 16:51:14 +01: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-10-30 22:12:58 +01:00
})();