//META{"name":"ShowHiddenChannels","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowHiddenChannels","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ShowHiddenChannels/ShowHiddenChannels.plugin.js"}*//
class ShowHiddenChannels {
getName () {return "ShowHiddenChannels";}
getVersion () {return "2.5.7";}
getAuthor () {return "DevilBro";}
getDescription () {return "Displays channels that are hidden from you by role restrictions.";}
constructor () {
this.changelog = {
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
};
this.patchModules = {
"Channels":["componentDidMount","componentDidUpdate"],
"ChannelItem":"componentDidMount",
"ChannelCategoryItem":"componentDidMount",
"StandardSidebarView":"componentWillUnmount"
};
}
initConstructor () {
this.categoryMarkup =
`
`;
this.channelMarkup =
``;
this.channelMessage = {
GUILD_TEXT: `enter the hidden text channel`,
GUILD_VOICE: `enter the hidden voice channel`,
GUILD_NEWS: `enter the hidden news channel`,
GUILD_STORE: `enter the hidden store channel`,
GUILD_CATEGORY: `open the hidden category`,
DEFAULT: `open the channel`,
}
this.channelIcons = {
GUILD_TEXT: `M5.88657 21C5.57547 21 5.3399 20.7189 5.39427 20.4126L6.00001 17H2.59511C2.28449 17 2.04905 16.7198 2.10259 16.4138L2.27759 15.4138C2.31946 15.1746 2.52722 15 2.77011 15H6.35001L7.41001 9H4.00511C3.69449 9 3.45905 8.71977 3.51259 8.41381L3.68759 7.41381C3.72946 7.17456 3.93722 7 4.18011 7H7.76001L8.39677 3.41262C8.43914 3.17391 8.64664 3 8.88907 3H9.87344C10.1845 3 10.4201 3.28107 10.3657 3.58738L9.76001 7H15.76L16.3968 3.41262C16.4391 3.17391 16.6466 3 16.8891 3H17.8734C18.1845 3 18.4201 3.28107 18.3657 3.58738L17.76 7H21.1649C21.4755 7 21.711 7.28023 21.6574 7.58619L21.4824 8.58619C21.4406 8.82544 21.2328 9 20.9899 9H17.41L16.35 15H19.7549C20.0655 15 20.301 15.2802 20.2474 15.5862L20.0724 16.5862C20.0306 16.8254 19.8228 17 19.5799 17H16L15.3632 20.5874C15.3209 20.8261 15.1134 21 14.8709 21H13.8866C13.5755 21 13.3399 20.7189 13.3943 20.4126L14 17H8.00001L7.36325 20.5874C7.32088 20.8261 7.11337 21 6.87094 21H5.88657ZM9.41045 9L8.35045 15H14.3504L15.4104 9H9.41045Z`,
GUILD_VOICE: `M11.383 3.07904C11.009 2.92504 10.579 3.01004 10.293 3.29604L6 8.00204H3C2.45 8.00204 2 8.45304 2 9.00204V15.002C2 15.552 2.45 16.002 3 16.002H6L10.293 20.71C10.579 20.996 11.009 21.082 11.383 20.927C11.757 20.772 12 20.407 12 20.002V4.00204C12 3.59904 11.757 3.23204 11.383 3.07904ZM14 5.00195V7.00195C16.757 7.00195 19 9.24595 19 12.002C19 14.759 16.757 17.002 14 17.002V19.002C17.86 19.002 21 15.863 21 12.002C21 8.14295 17.86 5.00195 14 5.00195ZM14 9.00195C15.654 9.00195 17 10.349 17 12.002C17 13.657 15.654 15.002 14 15.002V13.002C14.551 13.002 15 12.553 15 12.002C15 11.451 14.551 11.002 14 11.002V9.00195Z`,
GUILD_NEWS: `M22 7H19V3C19 2.448 18.553 2 18 2H2C1.447 2 1 2.448 1 3V21C1 21.552 1.447 22 2 22H20C20.266 22 20.52 21.895 20.707 21.707L22.707 19.707C22.895 19.519 23 19.265 23 18.999V7.999C23 7.448 22.553 7 22 7ZM9 18.999H3V16.999H9V18.999ZM9 15.999H3V13.999H9V15.999ZM9 13H3V11H9V13ZM16 18.999H10V16.999H16V18.999ZM16 15.999H10V13.999H16V15.999ZM16 13H10V11H16V13ZM16 8H3V5H16V8ZM21 18.585L20.586 18.999H19V8.999H21V18.585Z`,
GUILD_STORE: `M21.707 13.293l-11-11C10.519 2.105 10.266 2 10 2H3c-.553 0-1 .447-1 1v7c0 .266.105.519.293.707l11 11c.195.195.451.293.707.293s.512-.098.707-.293l7-7c.391-.391.391-1.023 0-1.414zM7 9c-1.106 0-2-.896-2-2 0-1.106.894-2 2-2 1.104 0 2 .894 2 2 0 1.104-.896 2-2 2z`,
GUILD_CATEGORY: `M9.6 1.6 L9.6 6.4 L3.2 6.4 L3.2 1.6 L9.6 1.6 Z M16 16 L22.4 16 L22.4 20.8 L16 20.8 L16 16.533333328 L16 16 Z M14.4 12.8 L8 12.8 L8 17.6 L14.4 17.6 L14.4 20.8 L8 20.8 L4.8 20.8 L4.8 8 L8 8 L8 9.6 L14.4 9.6 L14.4 12.8 Z`,
DEFAULT: `M 11.44 0 c 4.07 0 8.07 1.87 8.07 6.35 c 0 4.13 -4.74 5.72 -5.75 7.21 c -0.76 1.11 -0.51 2.67 -2.61 2.67 c -1.37 0 -2.03 -1.11 -2.03 -2.13 c 0 -3.78 5.56 -4.64 5.56 -7.76 c 0 -1.72 -1.14 -2.73 -3.05 -2.73 c -4.07 0 -2.48 4.19 -5.56 4.19 c -1.11 0 -2.07 -0.67 -2.07 -1.94 C 4 2.76 7.56 0 11.44 0 z M 11.28 18.3 c 1.43 0 2.61 1.17 2.61 2.61 c 0 1.43 -1.18 2.61 -2.61 2.61 c -1.43 0 -2.61 -1.17 -2.61 -2.61 C 8.68 19.48 9.85 18.3 11.28 18.3 z`
};
this.settingsMap = {
GUILD_TEXT: "showText",
GUILD_VOICE: "showVoice",
GUILD_NEWS: "showNews",
GUILD_STORE: "showStore",
GUILD_CATEGORY: "showCategory"
};
this.defaults = {
settings: {
showText: {value:true, inner:false, description:"Show hidden Textchannels:"},
showVoice: {value:true, inner:false, description:"Show hidden Voicechannels:"},
showNews: {value:true, inner:false, description:"Show hidden Newschannels:"},
showStore: {value:true, inner:false, description:"Show hidden Storechannels:"},
showCategory: {value:false, inner:false, description:"Show hidden Categories:"},
showForNormal: {value:false, inner:false, description:"Also show Roles/Users for visible Channels on hover:"},
showAllowedRoles: {value:true, inner:true, description:"Allowed Roles:"},
showOverWrittenRoles: {value:true, inner:true, description:"Include overwritten Roles in allowed Roles:"},
showAllowedUsers: {value:true, inner:true, description:"Specifically allowed Users:"},
showDeniedRoles: {value:true, inner:true, description:"Denied Roles:"},
showDeniedUsers: {value:true, inner:true, description:"Specifically denied Users:"},
showTopic: {value:false, inner:true, description:"The Topic of the Channel (only for hidden):"},
showChannelCategory: {value:false, inner:true, description:"The Category of the Channel (only for hidden):"},
showVoiceUsers: {value:false, inner:true, description:"All currently connected Users of a Voice Channel (only for hidden/locked):"}
},
amounts: {
hoverDelay: {value:0, min:0, description:"Tooltip delay in millisec:"}
}
};
}
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
var settings = BDFDB.getAllData(this, "settings");
var amounts = BDFDB.getAllData(this, "amounts");
var settingshtml = `${this.name}
`;
for (let key in settings) {
if (!this.defaults.settings[key].inner) settingshtml += `
`;
}
settingshtml += `
Display in the hover Tooltip:
`;
for (let key in settings) {
if (this.defaults.settings[key].inner) settingshtml += `
`;
}
for (let key in amounts) {
settingshtml += `
`;
}
settingshtml += `
`;
settingshtml += `
`;
let settingspanel = BDFDB.htmlToElement(settingshtml);
BDFDB.initElements(settingspanel, this);
return settingspanel;
}
//legacy
load () {}
start () {
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
var 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 (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
}
initialize () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.loadMessage(this);
BDFDB.WebModules.forceAllUpdates(this, "Channels");
}
else {
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
}
}
stop () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
BDFDB.removeEles(".container-hidden");
BDFDB.unloadMessage(this);
}
}
// begin of own functions
processChannels (instance, wrapper, returnvalue, methodnames) {
if (instance.props && instance.props.guild) {
if (methodnames.includes("componentDidMount")) this.appendHiddenContainer(instance.props.guild);
if (methodnames.includes("componentDidUpdate")) this.reappendHiddenContainer(instance.props.guild);
}
}
processChannelItem (instance, wrapper, returnvalue) {
if (instance.props && instance.props.channel) this.reappendHiddenContainer(BDFDB.LibraryModules.GuildStore.getGuild(instance.props.channel.guild_id));
}
processChannelCategoryItem (instance, wrapper, returnvalue) {
if (instance.props && instance.props.channel) this.reappendHiddenContainer(BDFDB.LibraryModules.GuildStore.getGuild(instance.props.channel.guild_id));
}
processStandardSidebarView (instance, wrapper, returnvalue) {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
BDFDB.WebModules.forceAllUpdates(this, "Channels");
}
}
appendHiddenContainer (guild) {
BDFDB.removeEles(".container-hidden");
if (!guild) return;
this.currentGuild = guild.id;
var allChannels = BDFDB.LibraryModules.ChannelStore.getChannels();
var shownChannels = BDFDB.LibraryModules.GuildChannelStore.getChannels(guild.id);
var hiddenChannels = {};
for (let type in BDFDB.DiscordConstants.ChannelTypes) hiddenChannels[BDFDB.DiscordConstants.ChannelTypes[type]] = [];
for (let channel_id in allChannels) {
var channel = allChannels[channel_id];
if (channel.guild_id == guild.id) {
var isHidden = true;
if (channel.type == BDFDB.DiscordConstants.ChannelTypes.GUILD_CATEGORY) {
for (let type in BDFDB.DiscordConstants.ChannelTypes) {
let shownChannelsOfType = BDFDB.DiscordConstants.ChannelTypes[type] == 0 && shownChannels.SELECTABLE ? shownChannels.SELECTABLE : shownChannels[BDFDB.DiscordConstants.ChannelTypes[type]];
if (shownChannelsOfType) for (let shownChannel of shownChannelsOfType) {
if (!channel.id || shownChannel.channel.parent_id == channel.id) {
isHidden = false;
break;
}
}
}
}
if (BDFDB.isUserAllowedTo("VIEW_CHANNEL", BDFDB.myData.id, channel.id)) isHidden = false;
if (isHidden) hiddenChannels[channel.type].push(channel);
}
}
var settings = BDFDB.getAllData(this, "settings");
var count = 0;
for (let type in BDFDB.DiscordConstants.ChannelTypes) {
if (this.settingsMap[type] && !settings[this.settingsMap[type]]) hiddenChannels[BDFDB.DiscordConstants.ChannelTypes[type]] = [];
BDFDB.sortArrayByKey(hiddenChannels[BDFDB.DiscordConstants.ChannelTypes[type]], "name");
count += hiddenChannels[BDFDB.DiscordConstants.ChannelTypes[type]].length;
}
hiddenChannels.count = count;
if (count > 0) {
var category = BDFDB.htmlToElement(this.categoryMarkup);
var wrapper = category.querySelector(BDFDB.dotCN.categorywrapper);
category.setAttribute("guild", guild.id);
wrapper.addEventListener("click", () => {
BDFDB.toggleClass(wrapper, BDFDB.disCN.categorycollapsed);
var visibile = !BDFDB.containsClass(wrapper, BDFDB.disCN.categorycollapsed);
BDFDB.toggleEles(category.querySelectorAll(BDFDB.dotCN.channelcontainerdefault), visibile);
BDFDB.saveData(guild.id, visibile, this, "categorystatus");
});
for (let type in BDFDB.DiscordConstants.ChannelTypes) for (let hiddenChannel of hiddenChannels[BDFDB.DiscordConstants.ChannelTypes[type]]) this.createChannel(guild, category, hiddenChannel, type);
var isvisibile = BDFDB.loadData(guild.id, this, "categorystatus") === true;
BDFDB.toggleClass(wrapper, BDFDB.disCN.categorycollapsed, !isvisibile);
BDFDB.toggleEles(category.querySelectorAll(BDFDB.dotCN.channelcontainerdefault), isvisibile);
this.reappendHiddenContainer(guild, category);
}
let channellist = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCN.scroller);
if (channellist) {
BDFDB.removeEventListener(this, channellist, "mouseenter", BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault);
if (settings.showForNormal) BDFDB.addEventListener(this, channellist, "mouseenter", BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault, e => {
if (!BDFDB.containsClass(e.currentTarget, "hidden-channel")) {
var channel = BDFDB.getKeyInformation({"node":e.currentTarget,"key":"channel"});
if (channel) this.showAccessRoles(guild, channel, e, true);
}
});
}
}
createChannel (guild, category, info, type) {
let channel = BDFDB.htmlToElement(this.channelMarkup);
channel.querySelector(BDFDB.dotCN.channelname).innerText = info.name;
channel.querySelector(BDFDB.dotCNS.channelicon + "mask").setAttribute("id", `showHiddenChannelsMask${info.id}`);
let iconinner = channel.querySelector(BDFDB.dotCNS.channelicon + ".hidden-icon-inner");
iconinner.setAttribute("d", this.channelIcons[type] ? this.channelIcons[type] : this.channelIcons.DEFAULT);
iconinner.setAttribute("mask", `url(#showHiddenChannelsMask${info.id})`);
this.setReactInstanceOfChannel(info, channel);
BDFDB.addChildEventListener(channel, "mouseenter mouseleave", BDFDB.dotCN.channelwrapper, e => {
this.showAccessRoles(guild, info, e, false);
});
channel.addEventListener("click", () => {
BDFDB.showToast(`You can not ${this.channelMessage[type] ? this.channelMessage[type] : this.channelMessage.DEFAULT} ${BDFDB.encodeToHTML(info.name)}.`, {type:"error", html:true});
});
channel.addEventListener("contextmenu", e => {
this.createHiddenObjContextMenu(guild, info, type, e);
});
category.appendChild(channel);
}
reappendHiddenContainer (guild, category = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCNS.scroller + ".container-hidden")) {
if (!guild) return;
if (guild.id != this.currentGuild) this.appendHiddenContainer(guild);
else if (category) {
var scroller = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCN.scroller);
if (!scroller || scroller.lastChild.previousSibling == category) return;
category.remove();
let count = parseInt(scroller.lastChild.previousSibling.className.split("-")[1])+1;
scroller.insertBefore(category, scroller.lastChild);
}
}
setReactInstanceOfChannel (guild, div) {
var reactInstance = BDFDB.React.createElement(div);
reactInstance.memoizedProps = {channel:guild};
div.__reactInternalInstance = reactInstance;
}
createHiddenObjContextMenu (guild, channel, type, e) {
BDFDB.stopEvent(e);
BDFDB.openChannelContextMenu(channel, e);
}
showAccessRoles (guild, channel, e, allowed) {
if ((e.type != "mouseenter" && e.type != "mouseover") || !guild || !channel) return;
var settings = BDFDB.getAllData(this, "settings");
var myMember = BDFDB.LibraryModules.MemberStore.getMember(guild.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" && (guild.roles[id] && guild.roles[id].name != "@everyone") && ((channel.permissionOverwrites[id].allow | BDFDB.DiscordConstants.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].allow || (channel.permissionOverwrites[id].allow | BDFDB.DiscordConstants.Permissions.CONNECT) == channel.permissionOverwrites[id].allow)) {
if (myMember.roles.includes(id) && !allowed) {
if (settings.showOverWrittenRoles) overwrittenRoles.push(guild.roles[id]);
}
else {
allowedRoles.push(guild.roles[id]);
}
}
else if (settings.showAllowedUsers && channel.permissionOverwrites[id].type == "member" && ((channel.permissionOverwrites[id].allow | BDFDB.DiscordConstants.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].allow || (channel.permissionOverwrites[id].allow | BDFDB.DiscordConstants.Permissions.CONNECT) == channel.permissionOverwrites[id].allow)) {
let user = BDFDB.LibraryModules.UserStore.getUser(id);
let member = BDFDB.LibraryModules.MemberStore.getMember(guild.id,id);
if (user && member) allowedUsers.push(Object.assign({name:user.username,id:user.id},member));
}
if (settings.showDeniedRoles && channel.permissionOverwrites[id].type == "role" && ((channel.permissionOverwrites[id].deny | BDFDB.DiscordConstants.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].deny || (channel.permissionOverwrites[id].deny | BDFDB.DiscordConstants.Permissions.CONNECT) == channel.permissionOverwrites[id].deny)) {
deniedRoles.push(guild.roles[id]);
if (guild.roles[id] && guild.roles[id].name == "@everyone") everyoneDenied = true;
}
else if (settings.showDeniedUsers && channel.permissionOverwrites[id].type == "member" && ((channel.permissionOverwrites[id].deny | BDFDB.DiscordConstants.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].deny || (channel.permissionOverwrites[id].deny | BDFDB.DiscordConstants.Permissions.CONNECT) == channel.permissionOverwrites[id].deny)) {
let user = BDFDB.LibraryModules.UserStore.getUser(id);
let member = BDFDB.LibraryModules.MemberStore.getMember(guild.id, id);
if (user && member) deniedUsers.push(Object.assign({name:user.username,id:user.id},member));
}
}
if (settings.showAllowedRoles && allowed && !everyoneDenied) {
allowedRoles.push({"name":"@everyone"});
}
var htmlString = ``;
if (settings.showChannelCategory && !allowed && channel.parent_id) {
htmlString += `Category:
${BDFDB.encodeToHTML(BDFDB.LibraryModules.ChannelStore.getChannel(channel.parent_id).name)}
`;
}
if (settings.showTopic && !allowed && channel.topic && channel.topic.replace(/[\t\n\r\s]/g, "")) {
htmlString += `Topic:
${BDFDB.encodeToHTML(channel.topic)}
`;
}
if (settings.showVoiceUsers && channel.type == BDFDB.DiscordConstants.ChannelTypes.GUILD_VOICE && (!allowed || e.currentTarget.querySelector(BDFDB.dotCN.channelmodelocked))) {
let voicestates = BDFDB.LibraryModules.VoiceUtils.getVoiceStatesForChannel(channel);
if (voicestates.length > 0) {
htmlString += `Connected Voice Users:
`;
for (let voicestate of voicestates) {
let user = BDFDB.LibraryModules.UserStore.getUser(voicestate.userId);
let member = BDFDB.LibraryModules.MemberStore.getMember(guild.id, voicestate.userId);
if (user && member) {
let color = member.colorString ? BDFDB.colorCONVERT(member.colorString, "RGBCOMP") : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(member.nick || user.username)}
`;
}
}
htmlString += `
`;
}
}
if (allowedRoles.length > 0 || overwrittenRoles.length > 0) {
htmlString += `Allowed Roles:
`;
for (let role of allowedRoles) {
let color = role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(role.name)}
`;
}
for (let role of overwrittenRoles) {
let color = role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [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.colorCONVERT(user.colorString, "RGBCOMP") : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(user.nick || user.name)}
`;
}
htmlString += `
`;
}
if (deniedRoles.length > 0) {
htmlString += `Denied Roles:
`;
for (let role of deniedRoles) {
let color = role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [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.colorCONVERT(user.colorString, "RGBCOMP") : [255,255,255];
htmlString += `
${BDFDB.encodeToHTML(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")});
var style = getComputedStyle(e.currentTarget);
tooltip.style.setProperty("top", BDFDB.getRects(tooltip).top - style.paddingBottom.replace("px","")/2 + style.paddingTop.replace("px","")/2 + "px");
}
}
}