module.exports = (Plugin, Api, Vendor) => {
if (typeof BDFDB !== "object") global.BDFDB = {$: Vendor.$, BDv2Api: Api};
const {$} = Vendor;
return class extends Plugin {
initConstructor () {
this.updateHiddenCategory = false;
this.categoryMarkup =
`
`;
this.channelTextMarkup =
``;
this.channelVoiceMarkup =
``;
this.channelCategoryMarkup =
``;
this.defaults = {
settings: {
showText: {value:true, description:"Show hidden Textchannels:"},
showVoice: {value:true, description:"Show hidden Voicechannels:"},
showCategory: {value:false, description:"Show hidden Categories:"},
showAllowedRoles: {value:true, description:"Show allowed Roles on hover:"},
showOverWrittenRoles: {value:true, description:"Include overwritten Roles in allowed Roles:"},
showDeniedRoles: {value:true, description:"Show denied Roles on hover:"},
showDeniedUsers: {value:true, description:"Show denied Users on hover:"},
showForNormal: {value:false, description:"Also show Roles/Users for allowed channels:"},
showTopic: {value:false, description:"Show the topic of hidden channels:"}
}
};
}
onStart () {
var libraryScript = null;
if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) {
libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
document.head.appendChild(libraryScript);
}
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize();
else libraryScript.addEventListener("load", () => {this.initialize();});
return true;
}
initialize () {
if (typeof BDFDB === "object") {
BDFDB.loadMessage(this);
this.UserStore = BDFDB.WebModules.findByProperties(["getUsers", "getUser"]);
this.MemberStore = BDFDB.WebModules.findByProperties(["getMember", "getMembers"]);
this.ChannelStore = BDFDB.WebModules.findByProperties(["getChannels", "getDMFromUserId"]);
this.GuildChannels = BDFDB.WebModules.findByProperties(["getChannels", "getDefaultChannel"]);
this.Permissions = BDFDB.WebModules.findByProperties(["Permissions", "ActivityTypes"]).Permissions;
var observer = null;
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.addedNodes) {
change.addedNodes.forEach((node) => {
if (node && node.className && node.className.length > 0 && node.className.indexOf("container-") > -1 && node.className.indexOf("hidden") == -1) {
this.appendToChannelList(document.querySelector(".container-hidden"));
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.channels, {name:"channelListObserver",instance:observer}, {childList: true, subtree: true});
this.displayHiddenChannels();
return true;
}
else {
console.error(this.name + ": Fatal Error: Could not load BD functions!");
return false;
}
}
onStop () {
if (typeof BDFDB === "object") {
$(".container-hidden").remove();
BDFDB.unloadMessage(this);
return true;
}
else {
return false;
}
}
onSwitch () {
if (typeof BDFDB === "object") {
this.displayHiddenChannels();
}
}
// begin of own functions
updateSettings (settingspanel) {
var settings = {};
for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
settings[input.value] = input.checked;
}
BDFDB.saveAllData(settings, this, "settings");
this.updateHiddenCategory = true;
}
displayHiddenChannels () {
var serverObj = BDFDB.getSelectedServer();
if (serverObj) {
var serverID = serverObj.id;
if (!document.querySelector(".container-hidden.server" + serverID)) {
$(".container-hidden").remove();
var types = {
"text":0,
"voice":2,
"category":4
};
var allChannels = this.ChannelStore.getChannels();
var shownChannels = this.GuildChannels.getChannels(serverID);
var hiddenChannels = {};
for (let type in types) hiddenChannels[types[type]] = [];
for (let channelID in allChannels) {
var channel = allChannels[channelID];
if (channel.guild_id == serverID) {
var isHidden = true;
if (channel.type == types.category) {
for (let type in types) {
for (let shownChannel of shownChannels[types[type]]) {
if (!channel.id || shownChannel.channel.parent_id == channel.id) {
isHidden = false;
break;
}
}
}
}
else {
for (let shownChannel of shownChannels[channel.type]) {
if (shownChannel.channel.id == channel.id) {
isHidden = false;
break;
}
}
}
if (isHidden) {
hiddenChannels[channel.type].push(channel);
}
}
}
var settings = BDFDB.getAllData(this, "settings");
var count = 0;
for (let type in types) {
if (!settings.showText && type == "text" || !settings.showVoice && type == "voice" || !settings.showCategory && type == "category") {
hiddenChannels[types[type]] = [];
}
BDFDB.sortArrayByKey(hiddenChannels[types[type]], "name");
count += hiddenChannels[types[type]].length;
}
hiddenChannels.count = count;
if (count > 0) {
var category = $(this.categoryMarkup)[0]
var wrapper = category.querySelector(BDFDB.dotCN.cursorpointer);
var svg = category.querySelector(BDFDB.dotCN.categoryicontransition);
var name = category.querySelector(BDFDB.dotCN.categorycolortransition);
$(category)
.addClass("server" + serverID)
.on("click", BDFDB.dotCN.categorycontainerdefault + " > " + BDFDB.dotCN.flex, (e) => {
wrapper.classList.toggle(BDFDB.disCN.categorywrapperhovered);
wrapper.classList.toggle(BDFDB.disCN.categorywrapperhoveredcollapsed);
svg.classList.toggle(BDFDB.disCN.categoryiconhovered);
svg.classList.toggle(BDFDB.disCN.categoryiconhoveredcollapsed);
svg.classList.toggle(BDFDB.disCN.closed);
name.classList.toggle(BDFDB.disCN.categorynamehovered);
name.classList.toggle(BDFDB.disCN.categorynamehoveredcollapsed);
$(category).find(BDFDB.dotCN.channelcontainerdefault).toggle(!svg.classList.contains(BDFDB.disCN.closed));
BDFDB.saveData(serverID, !svg.classList.contains(BDFDB.disCN.closed), this, "categorystatus");
})
.on("mouseenter mouseleave", BDFDB.dotCN.categorycontainerdefault + " > " + BDFDB.dotCN.flex, () => {
if (!category.querySelector(BDFDB.dotCN.closed)) {
wrapper.classList.toggle(BDFDB.disCN.categorywrapperdefault);
wrapper.classList.toggle(BDFDB.disCN.categorywrapperhovered);
svg.classList.toggle(BDFDB.disCN.categoryicondefault);
svg.classList.toggle(BDFDB.disCN.categoryiconhovered);
name.classList.toggle(BDFDB.disCN.categorynamedefault);
name.classList.toggle(BDFDB.disCN.categorynamehovered);
}
else {
wrapper.classList.toggle(BDFDB.disCN.categorywrappercollapsed);
wrapper.classList.toggle(BDFDB.disCN.categorywrapperhoveredcollapsed)
svg.classList.toggle(BDFDB.disCN.categoryiconcollapsed)
svg.classList.toggle(BDFDB.disCN.categoryiconhoveredcollapsed);
name.classList.toggle(BDFDB.disCN.categorynamecollapsed);
name.classList.toggle(BDFDB.disCN.categorynamehoveredcollapsed)
}
});
for (let hiddenChannel of hiddenChannels[0]) {
let channel = $(this.channelTextMarkup)[0];
let channelwrapper = channel.querySelector(BDFDB.dotCN.channelwrapper);
let channelicon = channel.querySelector(BDFDB.dotCN.channelcontent);
let channelsvg = channel.querySelector(BDFDB.dotCN.channelicon);
let channelname = channel.querySelector(BDFDB.dotCN.channelname);
channelname.innerText = hiddenChannel.name;
$(channel)
.on("mouseenter mouseleave", BDFDB.dotCN.channelwrapper, (e) => {
channelwrapper.classList.toggle(BDFDB.disCN.channelwrapperdefaulttext);
channelwrapper.classList.toggle(BDFDB.disCN.channelwrapperhoveredtext);
channelicon.classList.toggle(BDFDB.disCN.channelcontentdefaulttext);
channelicon.classList.toggle(BDFDB.disCN.channelcontenthoveredtext);
channelsvg.classList.toggle(BDFDB.disCN.channelcolordefaulttext);
channelsvg.classList.toggle(BDFDB.disCN.channelcolorhoveredtext);
channelname.classList.toggle(BDFDB.disCN.channelnamedefaulttext);
channelname.classList.toggle(BDFDB.disCN.channelnamehoveredtext);
this.showAccessRoles(serverObj, hiddenChannel, e, false);
})
.on("click", () => {
BDFDB.showToast(`You can not enter the hidden textchannel ${hiddenChannel.name}.`, {type:"error"});
})
.on("contextmenu", (e) => {
this.createHiddenObjContextMenu(hiddenChannel, e);
})
.appendTo(category);
}
for (let hiddenChannel of hiddenChannels[2]) {
let channel = $(this.channelVoiceMarkup)[0];
let channelwrapper = channel.querySelector(BDFDB.dotCN.channelwrapper);
let channelicon = channel.querySelector(BDFDB.dotCN.channelcontent);
let channelsvg = channel.querySelector(BDFDB.dotCN.channelicon);
let channelname = channel.querySelector(BDFDB.dotCN.channelname);
channelname.innerText = hiddenChannel.name;
$(channel)
.on("mouseenter mouseleave", BDFDB.dotCN.channelwrapper, (e) => {
channelwrapper.classList.toggle(BDFDB.disCN.channelwrapperdefaultvoice);
channelwrapper.classList.toggle(BDFDB.disCN.channelwrapperhoveredvoice);
channelicon.classList.toggle(BDFDB.disCN.channelcontentdefaultvoice);
channelicon.classList.toggle(BDFDB.disCN.channelcontenthoveredvoice);
channelsvg.classList.toggle(BDFDB.disCN.channelcolordefaultvoice);
channelsvg.classList.toggle(BDFDB.disCN.channelcolorhoveredvoice);
channelname.classList.toggle(BDFDB.disCN.channelnamedefaultvoice);
channelname.classList.toggle(BDFDB.disCN.channelnamehoveredvoice);
this.showAccessRoles(serverObj, hiddenChannel, e, false);
})
.on("click", () => {
BDFDB.showToast(`You can not enter the hidden voicechannel ${hiddenChannel.name}.`, {type:"error"});
})
.on("contextmenu", (e) => {
this.createHiddenObjContextMenu(hiddenChannel, e);
})
.appendTo(category);
}
for (let hiddenChannel of hiddenChannels[4]) {
let channel = $(this.channelCategoryMarkup)[0];
let channelwrapper = channel.querySelector(BDFDB.dotCN.categorywrappercollapsed);
let channelsvg = channel.querySelector(BDFDB.dotCN.categoryiconcollapsed);
let channelname = channel.querySelector(BDFDB.dotCN.categorynamecollapsed);
channelname.innerText = hiddenChannel.name;
$(channel)
.on("mouseenter mouseleave", BDFDB.dotCN.flex, (e) => {
channelwrapper.classList.toggle(BDFDB.disCN.categorywrappercollapsed);
channelwrapper.classList.toggle(BDFDB.disCN.categorywrapperhoveredcollapsed);
channelsvg.classList.toggle(BDFDB.disCN.categoryiconcollapsed)
channelsvg.classList.toggle(BDFDB.disCN.categoryiconhoveredcollapsed);
channelname.classList.toggle(BDFDB.disCN.categorynamecollapsed);
channelname.classList.toggle(BDFDB.disCN.categorynamehoveredcollapsed);
this.showAccessRoles(serverObj, hiddenChannel, e, false);
})
.on("click", () => {
BDFDB.showToast(`You can not open the hidden category ${hiddenChannel.name}.`, {type:"error"});
})
.on("contextmenu", (e) => {
this.createHiddenObjContextMenu(hiddenChannel, e);
})
.appendTo(category);
}
var isOpen = BDFDB.loadData(serverID, this, "categorystatus");
isOpen = isOpen === null ? true : isOpen;
if (!isOpen) {
wrapper.classList.toggle(BDFDB.disCN.categorywrapperdefault);
wrapper.classList.toggle(BDFDB.disCN.categorywrappercollapsed);
svg.classList.toggle(BDFDB.disCN.categoryicondefault);
svg.classList.toggle(BDFDB.disCN.categoryiconcollapsed)
svg.classList.toggle(BDFDB.disCN.closed);
name.classList.toggle(BDFDB.disCN.categorynamedefault);
name.classList.toggle(BDFDB.disCN.categorynamecollapsed);
$(category).find(BDFDB.dotCN.channelcontainerdefault).hide();
}
this.appendToChannelList(category);
}
let channelist = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCN.scroller);
$(channelist).off("mouseenter." + this.name);
if (BDFDB.getData("showForNormal", this, "settings")) {
$(channelist).on("mouseenter." + this.name, BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault, (e) => {
var channel = BDFDB.getKeyInformation({"node":e.currentTarget,"key":"channel"});
if (channel) this.showAccessRoles(serverObj, channel, e, true);
});
}
}
}
}
createHiddenObjContextMenu (hiddenObj, e) {
e.preventDefault();
e.stopPropagation();
var contextMenu = $(`