Update RemoveNicknames.plugin.js
This commit is contained in:
parent
68f1a283bf
commit
6e6ced3c3c
|
@ -3,7 +3,7 @@
|
|||
class RemoveNicknames {
|
||||
getName () {return "RemoveNicknames";}
|
||||
|
||||
getVersion () {return "1.2.6";}
|
||||
getVersion () {return "1.2.7";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
|
@ -11,7 +11,7 @@ class RemoveNicknames {
|
|||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
|
||||
"added":[["Ignore Elements","Added an option list that let's you costumize in which places nicknames are being removed"]]
|
||||
};
|
||||
|
||||
this.patchModules = {
|
||||
|
@ -26,10 +26,16 @@ class RemoveNicknames {
|
|||
initConstructor () {
|
||||
this.defaults = {
|
||||
settings: {
|
||||
replaceOwn: {value:false, description:"Replace your own name:"},
|
||||
replaceBots: {value:true, description:"Replace the nickname of bots:"},
|
||||
addNickname: {value:false, description:"Add nickname as parentheses:"},
|
||||
swapPositions: {value:false, description:"Swap the position of username and nickname:"}
|
||||
replaceOwn: {value:false, inner:false, description:"Replace your own name:"},
|
||||
replaceBots: {value:true, inner:false, description:"Replace the nickname of bots:"},
|
||||
addNickname: {value:false, inner:false, description:"Add nickname as parentheses:"},
|
||||
swapPositions: {value:false, inner:false, description:"Swap the position of username and nickname:"},
|
||||
changeInChatWindow: {value:true, inner:true, description:"Messages"},
|
||||
changeInMentions: {value:true, inner:true, description:"Mentions"},
|
||||
changeInVoiceChat: {value:true, inner:true, description:"Voice Channels"},
|
||||
changeInMemberList: {value:true, inner:true, description:"Member List"},
|
||||
changeInTyping: {value:true, inner:true, description:"Typing List"},
|
||||
changeInAutoComplete: {value:true, inner:true, description:"Autocomplete Menu"}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -39,8 +45,13 @@ class RemoveNicknames {
|
|||
var settings = BDFDB.getAllData(this, "settings");
|
||||
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
|
||||
for (let key in settings) {
|
||||
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + 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.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>`;
|
||||
if (!this.defaults.settings[key].inner) settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + 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.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>`;
|
||||
}
|
||||
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + 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.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 0 0 auto;">Remove Nicknames in:</h3></div><div class="BDFDB-settings-inner-list">`;
|
||||
for (let key in settings) {
|
||||
if (this.defaults.settings[key].inner) settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + 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.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>`;
|
||||
}
|
||||
settingshtml += `</div>`;
|
||||
settingshtml += `</div></div>`;
|
||||
|
||||
let settingspanel = BDFDB.htmlToElement(settingshtml);
|
||||
|
@ -116,7 +127,7 @@ class RemoveNicknames {
|
|||
let user = BDFDB.getReactValue(instance, "props.user");
|
||||
if (user) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.memberusername);
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(user));
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(user, wrapper));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +135,7 @@ class RemoveNicknames {
|
|||
let message = BDFDB.getReactValue(instance, "props.message");
|
||||
if (message) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(message.author));
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(message.author, wrapper));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,18 +152,17 @@ class RemoveNicknames {
|
|||
if (BDFDB.containsClass(wrapper.parentElement, BDFDB.disCN.messagesystemcontent) && wrapper.parentElement.querySelector("a") == wrapper) {
|
||||
let message = BDFDB.getKeyInformation({node:wrapper.parentElement, key:"message", up:true});
|
||||
if (message) {
|
||||
BDFDB.setInnerText(wrapper, this.getNewName(message.author));
|
||||
BDFDB.setInnerText(wrapper, this.getNewName(message.author, wrapper));
|
||||
if (message.mentions.length == 1) {
|
||||
let seconduser = BDFDB.LibraryModules.UserStore.getUser(message.mentions[0]);
|
||||
let secondwrapper = wrapper.parentElement.querySelectorAll("a")[1];
|
||||
if (seconduser && secondwrapper) BDFDB.setInnerText(secondwrapper, this.getNewName(seconduser));
|
||||
if (seconduser && secondwrapper) BDFDB.setInnerText(secondwrapper, this.getNewName(seconduser, wrapper));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (instance.props.tag == "span" && instance.props.className.indexOf(BDFDB.disCN.mention) > -1) {
|
||||
let render = BDFDB.getReactValue(instance, "_reactInternalFiber.return.return.stateNode.props.render");
|
||||
if (typeof render == "function") BDFDB.setInnerText(wrapper, "@" + this.getNewName(render().props.user));
|
||||
if (typeof render == "function") {
|
||||
var props = render().props;
|
||||
if (props && props.user) BDFDB.setInnerText(wrapper, "@" + this.getNewName(props.user, wrapper));
|
||||
|
@ -163,14 +173,14 @@ class RemoveNicknames {
|
|||
let user = BDFDB.getReactValue(instance, "_reactInternalFiber.return.memoizedProps.user");
|
||||
if (user) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.voicename);
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(user));
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(user, username));
|
||||
}
|
||||
}
|
||||
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.autocompleterow) > -1) {
|
||||
let user = BDFDB.getReactValue(instance, "_reactInternalFiber.return.memoizedProps.user");
|
||||
if (user) {
|
||||
let username = wrapper.querySelector(BDFDB.dotCN.marginleft8);
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(user));
|
||||
if (username) BDFDB.setInnerText(username, this.getNewName(user, username));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,13 +192,33 @@ class RemoveNicknames {
|
|||
}
|
||||
}
|
||||
|
||||
getNewName (info) {
|
||||
getNewName (info, wrapper) {
|
||||
if (!info) return null;
|
||||
let settings = BDFDB.getAllData(this, "settings");
|
||||
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id) || {};
|
||||
let EditUsersData = (BDFDB.isPluginEnabled("EditUsers") ? BDFDB.loadData(info.id, "EditUsers", "users") : null) || {};
|
||||
if (this.reseting || !member.nick || info.id == BDFDB.myData.id && !settings.replaceOwn || info.bot && !settings.replaceBots) return EditUsersData.name || member.nick || info.username;
|
||||
if (this.reseting || !member.nick || info.id == BDFDB.myData.id && !settings.replaceOwn || info.bot && !settings.replaceBots || this.ignoreElement(wrapper)) return EditUsersData.name || member.nick || info.username;
|
||||
var username = EditUsersData.name || info.username;
|
||||
return settings.addNickname ? (settings.swapPositions ? (member.nick + " (" + username + ")") : (username + " (" + member.nick + ")")) : username;
|
||||
}
|
||||
|
||||
ignoreElement (id, wrapper) {
|
||||
let allenabled = true, settings = BDFDB.filterObject(BDFDB.getAllData(this, "settings"), key => {return this.defaults.settings[key].inner;}, true);
|
||||
for (let i in settings) if (!settings[i]) {
|
||||
allenabled = false;
|
||||
break;
|
||||
}
|
||||
if (allenabled) return false;
|
||||
|
||||
let key = null;
|
||||
if (!BDFDB.containsClass(wrapper, BDFDB.disCN.mention) && BDFDB.getParentEle(BDFDB.dotCN.messagegroup, wrapper)) key = "changeInChatWindow";
|
||||
else if (BDFDB.containsClass(wrapper, BDFDB.disCN.mention)) key = "changeInMentions";
|
||||
else if (BDFDB.getParentEle(BDFDB.dotCN.voiceuser, wrapper)) key = "changeInVoiceChat";
|
||||
else if (BDFDB.getParentEle(BDFDB.dotCN.members, wrapper)) key = "changeInMemberList";
|
||||
else if (BDFDB.getParentEle(BDFDB.dotCN.typing, wrapper)) key = "changeInTyping";
|
||||
else if (BDFDB.getParentEle(BDFDB.dotCN.autocomplete, wrapper)) key = "changeInAutoComplete";
|
||||
|
||||
if (!key || settings[key]) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue