Advertisement
Guest User

Hax4Dan

a guest
Jun 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.23 KB | None | 0 0
  1. //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"}*//
  2.  
  3. class ShowHiddenChannels {
  4. getName () {return "ShowHiddenChannels";}
  5.  
  6. getVersion () {return "2.5.3";}
  7.  
  8. getAuthor () {return "DevilBro";}
  9.  
  10. getDescription () {return "Displays channels that are hidden from you by role restrictions.";}
  11.  
  12. initConstructor () {
  13. this.changelog = {
  14. "fixed":[["PermissionsViewer","Readded support for PermissionsViewer"]]
  15. };
  16.  
  17. this.patchModules = {
  18. "Channels":["componentDidMount","componentDidUpdate"],
  19. "ChannelItem":"componentDidMount",
  20. "ChannelCategoryItem":"componentDidMount",
  21. "StandardSidebarView":"componentWillUnmount"
  22. };
  23.  
  24. this.categoryMarkup =
  25. `<div class="container-hidden">
  26. <div class="${BDFDB.disCN.categorycontainerdefault} hidden-category" draggable="false">
  27. <div tabindex="0" class="${BDFDB.disCNS.categoryiconvisibility + BDFDB.disCNS.categorywrapper + BDFDB.disCNS.categorycollapsed + BDFDB.disCNS.categoryclickable}" role="button">
  28. <svg class="${BDFDB.disCN.categoryicon}" width="24" height="24" viewBox="0 0 24 24">
  29. <path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M16.59 8.59004L12 13.17L7.41 8.59004L6 10L12 16L18 10L16.59 8.59004Z"></path>
  30. </svg>
  31. <div class="${BDFDB.disCN.categoryname}">hidden</div>
  32. <div class="${BDFDB.disCN.categorychildren}"></div>
  33. </div>
  34. </div>
  35. </div>`;
  36.  
  37. this.channelMarkup =
  38. `<div class="${BDFDB.disCN.channelcontainerdefault} hidden-channel">
  39. <div tabindex="0" class="${BDFDB.disCNS.channeliconvisibility + BDFDB.disCNS.channelwrapper + BDFDB.disCN.channelmodelocked}" role="button">
  40. <div class="${BDFDB.disCN.channelcontent}">
  41. <svg class="${BDFDB.disCN.channelicon} hidden-icon" width="24" height="24" viewBox="0 0 24 24">
  42. <mask fill="black">
  43. <path d="M0 0H24V24H0Z" fill="white"></path>
  44. <path d="M24 0H13V12H24Z" fill="black"></path>
  45. </mask>
  46. <path class="hidden-icon-inner" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d=""></path>
  47. <path fill="currentColor" d="M21.025 5V4C21.025 2.88 20.05 2 19 2C17.95 2 17 2.88 17 4V5C16.4477 5 16 5.44772 16 6V9C16 9.55228 16.4477 10 17 10H19H21C21.5523 10 22 9.55228 22 9V5.975C22 5.43652 21.5635 5 21.025 5ZM20 5H18V4C18 3.42857 18.4667 3 19 3C19.5333 3 20 3.42857 20 4V5Z"></path>
  48. </svg>
  49. <div class="${BDFDB.disCN.channelname}"></div>
  50. <div class="${BDFDB.disCN.channelchildren}"></div>
  51. </div>
  52. </div>
  53. </div>`;
  54.  
  55. this.channelMessage = {
  56. GUILD_TEXT: `enter the hidden text channel`,
  57. GUILD_VOICE: `enter the hidden voice channel`,
  58. GUILD_NEWS: `enter the hidden news channel`,
  59. GUILD_STORE: `enter the hidden store channel`,
  60. GUILD_CATEGORY: `open the hidden category`,
  61. DEFAULT: `open the channel`,
  62. }
  63.  
  64. this.channelIcons = {
  65. 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`,
  66. 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`,
  67. 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`,
  68. 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`,
  69. 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`,
  70. 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`
  71. };
  72.  
  73. this.settingsMap = {
  74. GUILD_TEXT: "showText",
  75. GUILD_VOICE: "showVoice",
  76. GUILD_NEWS: "showNews",
  77. GUILD_STORE: "showStore",
  78. GUILD_CATEGORY: "showCategory"
  79. };
  80.  
  81. this.defaults = {
  82. settings: {
  83. showText: {value:true, inner:false, description:"Show hidden Textchannels:"},
  84. showVoice: {value:true, inner:false, description:"Show hidden Voicechannels:"},
  85. showNews: {value:true, inner:false, description:"Show hidden Newschannels:"},
  86. showStore: {value:true, inner:false, description:"Show hidden Storechannels:"},
  87. showCategory: {value:false, inner:false, description:"Show hidden Categories:"},
  88. showForNormal: {value:false, inner:false, description:"Also show Roles/Users for visible Channels on hover:"},
  89. showAllowedRoles: {value:true, inner:true, description:"Allowed Roles:"},
  90. showOverWrittenRoles: {value:true, inner:true, description:"Include overwritten Roles in allowed Roles:"},
  91. showAllowedUsers: {value:true, inner:true, description:"Specifically allowed Users:"},
  92. showDeniedRoles: {value:true, inner:true, description:"Denied Roles:"},
  93. showDeniedUsers: {value:true, inner:true, description:"Specifically denied Users:"},
  94. showTopic: {value:false, inner:true, description:"The Topic of the Channel:"},
  95. showChannelCategory: {value:false, inner:true, description:"The Category of the Channel:"},
  96. showVoiceUsers: {value:false, inner:true, description:"All currently connected Users of a Voice Channel:"}
  97. },
  98. amounts: {
  99. hoverDelay: {value:0, min:0, description:"Tooltip delay in millisec:"}
  100. }
  101. };
  102. }
  103.  
  104. getSettingsPanel () {
  105. if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
  106. var settings = BDFDB.getAllData(this, "settings");
  107. var amounts = BDFDB.getAllData(this, "amounts");
  108. var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
  109. for (let key in settings) {
  110. if (!this.defaults.settings[key].inner) settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
  111. }
  112. settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 0 0 auto;">Display in the hover Tooltip:</h3></div><div class="BDFDB-settings-inner-list">`;
  113. for (let key in settings) {
  114. if (this.defaults.settings[key].inner) settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
  115. }
  116. for (let key in amounts) {
  117. settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCN.flexchild}" style="flex: 0 0 50%;">${this.defaults.amounts[key].description}</h3><div class="${BDFDB.disCN.inputwrapper} inputNumberWrapper ${BDFDB.disCNS.vertical + BDFDB.disCNS.flex + BDFDB.disCNS.directioncolumn}" style="flex: 1 1 auto;"><span class="numberinput-buttons-zone"><span class="numberinput-button-up"></span><span class="numberinput-button-down"></span></span><input type="number"${(!isNaN(this.defaults.amounts[key].min) && this.defaults.amounts[key].min !== null ? ' min="' + this.defaults.amounts[key].min + '"' : '') + (!isNaN(this.defaults.amounts[key].max) && this.defaults.amounts[key].max !== null ? ' max="' + this.defaults.amounts[key].max + '"' : '')} option="${key}" value="${amounts[key]}" class="${BDFDB.disCNS.inputdefault + BDFDB.disCNS.input + BDFDB.disCN.size16} amount-input"></div></div>`;
  118. }
  119. settingshtml += `</div>`;
  120. settingshtml += `</div></div>`;
  121.  
  122. let settingspanel = BDFDB.htmlToElement(settingshtml);
  123.  
  124. BDFDB.initElements(settingspanel, this);
  125.  
  126. return settingspanel;
  127. }
  128.  
  129. //legacy
  130. load () {}
  131.  
  132. start () {
  133. if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
  134. if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
  135. var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
  136. if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
  137. if (libraryScript) libraryScript.remove();
  138. libraryScript = document.createElement("script");
  139. libraryScript.setAttribute("id", "BDFDBLibraryScript");
  140. libraryScript.setAttribute("type", "text/javascript");
  141. libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
  142. libraryScript.setAttribute("date", performance.now());
  143. libraryScript.addEventListener("load", () => {this.initialize();});
  144. document.head.appendChild(libraryScript);
  145. this.libLoadTimeout = setTimeout(() => {
  146. libraryScript.remove();
  147. require("request")("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => {
  148. if (body) {
  149. libraryScript = document.createElement("script");
  150. libraryScript.setAttribute("id", "BDFDBLibraryScript");
  151. libraryScript.setAttribute("type", "text/javascript");
  152. libraryScript.setAttribute("date", performance.now());
  153. libraryScript.innerText = body;
  154. document.head.appendChild(libraryScript);
  155. }
  156. this.initialize();
  157. });
  158. }, 15000);
  159. }
  160. else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
  161. this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
  162. }
  163.  
  164. initialize () {
  165. if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
  166. if (this.started) return;
  167. BDFDB.loadMessage(this);
  168.  
  169. this.UserUtils = BDFDB.WebModules.findByProperties("getUsers", "getUser");
  170. this.MemberUtils = BDFDB.WebModules.findByProperties("getMember", "getMembers");
  171. this.GuildUtils = BDFDB.WebModules.findByProperties("getGuilds", "getGuild");
  172. this.ChannelUtils = BDFDB.WebModules.findByProperties("getChannels", "getDMFromUserId");
  173. this.VoiceUtils = BDFDB.WebModules.findByProperties("getAllVoiceStates", "getVoiceStatesForChannel");
  174. this.GuildChannels = BDFDB.WebModules.findByProperties("getChannels", "getDefaultChannel");
  175. this.ChannelTypes = BDFDB.WebModules.findByProperties("ChannelTypes").ChannelTypes;
  176. this.Permissions = BDFDB.WebModules.findByProperties("Permissions", "ActivityTypes").Permissions;
  177.  
  178. BDFDB.WebModules.forceAllUpdates(this, "Channels");
  179. }
  180. else {
  181. console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
  182. }
  183. }
  184.  
  185. stop () {
  186. if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
  187. BDFDB.removeEles(".container-hidden");
  188. BDFDB.unloadMessage(this);
  189. }
  190. }
  191.  
  192.  
  193. // begin of own functions
  194.  
  195. processChannels (instance, wrapper, methodnames) {
  196. if (instance.props && instance.props.guild) {
  197. if (methodnames.includes("componentDidMount")) this.appendHiddenContainer(instance.props.guild);
  198. if (methodnames.includes("componentDidUpdate")) this.reappendHiddenContainer(instance.props.guild);
  199. }
  200. }
  201.  
  202. processChannelItem (instance, wrapper) {
  203. if (instance.props && instance.props.channel) this.reappendHiddenContainer(this.GuildUtils.getGuild(instance.props.channel.guild_id));
  204. }
  205.  
  206. processChannelCategoryItem (instance, wrapper) {
  207. if (instance.props && instance.props.channel) this.reappendHiddenContainer(this.GuildUtils.getGuild(instance.props.channel.guild_id));
  208. }
  209.  
  210. processStandardSidebarView (instance, wrapper) {
  211. if (this.SettingsUpdated) {
  212. delete this.SettingsUpdated;
  213. BDFDB.WebModules.forceAllUpdates(this, "Channels");
  214. }
  215. }
  216.  
  217. appendHiddenContainer (guild) {
  218. BDFDB.removeEles(".container-hidden");
  219. if (!guild) return;
  220. this.currentGuild = guild.id;
  221. var allChannels = this.ChannelUtils.getChannels();
  222. var shownChannels = this.GuildChannels.getChannels(guild.id);
  223. var hiddenChannels = {};
  224.  
  225. for (let type in this.ChannelTypes) hiddenChannels[this.ChannelTypes[type]] = [];
  226.  
  227. for (let channel_id in allChannels) {
  228. var channel = allChannels[channel_id];
  229. if (channel.guild_id == guild.id) {
  230. var isHidden = true;
  231. if (channel.type == this.ChannelTypes.GUILD_CATEGORY) {
  232. for (let type in this.ChannelTypes) {
  233. let shownChannelsOfType = this.ChannelTypes[type] == 0 && shownChannels.SELECTABLE ? shownChannels.SELECTABLE : shownChannels[this.ChannelTypes[type]];
  234. if (shownChannelsOfType) for (let shownChannel of shownChannelsOfType) {
  235. if (!channel.id || shownChannel.channel.parent_id == channel.id) {
  236. isHidden = false;
  237. break;
  238. }
  239. }
  240. }
  241. }
  242. if (BDFDB.isUserAllowedTo("VIEW_CHANNEL", BDFDB.myData.id, channel.id)) isHidden = false;
  243. if (isHidden) hiddenChannels[channel.type].push(channel);
  244. }
  245. }
  246.  
  247. var settings = BDFDB.getAllData(this, "settings");
  248. var count = 0;
  249. for (let type in this.ChannelTypes) {
  250. if (this.settingsMap[type] && !settings[this.settingsMap[type]]) hiddenChannels[this.ChannelTypes[type]] = [];
  251. BDFDB.sortArrayByKey(hiddenChannels[this.ChannelTypes[type]], "name");
  252. count += hiddenChannels[this.ChannelTypes[type]].length;
  253. }
  254. hiddenChannels.count = count;
  255.  
  256. if (count > 0) {
  257. var category = BDFDB.htmlToElement(this.categoryMarkup);
  258. var wrapper = category.querySelector(BDFDB.dotCN.categorywrapper);
  259. category.setAttribute("guild", guild.id);
  260. wrapper.addEventListener("click", () => {
  261. BDFDB.toggleClass(wrapper, BDFDB.disCN.categorycollapsed);
  262.  
  263. var visibile = !BDFDB.containsClass(wrapper, BDFDB.disCN.categorycollapsed);
  264. BDFDB.toggleEles(category.querySelectorAll(BDFDB.dotCN.channelcontainerdefault), visibile);
  265. BDFDB.saveData(guild.id, visibile, this, "categorystatus");
  266. });
  267.  
  268. for (let type in this.ChannelTypes) for (let hiddenChannel of hiddenChannels[this.ChannelTypes[type]]) this.createChannel(guild, category, hiddenChannel, type);
  269.  
  270. var isvisibile = BDFDB.loadData(guild.id, this, "categorystatus") === true;
  271. BDFDB.toggleClass(wrapper, BDFDB.disCN.categorycollapsed, !isvisibile);
  272. BDFDB.toggleEles(category.querySelectorAll(BDFDB.dotCN.channelcontainerdefault), isvisibile);
  273.  
  274. this.reappendHiddenContainer(guild, category);
  275. }
  276. let channellist = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCN.scroller);
  277. if (channellist) {
  278. BDFDB.removeEventListener(this, channellist, "mouseenter", BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault);
  279. if (settings.showForNormal) BDFDB.addEventListener(this, channellist, "mouseenter", BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.categorycontainerdefault, e => {
  280. if (!BDFDB.containsClass(e.currentTarget, "hidden-channel")) {
  281. var channel = BDFDB.getKeyInformation({"node":e.currentTarget,"key":"channel"});
  282. if (channel) this.showAccessRoles(guild, channel, e, false);
  283. }
  284. });
  285. }
  286. }
  287.  
  288. createChannel (guild, category, info, type) {
  289. let channel = BDFDB.htmlToElement(this.channelMarkup);
  290. channel.querySelector(BDFDB.dotCN.channelname).innerText = info.name;
  291. channel.querySelector(BDFDB.dotCNS.channelicon + "mask").setAttribute("id", `showHiddenChannelsMask${info.id}`);
  292. let iconinner = channel.querySelector(BDFDB.dotCNS.channelicon + ".hidden-icon-inner");
  293. iconinner.setAttribute("d", this.channelIcons[type] ? this.channelIcons[type] : this.channelIcons.DEFAULT);
  294. iconinner.setAttribute("mask", `url(#showHiddenChannelsMask${info.id})`);
  295. this.setReactInstanceOfChannel(info, channel);
  296. BDFDB.addChildEventListener(channel, "mouseenter mouseleave", BDFDB.dotCN.channelwrapper, e => {
  297. this.showAccessRoles(guild, info, e, false);
  298. });
  299. channel.addEventListener("click", () => {
  300. BDFDB.showToast(`You can not ${this.channelMessage[type] ? this.channelMessage[type] : this.channelMessage.DEFAULT}&nbsp;&nbsp;<strong>${BDFDB.encodeToHTML(info.name)}</strong>.`, {type:"error", html:true});
  301. });
  302. channel.addEventListener("contextmenu", e => {
  303. this.createHiddenObjContextMenu(guild, info, type, e);
  304. });
  305. category.appendChild(channel);
  306. }
  307.  
  308. reappendHiddenContainer (guild, category = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCNS.scroller + ".container-hidden")) {
  309. if (!guild) return;
  310. if (guild.id != this.currentGuild) this.appendHiddenContainer(guild);
  311. else if (category) {
  312. var scroller = document.querySelector(BDFDB.dotCNS.channels + BDFDB.dotCN.scroller);
  313. if (!scroller || scroller.lastChild.previousSibling == category) return;
  314. category.remove();
  315. let count = parseInt(scroller.lastChild.previousSibling.className.split("-")[1])+1;
  316. scroller.insertBefore(category, scroller.lastChild);
  317. }
  318. }
  319.  
  320. setReactInstanceOfChannel (guild, div) {
  321. var reactInstance = BDFDB.React.createElement(div);
  322. reactInstance.memoizedProps = {channel:guild};
  323. div.__reactInternalInstance = reactInstance;
  324. }
  325.  
  326. createHiddenObjContextMenu (guild, channel, type, e) {
  327. BDFDB.stopEvent(e);
  328. var contextMenu = BDFDB.htmlToElement(`<div class="${BDFDB.disCN.contextmenu} showhiddenchannels-contextmenu">${BDFDB.isPluginEnabled("PermissionsViewer") ? '<div class="' + BDFDB.disCN.contextmenuitemgroup + '"><div class="' + BDFDB.disCN.contextmenuitem + '" style="display: none !important;"></div></div>' : ''}<div class="${BDFDB.disCN.contextmenuitemgroup}"><div class="${BDFDB.disCN.contextmenuitem} permissionviewer-item"><span></span><div class="${BDFDB.disCN.contextmenuhint}"></div></div><div class="${BDFDB.disCN.contextmenuitem} copyid-item"><span>${BDFDB.LanguageStrings.COPY_ID}</span><div class="${BDFDB.disCN.contextmenuhint}"></div></div></div></div>`);
  329. var permissionvieweritem = contextMenu.querySelector(".permissionviewer-item");
  330. if (BDFDB.isPluginEnabled("PermissionsViewer")) {
  331. permissionvieweritem.firstElementChild.innerText = window.bdplugins.PermissionsViewer.plugin.strings.contextMenuLabel;
  332. permissionvieweritem.addEventListener("click", () => {
  333. contextMenu.remove();
  334. if (!Object.keys(channel.permissionOverwrites).length) BDFDB.showToast(`#${channel.name} has no permission overrides`, {type: "info"});
  335. else window.bdplugins.PermissionsViewer.plugin.showModal(window.bdplugins.PermissionsViewer.plugin.createModalChannel(channel.name, channel, guild));
  336. });
  337. }
  338. else BDFDB.removeEles(permissionvieweritem);
  339. var reactInstance = BDFDB.React.createElement(contextMenu);
  340. reactInstance.memoizedProps = {displayName:"ChannelDeleteGroup",guild,channel};
  341. reactInstance.return = {memoizedProps:{type:("CHANNEL_LIST_" + type),guild,channel}};
  342. contextMenu.__reactInternalInstance = reactInstance;
  343. BDFDB.addChildEventListener(contextMenu, "click", ".copyid-item", e2 => {
  344. contextMenu.remove();
  345. require("electron").clipboard.write({text: channel.id});
  346. });
  347.  
  348. BDFDB.appendContextMenu(contextMenu, e);
  349. }
  350.  
  351. showAccessRoles (guild, channel, e, allowed) {
  352. if ((e.type != "mouseenter" && e.type != "mouseover") || !guild || !channel) return;
  353. var settings = BDFDB.getAllData(this, "settings");
  354. var myMember = this.MemberUtils.getMember(guild.id, BDFDB.myData.id);
  355. var allowedRoles = [], allowedUsers = [], overwrittenRoles = [], deniedRoles = [], deniedUsers = [];
  356. var everyoneDenied = false;
  357. for (let id in channel.permissionOverwrites) {
  358. if (settings.showAllowedRoles && channel.permissionOverwrites[id].type == "role" && (guild.roles[id] && guild.roles[id].name != "@everyone") && ((channel.permissionOverwrites[id].allow | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].allow || (channel.permissionOverwrites[id].allow | this.Permissions.CONNECT) == channel.permissionOverwrites[id].allow)) {
  359. if (myMember.roles.includes(id) && !allowed) {
  360. if (settings.showOverWrittenRoles) overwrittenRoles.push(guild.roles[id]);
  361. }
  362. else {
  363. allowedRoles.push(guild.roles[id]);
  364. }
  365. }
  366. else if (settings.showAllowedUsers && channel.permissionOverwrites[id].type == "member" && ((channel.permissionOverwrites[id].allow | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].allow || (channel.permissionOverwrites[id].allow | this.Permissions.CONNECT) == channel.permissionOverwrites[id].allow)) {
  367. let user = this.UserUtils.getUser(id);
  368. let member = this.MemberUtils.getMember(guild.id,id);
  369. if (user && member) allowedUsers.push(Object.assign({name:user.username,id:user.id},member));
  370. }
  371. if (settings.showDeniedRoles && channel.permissionOverwrites[id].type == "role" && ((channel.permissionOverwrites[id].deny | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].deny || (channel.permissionOverwrites[id].deny | this.Permissions.CONNECT) == channel.permissionOverwrites[id].deny)) {
  372. deniedRoles.push(guild.roles[id]);
  373. if (guild.roles[id] && guild.roles[id].name == "@everyone") everyoneDenied = true;
  374. }
  375. else if (settings.showDeniedUsers && channel.permissionOverwrites[id].type == "member" && ((channel.permissionOverwrites[id].deny | this.Permissions.VIEW_CHANNEL) == channel.permissionOverwrites[id].deny || (channel.permissionOverwrites[id].deny | this.Permissions.CONNECT) == channel.permissionOverwrites[id].deny)) {
  376. let user = this.UserUtils.getUser(id);
  377. let member = this.MemberUtils.getMember(guild.id, id);
  378. if (user && member) deniedUsers.push(Object.assign({name:user.username,id:user.id},member));
  379. }
  380. }
  381. if (settings.showAllowedRoles && allowed && !everyoneDenied) {
  382. allowedRoles.push({"name":"@everyone"});
  383. }
  384. var htmlString = ``;
  385. if (settings.showChannelCategory && !allowed && channel.parent_id) {
  386. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Category:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}"><div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-category" style="border-color: rgba(255, 255, 255, 0.6); height: unset !important; padding-top: 5px; padding-bottom: 5px; max-width: ${window.outerWidth/3}px; text-transform: uppercase;">${BDFDB.encodeToHTML(this.ChannelUtils.getChannel(channel.parent_id).name)}</div></div>`;
  387. }
  388. if (settings.showTopic && !allowed && channel.topic && channel.topic.replace(/[\t\n\r\s]/g, "")) {
  389. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Topic:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}"><div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-topic" style="border-color: rgba(255, 255, 255, 0.6); height: unset !important; padding-top: 5px; padding-bottom: 5px; max-width: ${window.outerWidth/3}px">${BDFDB.encodeToHTML(channel.topic)}</div></div>`;
  390. }
  391. if (settings.showVoiceUsers && (!allowed || e.currentTarget.querySelector(BDFDB.dotCN.channelnamelockedvoice)) && channel.type == this.ChannelTypes.GUILD_VOICE) {
  392. let voicestates = this.VoiceUtils.getVoiceStatesForChannel(guild.id, channel.id);
  393. if (voicestates.length > 0) {
  394. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Connected Voice Users:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}">`;
  395. for (let voicestate of voicestates) {
  396. let user = this.UserUtils.getUser(voicestate.userId);
  397. let member = this.MemberUtils.getMember(guild.id, voicestate.userId);
  398. if (user && member) {
  399. let color = member.colorString ? BDFDB.colorCONVERT(member.colorString, "RGBCOMP") : [255,255,255];
  400. htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-voiceuser" style="padding-left: 0; border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCNS.avatarimage + BDFDB.disCN.avatarxsmall}" style="margin-right: 4px; z-index: 1003; background-image: url(${BDFDB.getUserAvatar(user.id)});"></div><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.encodeToHTML(member.nick || user.username)}</div></div>`;
  401. }
  402. }
  403. htmlString += `</div>`;
  404. }
  405. }
  406. if (allowedRoles.length > 0 || overwrittenRoles.length > 0) {
  407. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Allowed Roles:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}">`;
  408. for (let role of allowedRoles) {
  409. let color = role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [255,255,255];
  410. htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-allowedrole" style="border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.encodeToHTML(role.name)}</div></div>`;
  411. }
  412. for (let role of overwrittenRoles) {
  413. let color = role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [255,255,255];
  414. htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-overwrittenrole" style="border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}" style="text-decoration: line-through !important;">${BDFDB.encodeToHTML(role.name)}</div></div>`;
  415. }
  416. htmlString += `</div>`;
  417. }
  418. if (allowedUsers.length > 0) {
  419. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Allowed Users:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}">`;
  420. for (let user of allowedUsers) {
  421. let color = user.colorString ? BDFDB.colorCONVERT(user.colorString, "RGBCOMP") : [255,255,255];
  422. htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-alloweduser" style="padding-left: 0; border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCNS.avatarimage + BDFDB.disCN.avatarxsmall}" style="margin-right: 4px; z-index: 1003; background-image: url(${BDFDB.getUserAvatar(user.id)});"></div><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.encodeToHTML(user.nick || user.name)}</div></div>`;
  423. }
  424. htmlString += `</div>`;
  425. }
  426. if (deniedRoles.length > 0) {
  427. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Denied Roles:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}">`;
  428. for (let role of deniedRoles) {
  429. let color = role.colorString ? BDFDB.colorCONVERT(role.colorString, "RGBCOMP") : [255,255,255];
  430. htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-deniedrole" style="border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.encodeToHTML(role.name)}</div></div>`;
  431. }
  432. htmlString += `</div>`;
  433. }
  434. if (deniedUsers.length > 0) {
  435. htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Denied Users:</div><div class="${BDFDB.disCNS.flex + BDFDB.disCN.wrap}">`;
  436. for (let user of deniedUsers) {
  437. let color = user.colorString ? BDFDB.colorCONVERT(user.colorString, "RGBCOMP") : [255,255,255];
  438. htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex + BDFDB.disCNS.aligncenter + BDFDB.disCN.wrap + BDFDB.disCNS.size12 + BDFDB.disCN.weightmedium} SHC-denieduser" style="padding-left: 0; border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCNS.avatarimage + BDFDB.disCN.avatarxsmall}" style="margin-right: 4px; z-index: 1003; background-image: url(${BDFDB.getUserAvatar(user.id)});"></div><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.encodeToHTML(user.nick || user.name)}</div></div>`;
  439. }
  440. htmlString += `</div>`;
  441. }
  442. if (htmlString) {
  443. var width = window.outerWidth/2;
  444. 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")});
  445. var style = getComputedStyle(e.currentTarget);
  446. tooltip.style.setProperty("top", BDFDB.getRects(tooltip).top - style.paddingBottom.replace("px","")/2 + style.paddingTop.replace("px","")/2 + "px");
  447. }
  448. }
  449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement