Update ShowHiddenChannels.plugin.js
This commit is contained in:
parent
0162071c72
commit
a621a726b0
|
@ -3,7 +3,7 @@
|
||||||
class ShowHiddenChannels {
|
class ShowHiddenChannels {
|
||||||
getName () {return "ShowHiddenChannels";}
|
getName () {return "ShowHiddenChannels";}
|
||||||
|
|
||||||
getVersion () {return "2.6.0";}
|
getVersion () {return "2.6.1";}
|
||||||
|
|
||||||
getAuthor () {return "DevilBro";}
|
getAuthor () {return "DevilBro";}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class ShowHiddenChannels {
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.changelog = {
|
this.changelog = {
|
||||||
"fixed":[["User Duplicates","Removed the user duplicates, which I used for testing, BIG OOF"]],
|
"fixed":[["Channel Duplicates","Should be impossible now for channels to get duplicated"],["User Duplicates","Removed the user duplicates, which I used for testing, BIG OOF"]],
|
||||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"],["Sort", "You can now sort hidden channels in the native way, meaning they will be placed below their rightful category"],["Tooltip", "The tooltip was removed and was turned into a more friendly modal, which can be access via the right click menu on a channel"]]
|
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"],["Sort", "You can now sort hidden channels in the native way, meaning they will be placed below their rightful category"],["Tooltip", "The tooltip was removed and was turned into a more friendly modal, which can be access via the right click menu on a channel"]]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -169,7 +169,6 @@ class ShowHiddenChannels {
|
||||||
|
|
||||||
processChannels (e) {
|
processChannels (e) {
|
||||||
if (!e.instance.props.guild) return;
|
if (!e.instance.props.guild) return;
|
||||||
if (this.changedInstances[e.instance.props.guild.id]) this.resetInstance(e.instance.props.guild.id, false);
|
|
||||||
let [hiddenChannels, amount] = this.getHiddenChannels(e.instance.props.guild);
|
let [hiddenChannels, amount] = this.getHiddenChannels(e.instance.props.guild);
|
||||||
if (amount) {
|
if (amount) {
|
||||||
let settings = BDFDB.DataUtils.get(this, "settings"), index = -1;
|
let settings = BDFDB.DataUtils.get(this, "settings"), index = -1;
|
||||||
|
@ -182,34 +181,42 @@ class ShowHiddenChannels {
|
||||||
name: "hidden",
|
name: "hidden",
|
||||||
type: categoryType
|
type: categoryType
|
||||||
});
|
});
|
||||||
e.instance.props.categories._categories.push({
|
if (!BDFDB.ArrayUtils.is(e.instance.props.categories[hiddenCategory.id])) e.instance.props.categories[hiddenCategory.id] = [];
|
||||||
channel: hiddenCategory,
|
if (!e.instance.props.categories._categories.some(categoryObj => categoryObj.channel && categoryObj.channel.id == hiddenCategory.id)) {
|
||||||
index: ++index
|
e.instance.props.categories._categories.push({
|
||||||
});
|
channel: hiddenCategory,
|
||||||
e.instance.props.channels[categoryType].push({
|
index: ++index
|
||||||
comparator: ++(e.instance.props.channels[categoryType][e.instance.props.channels[categoryType].length - 1] || {comparator: 0}).comparator,
|
});
|
||||||
channel: hiddenCategory
|
}
|
||||||
});
|
if (!e.instance.props.channels[categoryType].some(categoryObj => categoryObj.channel && categoryObj.channel.id == hiddenCategory.id)) {
|
||||||
e.instance.props.categories[hiddenCategory.id] = [];
|
e.instance.props.channels[categoryType].push({
|
||||||
|
comparator: ++(e.instance.props.channels[categoryType][e.instance.props.channels[categoryType].length - 1] || {comparator: 0}).comparator,
|
||||||
|
channel: hiddenCategory
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let type in hiddenChannels) if (!settings.sortNative || type != categoryType) {
|
for (let type in hiddenChannels) {
|
||||||
let channeltype = type == 0 && e.instance.props.channels.SELECTABLE ? "SELECTABLE" : type;
|
let channeltype = type == 0 && e.instance.props.channels.SELECTABLE ? "SELECTABLE" : type;
|
||||||
let channels = e.instance.props.channels[channeltype];
|
if (!BDFDB.ArrayUtils.is(e.instance.props.channels[channeltype])) e.instance.props.channels[channeltype] = [];
|
||||||
let comparator = (channels && channels[channels.length - 1] || {comparator: 0}).comparator;
|
let comparator = (e.instance.props.channels[channeltype][e.instance.props.channels[channeltype].length - 1] || {comparator: 0}).comparator;
|
||||||
for (let channel of hiddenChannels[type]) {
|
for (let channel of hiddenChannels[type]) {
|
||||||
let hiddenChannel = new BDFDB.DiscordObjects.Channel(Object.assign({}, channel, {
|
let hiddenChannel = new BDFDB.DiscordObjects.Channel(Object.assign({}, channel, {
|
||||||
parent_id: settings.sortNative ? channel.parent_id : e.instance.props.guild.id + "_hidden"
|
parent_id: settings.sortNative ? channel.parent_id : e.instance.props.guild.id + "_hidden"
|
||||||
}));
|
}));
|
||||||
let parent_id = hiddenChannel.parent_id || "null";
|
let parent_id = hiddenChannel.parent_id || "null";
|
||||||
e.instance.props.categories[parent_id].push({
|
if (!e.instance.props.categories[parent_id].some(channelObj => channelObj.channel && channelObj.channel.id == hiddenChannel.id)) {
|
||||||
channel: hiddenChannel,
|
e.instance.props.categories[parent_id].push({
|
||||||
index: ++(e.instance.props.categories[parent_id][e.instance.props.categories[parent_id].length - 1] || {index: 0}).index
|
channel: hiddenChannel,
|
||||||
});
|
index: ++(e.instance.props.categories[parent_id][e.instance.props.categories[parent_id].length - 1] || {index: 0}).index
|
||||||
e.instance.props.channels[channeltype].push({
|
});
|
||||||
comparator: ++comparator,
|
}
|
||||||
channel: hiddenChannel
|
if (!e.instance.props.channels[channeltype].some(channelObj => channelObj.channel && channelObj.channel.id == hiddenChannel.id)) {
|
||||||
});
|
e.instance.props.channels[channeltype].push({
|
||||||
|
comparator: ++comparator,
|
||||||
|
channel: hiddenChannel
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,28 +284,13 @@ class ShowHiddenChannels {
|
||||||
getHiddenChannels (guild) {
|
getHiddenChannels (guild) {
|
||||||
if (!guild) return [{}, 0];
|
if (!guild) return [{}, 0];
|
||||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||||
let all = BDFDB.LibraryModules.ChannelStore.getChannels(), shown = BDFDB.LibraryModules.GuildChannelStore.getChannels(guild.id), hidden = {}, amount = 0;
|
let all = BDFDB.LibraryModules.ChannelStore.getChannels(), hidden = {}, amount = 0;
|
||||||
for (let type in BDFDB.DiscordConstants.ChannelTypes) hidden[BDFDB.DiscordConstants.ChannelTypes[type]] = [];
|
for (let type in BDFDB.DiscordConstants.ChannelTypes) hidden[BDFDB.DiscordConstants.ChannelTypes[type]] = [];
|
||||||
for (let channel_id in all) {
|
for (let channel_id in all) {
|
||||||
let channel = all[channel_id];
|
let channel = all[channel_id];
|
||||||
if (channel.guild_id == guild.id && (settings[this.settingsMap[this.channelTypes[channel.type]]] || settings[this.settingsMap[this.channelTypes[channel.type]]] === undefined)) {
|
if (channel.guild_id == guild.id && (settings[this.settingsMap[this.channelTypes[channel.type]]] || settings[this.settingsMap[this.channelTypes[channel.type]]] === undefined) && this.isChannelHidden(channel.id)) {
|
||||||
let isHidden = true;
|
amount++;
|
||||||
if (channel.type == BDFDB.DiscordConstants.ChannelTypes.GUILD_CATEGORY) {
|
hidden[channel.type].push(channel);
|
||||||
for (let type in BDFDB.DiscordConstants.ChannelTypes) {
|
|
||||||
let channelObjs = BDFDB.DiscordConstants.ChannelTypes[type] == 0 && shown.SELECTABLE || shown[BDFDB.DiscordConstants.ChannelTypes[type]];
|
|
||||||
if (channelObjs) for (let channelObj of channelObjs) {
|
|
||||||
if (!channel.id || channelObj.channel.parent_id == channel.id) {
|
|
||||||
isHidden = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.isChannelHidden(channel.id)) isHidden = false;
|
|
||||||
if (isHidden) {
|
|
||||||
amount++;
|
|
||||||
hidden[channel.type].push(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [hidden, amount];
|
return [hidden, amount];
|
||||||
|
@ -440,59 +432,6 @@ class ShowHiddenChannels {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showAccessRoles (guild, channel, e, allowed) {
|
|
||||||
if ((e.type != "mouseenter" && e.type != "mouseover") || !guild || !channel) return;
|
|
||||||
var htmlString = ``;
|
|
||||||
if (settings.showChannelCategory && !allowed && channel.parent_id) {
|
|
||||||
htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Category:</div><div class="${BDFDB.disCNS.flex2 + BDFDB.disCN.wrap}"><div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} 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.StringUtils.htmlEscape(BDFDB.LibraryModules.ChannelStore.getChannel(channel.parent_id).name)}</div></div>`;
|
|
||||||
}
|
|
||||||
if (settings.showTopic && !allowed && channel.topic && channel.topic.replace(/[\t\n\r\s]/g, "")) {
|
|
||||||
htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Topic:</div><div class="${BDFDB.disCNS.flex2 + BDFDB.disCN.wrap}"><div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} 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.StringUtils.htmlEscape(channel.topic)}</div></div>`;
|
|
||||||
}
|
|
||||||
if (allowedRoles.length > 0 || overwrittenRoles.length > 0) {
|
|
||||||
htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Allowed Roles:</div><div class="${BDFDB.disCNS.flex2 + BDFDB.disCN.wrap}">`;
|
|
||||||
for (let role of allowedRoles) {
|
|
||||||
let color = role.colorString ? BDFDB.ColorUtils.convert(role.colorString, "RGBCOMP") : [255,255,255];
|
|
||||||
htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} 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.StringUtils.htmlEscape(role.name)}</div></div>`;
|
|
||||||
}
|
|
||||||
for (let role of overwrittenRoles) {
|
|
||||||
let color = role.colorString ? BDFDB.ColorUtils.convert(role.colorString, "RGBCOMP") : [255,255,255];
|
|
||||||
htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} 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.StringUtils.htmlEscape(role.name)}</div></div>`;
|
|
||||||
}
|
|
||||||
htmlString += `</div>`;
|
|
||||||
}
|
|
||||||
if (allowedUsers.length > 0) {
|
|
||||||
htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Allowed Users:</div><div class="${BDFDB.disCNS.flex2 + BDFDB.disCN.wrap}">`;
|
|
||||||
for (let user of allowedUsers) {
|
|
||||||
let color = user.colorString ? BDFDB.ColorUtils.convert(user.colorString, "RGBCOMP") : [255,255,255];
|
|
||||||
htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} SHC-alloweduser" style="padding-left: 0; border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCN.avatarwrapper}" role="img" aria-label="${user.username}" aria-hidden="false" style="width: 22px; height: 18px; z-index: 1003;"><svg width="18" height="18" viewBox="0 0 18 18" class="${BDFDB.disCN.avatarmask}" aria-hidden="true"><foreignObject x="0" y="0" width="18" height="18" mask="url(#svg-mask-avatar-default)"><img src="${BDFDB.UserUtils.getAvatar(user.id)}" alt=" " class="${BDFDB.disCN.avatar}" aria-hidden="true"></foreignObject></svg></div><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.StringUtils.htmlEscape(user.nick || user.name)}</div></div>`;
|
|
||||||
}
|
|
||||||
htmlString += `</div>`;
|
|
||||||
}
|
|
||||||
if (deniedRoles.length > 0) {
|
|
||||||
htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Denied Roles:</div><div class="${BDFDB.disCNS.flex2 + BDFDB.disCN.wrap}">`;
|
|
||||||
for (let role of deniedRoles) {
|
|
||||||
let color = role.colorString ? BDFDB.ColorUtils.convert(role.colorString, "RGBCOMP") : [255,255,255];
|
|
||||||
htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} 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.StringUtils.htmlEscape(role.name)}</div></div>`;
|
|
||||||
}
|
|
||||||
htmlString += `</div>`;
|
|
||||||
}
|
|
||||||
if (deniedUsers.length > 0) {
|
|
||||||
htmlString += `<div class="${BDFDB.disCN.marginbottom4}">Denied Users:</div><div class="${BDFDB.disCNS.flex2 + BDFDB.disCN.wrap}">`;
|
|
||||||
for (let user of deniedUsers) {
|
|
||||||
let color = user.colorString ? BDFDB.ColorUtils.convert(user.colorString, "RGBCOMP") : [255,255,255];
|
|
||||||
htmlString += `<div class="${BDFDB.disCNS.userpopoutrole + BDFDB.disCNS.flex2 + BDFDB.disCNS.aligncenter} SHC-denieduser" style="padding-left: 0; border-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.6);"><div class="${BDFDB.disCN.avatarwrapper}" role="img" aria-label="${user.username}" aria-hidden="false" style="width: 22px; height: 18px; z-index: 1003;"><svg width="18" height="18" viewBox="0 0 18 18" class="${BDFDB.disCN.avatarmask}" aria-hidden="true"><foreignObject x="0" y="0" width="18" height="18" mask="url(#svg-mask-avatar-default)"><img src="${BDFDB.UserUtils.getAvatar(user.id)}" alt=" " class="${BDFDB.disCN.avatar}" aria-hidden="true"></foreignObject></svg></div><div class="${BDFDB.disCN.userpopoutrolecircle}" style="background-color: rgb(${color[0]}, ${color[1]}, ${color[2]});"></div><div class="${BDFDB.disCNS.userpopoutrolename}">${BDFDB.StringUtils.htmlEscape(user.nick || user.name)}</div></div>`;
|
|
||||||
}
|
|
||||||
htmlString += `</div>`;
|
|
||||||
}
|
|
||||||
if (htmlString) {
|
|
||||||
var width = window.outerWidth/2;
|
|
||||||
var tooltip = BDFDB.TooltipUtils.create(e.currentTarget, htmlString, {type:"right", selector:"showhiddenchannels-tooltip", html:true, style:`max-width: ${width < 200 ? 400 : width}px !important;`, delay:BDFDB.DataUtils.get(this, "amounts", "hoverDelay")});
|
|
||||||
var style = getComputedStyle(e.currentTarget);
|
|
||||||
tooltip.style.setProperty("top", BDFDB.DOMUtils.getRects(tooltip).top - style.paddingBottom.replace("px","")/2 + style.paddingTop.replace("px","")/2 + "px");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setLabelsByLanguage () {
|
setLabelsByLanguage () {
|
||||||
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
||||||
case "hr": //croatian
|
case "hr": //croatian
|
||||||
|
|
Loading…
Reference in New Issue