BetterDiscordAddons/Plugins/HideMutedCategories/HideMutedCategories.plugin.js

104 lines
3.8 KiB
JavaScript
Raw Normal View History

2020-05-06 11:20:03 +02:00
//META{"name":"HideMutedCategories","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/HideMutedCategories","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/HideMutedCategories/HideMutedCategories.plugin.js"}*//
var HideMutedCategories = (_ => {
return class HideMutedCategories {
getName () {return "HideMutedCategories";}
2020-06-27 09:37:47 +02:00
getVersion () {return "1.0.2";}
2020-05-06 11:20:03 +02:00
getAuthor () {return "DevilBro";}
getDescription () {return "Hides muted categories the same way muted channels are hidden, when the server is set to hide muted channels.";}
constructor () {
2020-06-04 16:51:47 +02:00
this.changelog = {
2020-06-27 09:37:47 +02:00
"fixed":[["New Scroller","Adjusted for the new scroller component"]]
2020-06-04 16:51:47 +02:00
};
2020-05-06 11:20:03 +02:00
this.patchPriority = 10;
this.patchedModules = {
before: {
Channels: "render"
2020-06-04 16:51:47 +02:00
},
after: {
Channels: "render"
2020-05-06 11:20:03 +02:00
}
};
}
// Legacy
2020-08-21 16:17:47 +02:00
load () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) BDFDB.PluginUtils.load(this);
}
2020-05-06 11:20:03 +02: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);
}
initialize () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.PluginUtils.init(this);
2020-09-11 19:31:36 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-05-06 11:20:03 +02:00
}
else {
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
}
}
stop () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
this.stopping = true;
2020-09-11 19:31:36 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
2020-05-06 11:20:03 +02:00
BDFDB.PluginUtils.clear(this);
}
}
// Begin of own functions
processChannels (e) {
if (!e.instance.props.guild || !e.instance.props.collapseMuted) return;
2020-06-04 16:51:47 +02:00
if (!e.returnvalue) {
e.instance.props.categories = Object.assign({}, e.instance.props.categories);
for (let catId in e.instance.props.categories) if (BDFDB.LibraryModules.MutedUtils.isChannelMuted(e.instance.props.guild.id, catId)) e.instance.props.categories[catId] = [];
}
else {
2020-06-27 09:37:47 +02:00
let list = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.channelsscroller]]});
2020-06-04 16:51:47 +02:00
if (list) {
let renderSection = list.props.renderSection;
list.props.renderSection = (...args) => {
let section = renderSection(...args);
2020-06-04 16:52:02 +02:00
if (section && section.props && section.props.channel && BDFDB.LibraryModules.MutedUtils.isChannelMuted(e.instance.props.guild.id, section.props.channel.id))return null;
2020-06-04 16:51:47 +02:00
else return section;
};
}
}
2020-05-06 11:20:03 +02:00
}
}
2020-07-26 16:39:51 +02:00
})();
module.exports = HideMutedCategories;