2018-10-11 10:21:26 +02:00
|
|
|
module.exports = (Plugin, Api, Vendor) => {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (!global.BDFDB || typeof BDFDB != "object") global.BDFDB = {BDv2Api: Api};
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
return class extends Plugin {
|
|
|
|
initConstructor () {
|
2019-01-26 22:45:19 +01:00
|
|
|
this.patchModules = {
|
|
|
|
"NameTag":"componentDidMount",
|
|
|
|
"FluxContainer(TypingUsers)":"componentDidUpdate",
|
|
|
|
"MessageUsername":"componentDidMount",
|
|
|
|
"Clickable":"componentDidMount",
|
|
|
|
"StandardSidebarView":"componentWillUnmount"
|
|
|
|
};
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
this.defaults = {
|
|
|
|
settings: {
|
|
|
|
replaceOwn: {value:false, description:"Replace your own name:"},
|
2019-01-26 22:45:19 +01:00
|
|
|
addNickname: {value:false, description:"Add nickname as parentheses:"},
|
|
|
|
swapPositions: {value:false, description:"Swap the position of username and nickname:"}
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onStart () {
|
2019-01-26 22:45:19 +01:00
|
|
|
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
|
|
|
|
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
2019-01-26 22:45:19 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.addEventListener("load", () => {
|
|
|
|
BDFDB.loaded = true;
|
|
|
|
this.initialize();
|
|
|
|
});
|
2018-10-11 10:21:26 +02:00
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2018-10-11 10:21:26 +02:00
|
|
|
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
|
|
|
if (this.started) return true;
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.loadMessage(this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
this.reseting = false;
|
|
|
|
|
2018-12-20 22:54:42 +01:00
|
|
|
this.UserStore = BDFDB.WebModules.findByProperties("getUsers", "getUser");
|
2019-01-26 22:45:19 +01:00
|
|
|
this.LastGuildStore = BDFDB.WebModules.findByProperties("getLastSelectedGuildId");
|
|
|
|
this.LastChannelStore = BDFDB.WebModules.findByProperties("getLastSelectedChannelId");
|
|
|
|
this.MemberStore = BDFDB.WebModules.findByProperties("getNicknames", "getNick");
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2019-01-24 13:37:08 +01:00
|
|
|
console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
|
2018-10-11 10:21:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onStop () {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
|
|
|
this.reseting = true;
|
|
|
|
|
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.unloadMessage(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
// begin of own functions
|
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
getNewName (info) {
|
|
|
|
if (!info) return null;
|
|
|
|
let EditUsersData = BDFDB.isPluginEnabled("EditUsers") ? BDFDB.loadData(info.id, "EditUsers", "users") : null;
|
|
|
|
if (EditUsersData && EditUsersData.name) return EditUsersData.name;
|
|
|
|
let settings = BDFDB.getAllData(this, "settings");
|
|
|
|
let member = this.MemberStore.getMember(this.LastGuildStore.getGuildId(), info.id);
|
|
|
|
if (!member || !member.nick || info.id == BDFDB.myData.id && !settings.replaceOwn) return info.username;
|
|
|
|
if (this.reseting) return member.nick || info.username;
|
|
|
|
return settings.addNickname ? (settings.swapPositions ? (member.nick + " (" + info.username + ")") : (info.username + " (" + member.nick + ")")) : info.username;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
processNameTag (instance, wrapper) {
|
|
|
|
let username = wrapper.parentElement.querySelector("." + (BDFDB.containsClass(wrapper, BDFDB.disCN.userpopoutheadertagwithnickname) ? BDFDB.disCN.userpopoutheadernickname : instance.props.usernameClass).replace(/ /g, "."));
|
|
|
|
if (username) BDFDB.setInnerText(username, this.getNewName(instance.props.user));
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
processMessageUsername (instance, wrapper) {
|
|
|
|
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));
|
|
|
|
}
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
processFluxContainerTypingUsers (instance, wrapper) {
|
|
|
|
let users = !instance.state.typingUsers ? [] : Object.keys(instance.state.typingUsers).filter(id => id != BDFDB.myData.id).filter(id => !this.RelationshipUtils.isBlocked(id)).map(id => this.UserUtils.getUser(id)).filter(id => id != null);
|
|
|
|
wrapper.querySelectorAll("strong").forEach((username, i) => {
|
|
|
|
if (users[i] && username) BDFDB.setInnerText(username, this.getNewName(users[i]));
|
2018-10-11 10:21:26 +02:00
|
|
|
});
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
processClickable (instance, wrapper) {
|
|
|
|
if (!wrapper || !instance.props || !instance.props.className) return;
|
|
|
|
if (instance.props.tag == "a" && instance.props.className.indexOf(BDFDB.disCN.anchorunderlineonhover) > -1) {
|
|
|
|
if (BDFDB.containsClass(wrapper.parentElement, BDFDB.disCN.messagesystemcontent)) {
|
|
|
|
let message = BDFDB.getKeyInformation({node:wrapper.parentElement, key:"message", up:true});
|
|
|
|
if (message) BDFDB.setInnerText(wrapper, this.getNewName(message.author));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.voiceuser) > -1) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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));
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
getSettingsPanel () {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
2018-10-11 10:21:26 +02:00
|
|
|
var settings = BDFDB.getAllData(this, "settings");
|
2019-01-26 22:45:19 +01:00
|
|
|
var settingshtml = `<div class="${this.name}-settings DevilBro-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="DevilBro-settings-inner">`;
|
2018-10-11 10:21:26 +02:00
|
|
|
for (let key in settings) {
|
2019-01-26 22:45:19 +01:00
|
|
|
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>`;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
settingshtml += `</div></div>`;
|
|
|
|
|
|
|
|
let settingspanel = BDFDB.htmlToElement(settingshtml);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
BDFDB.initElements(settingspanel, this);
|
|
|
|
;
|
2018-10-11 10:21:26 +02:00
|
|
|
return settingspanel;
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
onSettingsClosed () {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (this.SettingsUpdated) {
|
|
|
|
delete this.SettingsUpdated;
|
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|