Update EditServers.plugin.js

This commit is contained in:
Mirco Wittrien 2019-04-26 14:57:08 +02:00
parent 0069932279
commit ebecdb6d9a
1 changed files with 72 additions and 40 deletions

View File

@ -3,7 +3,7 @@
class EditServers { class EditServers {
getName () {return "EditServers";} getName () {return "EditServers";}
getVersion () {return "1.9.6";} getVersion () {return "1.9.7";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -11,12 +11,13 @@ class EditServers {
initConstructor () { initConstructor () {
this.changelog = { this.changelog = {
"added":[["Banners","You can now add/change/remove banners to/from servers"]] "fixed":[["New Classes","Fixed the plugin for the new class update"]]
}; };
this.labels = {}; this.labels = {};
this.patchModules = { this.patchModules = {
"Guild":"componentDidMount",
"GuildIcon":"componentDidMount", "GuildIcon":"componentDidMount",
"GuildHeader":["componentDidMount","componentDidUpdate"], "GuildHeader":["componentDidMount","componentDidUpdate"],
"Clickable":"componentDidMount" "Clickable":"componentDidMount"
@ -211,6 +212,7 @@ class EditServers {
BDFDB.loadMessage(this); BDFDB.loadMessage(this);
this.GuildUtils = BDFDB.WebModules.findByProperties("getGuilds","getGuild"); this.GuildUtils = BDFDB.WebModules.findByProperties("getGuilds","getGuild");
this.CurrentGuildStore = BDFDB.WebModules.findByProperties("getLastSelectedGuildId");
BDFDB.WebModules.patch(BDFDB.WebModules.findByProperties('getGuildBannerURL'), 'getGuildBannerURL', this, {instead:e => { BDFDB.WebModules.patch(BDFDB.WebModules.findByProperties('getGuildBannerURL'), 'getGuildBannerURL', this, {instead:e => {
let guild = this.GuildUtils.getGuild(e.methodArguments[0].id); let guild = this.GuildUtils.getGuild(e.methodArguments[0].id);
@ -224,6 +226,7 @@ class EditServers {
BDFDB.WebModules.forceAllUpdates(this); BDFDB.WebModules.forceAllUpdates(this);
this.updateGuildSidebar(); this.updateGuildSidebar();
this.onSwitch();
} }
else { else {
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
@ -249,6 +252,13 @@ class EditServers {
} }
} }
onSwitch () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
BDFDB.removeClass(document.querySelector(".fake-guildacronym" + BDFDB.dotCN.guildiconselected), BDFDB.disCN.guildiconselected);
let guilddiv = BDFDB.getServerDiv(this.CurrentGuildStore.getGuildId());
if (guilddiv) BDFDB.addClass(guilddiv.querySelector(".fake-guildacronym"), BDFDB.disCN.guildiconselected);
}
}
// begin of own functions // begin of own functions
@ -297,6 +307,7 @@ class EditServers {
BDFDB.removeData(instance.props.guild.id, this, "servers"); BDFDB.removeData(instance.props.guild.id, this, "servers");
BDFDB.WebModules.forceAllUpdates(this); BDFDB.WebModules.forceAllUpdates(this);
this.updateGuildSidebar(); this.updateGuildSidebar();
this.onSwitch();
}); });
} }
BDFDB.appendSubMenu(settingsitem, serverContextSubMenu); BDFDB.appendSubMenu(settingsitem, serverContextSubMenu);
@ -304,6 +315,48 @@ class EditServers {
} }
} }
processGuild (instance, wrapper) {
if (instance.currentType && (instance.currentType == "GUILD" || instance.currentType.ownerId) && instance.props && instance.props.guild) {
let icon = wrapper.querySelector(BDFDB.dotCN.guildicon + ":not(.fake-guildicon), " + BDFDB.dotCN.guildiconacronym + ":not(.fake-guildacronym)");
if (!icon) return;
this.changeGuildIcon(instance.props.guild, icon);
this.changeTooltip(instance.props.guild, wrapper.querySelector(BDFDB.dotCN.guildcontainer), "right");
}
}
processGuildIcon (instance, wrapper) {
if (instance.props && instance.props.guild) {
let icon = wrapper.classList && BDFDB.containsClass(wrapper, BDFDB.disCN.avataricon) ? wrapper : wrapper.querySelector(BDFDB.dotCN.avataricon);
if (!icon) return;
this.changeGuildIcon(instance.props.guild, icon);
if (BDFDB.getParentEle(BDFDB.dotCN.friendscolumn, icon)) this.changeTooltip(instance.props.guild, icon.parentElement, "top");
}
}
processGuildHeader (instance, wrapper) {
if (instance.props && instance.props.guild) {
this.changeGuildName(instance.props.guild, wrapper.querySelector(BDFDB.dotCN.guildheadername));
}
}
processClickable (instance, wrapper) {
if (!wrapper || !instance.props || !instance.props.className) return;
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.userprofilelistrow) > -1) {
let guild = BDFDB.getReactValue(instance, "_reactInternalFiber.return.memoizedProps.guild");
if (guild && BDFDB.getReactValue(instance, "_reactInternalFiber.return.type.displayName") == "GuildRow") {
this.changeGuildName(guild, wrapper.querySelector(BDFDB.dotCN.userprofilelistname));
}
}
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.quickswitchresult) > -1) {
let guild = BDFDB.getReactValue(instance, "_reactInternalFiber.return.return.memoizedProps.guild");
if (guild) this.changeGuildName(result.record, wrapper.querySelector(BDFDB.dotCN.quickswitchresultmatch));
else {
let channel = BDFDB.getReactValue(instance, "_reactInternalFiber.return.return.memoizedProps.channel");
if (channel && channel.guild_id) this.changeGuildName(this.GuildUtils.getGuild(channel.guild_id), wrapper.querySelector(BDFDB.dotCN.quickswitchresultmisccontainer));
}
}
}
showServerSettings (info) { showServerSettings (info) {
var {name,shortName,url,removeIcon,banner,removeBanner,color1,color2,color3,color4} = BDFDB.loadData(info.id, this, "servers") || {}; var {name,shortName,url,removeIcon,banner,removeBanner,color1,color2,color3,color4} = BDFDB.loadData(info.id, this, "servers") || {};
@ -390,6 +443,7 @@ class EditServers {
else BDFDB.saveData(info.id, {name,shortName,url,removeIcon,banner,removeBanner,color1,color2,color3,color4}, this, "servers"); else BDFDB.saveData(info.id, {name,shortName,url,removeIcon,banner,removeBanner,color1,color2,color3,color4}, this, "servers");
BDFDB.WebModules.forceAllUpdates(this); BDFDB.WebModules.forceAllUpdates(this);
this.updateGuildSidebar(); this.updateGuildSidebar();
this.onSwitch();
}); });
servernameinput.focus(); servernameinput.focus();
} }
@ -424,40 +478,6 @@ class EditServers {
} }
} }
processGuildIcon (instance, wrapper) {
if (instance.props && instance.props.guild) {
let icon = wrapper.classList && BDFDB.containsClass(wrapper, BDFDB.disCN.avataricon) ? wrapper : wrapper.querySelector(BDFDB.dotCN.avataricon);
if (!icon) return;
this.changeGuildIcon(instance.props.guild, icon);
if (BDFDB.getParentEle(BDFDB.dotCN.guild, icon)) this.changeTooltip(instance.props.guild, wrapper, "right");
else if (BDFDB.getParentEle(BDFDB.dotCN.friendscolumn, icon)) this.changeTooltip(instance.props.guild, icon.parentElement, "top");
}
}
processGuildHeader (instance, wrapper) {
if (instance.props && instance.props.guild) {
this.changeGuildName(instance.props.guild, wrapper.querySelector(BDFDB.dotCN.guildheadername));
}
}
processClickable (instance, wrapper) {
if (!wrapper || !instance.props || !instance.props.className) return;
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.userprofilelistrow) > -1) {
let guild = BDFDB.getReactValue(instance, "_reactInternalFiber.return.memoizedProps.guild");
if (guild && BDFDB.getReactValue(instance, "_reactInternalFiber.return.type.displayName") == "GuildRow") {
this.changeGuildName(guild, wrapper.querySelector(BDFDB.dotCN.userprofilelistname));
}
}
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.quickswitchresult) > -1) {
let guild = BDFDB.getReactValue(instance, "_reactInternalFiber.return.return.memoizedProps.guild");
if (guild) this.changeGuildName(result.record, wrapper.querySelector(BDFDB.dotCN.quickswitchresultmatch));
else {
let channel = BDFDB.getReactValue(instance, "_reactInternalFiber.return.return.memoizedProps.channel");
if (channel && channel.guild_id) this.changeGuildName(this.GuildUtils.getGuild(channel.guild_id), wrapper.querySelector(BDFDB.dotCN.quickswitchresultmisccontainer));
}
}
}
changeGuildName (info, guildname) { changeGuildName (info, guildname) {
if (!info || !guildname || !guildname.parentElement) return; if (!info || !guildname || !guildname.parentElement) return;
if (guildname.EditServersChangeObserver && typeof guildname.EditServersChangeObserver.disconnect == "function") guildname.EditServersChangeObserver.disconnect(); if (guildname.EditServersChangeObserver && typeof guildname.EditServersChangeObserver.disconnect == "function") guildname.EditServersChangeObserver.disconnect();
@ -490,10 +510,22 @@ class EditServers {
let data = this.getGuildData(info.id, icon); let data = this.getGuildData(info.id, icon);
if (data.url || data.shortName || data.removeIcon || icon.getAttribute("changed-by-editservers")) { if (data.url || data.shortName || data.removeIcon || icon.getAttribute("changed-by-editservers")) {
let url = data.url || BDFDB.getGuildIcon(info.id); let url = data.url || BDFDB.getGuildIcon(info.id);
if (icon.tagName == "IMG") icon.setAttribute("src", data.removeIcon ? null : url); let shortname = data.url ? "" : (data.shortName ? data.shortName : (info.icon && !data.removeIcon ? "" : info.acronym));
if (icon.tagName == "IMG") {
icon.setAttribute("src", data.removeIcon ? null : url);
let removeicon = data.removeIcon && BDFDB.containsClass(icon, BDFDB.disCN.guildicon);
BDFDB.toggleEles(icon, !removeicon);
BDFDB.removeEles(icon.parentElement.querySelector(".fake-guildacronym"));
if (removeicon) {
let fakeicon = BDFDB.htmlToElement(`<div class="${BDFDB.disCN.guildiconacronym} fake-guildacronym" aria-label="Server Acronym">${shortname}</div>`);
icon.parentElement.appendChild(fakeicon);
icon.parentElement.style.setProperty("font-size", this.getFontSize(fakeicon));
}
else icon.parentElement.style.removeProperty("font-size");
}
else { else {
BDFDB.setInnerText(icon, data.url ? "" : (data.shortName || (info.icon && !data.removeIcon ? "" : info.acronym))); BDFDB.setInnerText(icon, shortname);
if (!data.removeIcon && !data.shortName && url) icon.style.setProperty("background-image", `url(${url})`); if (!data.removeIcon && !shortname && url) icon.style.setProperty("background-image", `url(${url})`);
else icon.style.removeProperty("background-image"); else icon.style.removeProperty("background-image");
icon.style.setProperty("background-color", BDFDB.colorCONVERT(data.color1, "RGB"), "important"); icon.style.setProperty("background-color", BDFDB.colorCONVERT(data.color1, "RGB"), "important");
icon.style.setProperty("color", BDFDB.colorCONVERT(data.color2, "RGB", "important")); icon.style.setProperty("color", BDFDB.colorCONVERT(data.color2, "RGB", "important"));
@ -536,7 +568,7 @@ class EditServers {
getFontSize (icon) { getFontSize (icon) {
if (icon.style.getPropertyValue("background-image")) return null; if (icon.style.getPropertyValue("background-image")) return null;
else if (BDFDB.containsClass(icon, BDFDB.disCN.guildicon)) { else if (BDFDB.containsClass(icon, BDFDB.disCN.guildicon) || BDFDB.containsClass(icon, BDFDB.disCN.guildiconacronym)) {
var shortname = icon.innerText; var shortname = icon.innerText;
if (shortname) { if (shortname) {
if (shortname.length > 5) return "10px"; if (shortname.length > 5) return "10px";