//META{"name":"ShowHiddenChannels"}*//
class ShowHiddenChannels {
initConstructor () {
this.updateHiddenCategory = false;
this.categoryMarkup =
`
`;
this.channelTextMarkup =
``;
this.channelVoiceMarkup =
``;
this.channelCategoryMarkup =
``;
this.css = `
.container-hidden .containerDefault-1ZnADq .iconTransition-2pOJ7l {
position: static;
}`;
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:"},
showAllowedUsers: {value:true, description:"Show specifically allowed Users 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:"}
},
amounts: {
hoverDelay: {value:0, description:"Tooltip delay in millisec:"}
}
};
}
getName () {return "ShowHiddenChannels";}
getDescription () {return "Displays channels that are hidden from you by role restrictions.";}
getVersion () {return "2.3.5";}
getAuthor () {return "DevilBro";}
getSettingsPanel () {
if (!this.started || typeof BDFDB !== "object") return;
var settings = BDFDB.getAllData(this, "settings");
var amounts = BDFDB.getAllData(this, "amounts");
var settingshtml = `${this.getName()}
`;
for (let key in settings) {
settingshtml += `
`;
}
for (let key in amounts) {
settingshtml += `
`;
}
settingshtml += `
`;
var settingspanel = $(settingshtml)[0];
BDFDB.initElements(settingspanel);
$(settingspanel)
.on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);})
.on("input", ".amountInput", (e) => {
var input = parseInt(e.currentTarget.value);
if (!isNaN(input) && input > -1) BDFDB.saveData(e.currentTarget.getAttribute("option"), input, this, "amounts");
});
return settingspanel;
}
//legacy
load () {}
start () {
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();});
}
initialize () {
if (typeof BDFDB === "object") {
BDFDB.loadMessage(this);
this.React = BDFDB.WebModules.findByProperties(["createElement", "cloneElement"]);
this.ChannelTypes = BDFDB.WebModules.findByProperties(["ChannelTypes"]).ChannelTypes;
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});
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.removedNodes) {
change.removedNodes.forEach((node) => {
if (this.updateHiddenCategory && node.tagName && node.getAttribute("layer-id") == "user-settings") {
document.querySelectorAll(".container-hidden").forEach(category => {category.remove();});
this.displayHiddenChannels();
this.updateHiddenCategory = false;
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCN.layers, {name:"settingsWindowObserver",instance:observer}, {childList:true});
this.displayHiddenChannels();
}
else {
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
}
}
stop () {
if (typeof BDFDB === "object") {
$(".container-hidden").remove();
BDFDB.unloadMessage(this);
}
}
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 allChannels = this.ChannelStore.getChannels();
var shownChannels = this.GuildChannels.getChannels(serverID);
var hiddenChannels = {};
for (let type in this.ChannelTypes) hiddenChannels[this.ChannelTypes[type]] = [];
for (let channelID in allChannels) {
var channel = allChannels[channelID];
if (channel.guild_id == serverID) {
var isHidden = true;
if (channel.type == this.ChannelTypes.GUILD_CATEGORY) {
for (let type in this.ChannelTypes) {
if (shownChannels[this.ChannelTypes[type]]) for (let shownChannel of shownChannels[this.ChannelTypes[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 this.ChannelTypes) {
if (!settings.showText && type == "GUILD_TEXT" || !settings.showVoice && type == "GUILD_VOICE" || !settings.showCategory && type == "GUILD_CATEGORY") {
hiddenChannels[this.ChannelTypes[type]] = [];
}
BDFDB.sortArrayByKey(hiddenChannels[this.ChannelTypes[type]], "name");
count += hiddenChannels[this.ChannelTypes[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)
.attr("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.directionright);
name.classList.toggle(BDFDB.disCN.categorynamehovered);
name.classList.toggle(BDFDB.disCN.categorynamehoveredcollapsed);
$(category).find(BDFDB.dotCN.channelcontainerdefault).toggle(!svg.classList.contains(BDFDB.disCN.directionright));
BDFDB.saveData(serverID, !svg.classList.contains(BDFDB.disCN.directionright), this, "categorystatus");
})
.on("mouseenter mouseleave", BDFDB.dotCN.categorycontainerdefault + " > " + BDFDB.dotCN.flex, () => {
if (!svg.classList.contains(BDFDB.disCN.directionright)) {
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(serverObj, hiddenChannel, "TEXT", 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(serverObj, hiddenChannel, "VOICE", 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(serverObj, hiddenChannel, "CATEGORY", 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.directionright);
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.getName()).off("mouseleave." + this.getName());
if (settings.showForNormal) {
$(channelist)
.on("mouseenter." + this.getName(), BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault, (e) => {
var channel = BDFDB.getKeyInformation({"node":e.currentTarget,"key":"channel"});
if (channel) this.showAccessRoles(serverObj, channel, e, false);
});
}
}
}
}
createHiddenObjContextMenu (serverObj, hiddenObj, type, e) {
e.preventDefault();
e.stopPropagation();
var contextMenu = $(``);
var reactInstance = this.React.createElement(contextMenu[0]);
reactInstance.return = {memoizedProps:{type:("CHANNEL_LIST_" + type),guild:serverObj.data,channel:hiddenObj}};
contextMenu[0].__reactInternalInstance = reactInstance;
contextMenu
.on("click." + this.getName(), ".copyid-item", (e2) => {
contextMenu.remove();
require("electron").clipboard.write({text: hiddenObj.id});
});
BDFDB.appendContextMenu(contextMenu[0], e);
}
showAccessRoles (serverObj, channel, e, allowed) {
if ((e.type != "mouseenter" && e.type != "mouseover") || !serverObj || !channel) return;
var settings = BDFDB.getAllData(this, "settings");
var myMember = this.MemberStore.getMember(serverObj.id, BDFDB.myData.id);
var allowedRoles = [], allowedUsers = [], overwrittenRoles = [], deniedRoles = [], deniedUsers = [];
var everyoneDenied = false;
for (let id in channel.permissionOverwrites) {
if (settings.showAllowedRoles &&
channel.permissionOverwrites[id].type == "role" &&
(serverObj.roles[id].name != "@everyone") &&
(channel.permissionOverwrites[id].allow | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].allow) {
if (myMember.roles.includes(id) && !allowed) {
if (settings.showOverWrittenRoles) overwrittenRoles.push(serverObj.roles[id]);
}
else {
allowedRoles.push(serverObj.roles[id]);
}
}
else if (settings.showAllowedUsers &&
channel.permissionOverwrites[id].type == "member" &&
(channel.permissionOverwrites[id].allow | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].allow) {
let user = this.UserStore.getUser(id);
let member = this.MemberStore.getMember(serverObj.id,id);
if (user && member) allowedUsers.push(Object.assign({name:user.username},member));
}
if (settings.showDeniedRoles &&
channel.permissionOverwrites[id].type == "role" &&
(channel.permissionOverwrites[id].deny | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].deny) {
deniedRoles.push(serverObj.roles[id]);
if (serverObj.roles[id].name == "@everyone") everyoneDenied = true;
}
else if (settings.showDeniedUsers &&
channel.permissionOverwrites[id].type == "member" &&
(channel.permissionOverwrites[id].deny | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].deny) {
let user = this.UserStore.getUser(id);
let member = this.MemberStore.getMember(serverObj.id,id);
if (user && member) deniedUsers.push(Object.assign({name:user.username},member));
}
}
if (settings.showAllowedRoles && allowed && !everyoneDenied) {
allowedRoles.push({"name":"@everyone"});
}
var htmlString = ``;
if (settings.showTopic && !allowed && channel.topic && channel.topic.replace(/[\t\n\r\s]/g, "")) {
htmlString += `Topic:
`;
}
if (allowedRoles.length > 0 || overwrittenRoles.length > 0) {
htmlString += `Allowed Roles:
`;
for (let role of allowedRoles) {
let color = role.colorString ? BDFDB.color2COMP(role.colorString) : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(role.name)}
`;
}
for (let role of overwrittenRoles) {
let color = role.colorString ? BDFDB.color2COMP(role.colorString) : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(role.name)}
`;
}
htmlString += `
`;
}
if (allowedUsers.length > 0) {
htmlString += `Allowed Users:
`;
for (let user of allowedUsers) {
let color = user.colorString ? BDFDB.color2COMP(user.colorString) : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(user.nick ? user.nick : user.name)}
`;
}
htmlString += `
`;
}
if (deniedRoles.length > 0) {
htmlString += `Denied Roles:
`;
for (let role of deniedRoles) {
let color = role.colorString ? BDFDB.color2COMP(role.colorString) : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(role.name)}
`;
}
htmlString += `
`;
}
if (deniedUsers.length > 0) {
htmlString += `Denied Users:
`;
for (let user of deniedUsers) {
let color = user.colorString ? BDFDB.color2COMP(user.colorString) : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(user.nick ? user.nick : user.name)}
`;
}
htmlString += `
`;
}
if (htmlString) {
var width = window.outerWidth/2;
var tooltip = BDFDB.createTooltip(htmlString, e.currentTarget, {type:"right", selector:"showhiddenchannels-tooltip", html:true, style:`max-width: ${width < 200 ? 400 : width}px !important;`, delay:BDFDB.getData("hoverDelay", this, "amounts")});
tooltip.style.top = tooltip.style.top.replace("px","") - $(e.currentTarget).css("padding-bottom").replace("px","")/2 + $(e.currentTarget).css("padding-top").replace("px","")/2 + "px";
}
}
appendToChannelList (category) {
var channelList = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCN.scroller);
if (channelList && category) {
category.remove();
let count = parseInt(channelList.lastChild.previousSibling.className.split("-")[1])+1;
category.className = "container-" + count + " container-hidden";
channelList.insertBefore(category,channelList.lastChild);
}
}
}