//META{"name":"OwnerTag"}*//
class OwnerTag {
getName () {return "OwnerTag";}
getVersion () {return "1.0.7";}
getAuthor () {return "DevilBro";}
getDescription () {return "Adds a Tag like Bottags to the Serverowner.";}
initConstructor () {
this.patchModules = {
"NameTag":["componentDidMount","componentDidUpdate"],
"MessageUsername":["componentDidMount","componentDidUpdate"],
"StandardSidebarView":"componentWillUnmount"
};
this.defaults = {
settings: {
addInChatWindow: {value:true, inner:true, description:"Messages"},
addInMemberList: {value:true, inner:true, description:"Member List"},
addInUserPopout: {value:true, inner:true, description:"User Popouts"},
addInUserProfil: {value:true, inner:true, description:"User Profile Modal"},
useRoleColor: {value:true, inner:false, description:"Use the Rolecolor instead of the default blue."},
useBlackFont: {value:false, inner:false, description:"Instead of darkening the Rolecolor on bright colors use black font."}
},
inputs: {
ownTagName: {value:"Owner", description:"Owner Tag Text"}
}
};
}
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
var settings = BDFDB.getAllData(this, "settings");
var inputs = BDFDB.getAllData(this, "inputs");
var settingshtml = `
${this.name}
`;
for (let key in inputs) {
settingshtml += `
`;
}
for (let key in settings) {
if (!this.defaults.settings[key].inner) settingshtml += `
`;
}
settingshtml += `
Add Owner Tag in:
`;
for (let key in settings) {
if (this.defaults.settings[key].inner) settingshtml += `
`;
}
settingshtml += `
`;
settingshtml += `
`;
let settingspanel = BDFDB.htmlToElement(settingshtml);
BDFDB.initElements(settingspanel, this);
BDFDB.addEventListener(this, settingspanel, "keyup", BDFDB.dotCN.input, () => {this.saveInputs(settingspanel);});
return settingspanel;
}
//legacy
load () {}
start () {
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", () => {
BDFDB.loaded = true;
this.initialize();
});
document.head.appendChild(libraryScript);
}
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
}
initialize () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.loadMessage(this);
this.MemberUtils = BDFDB.WebModules.findByProperties("getMembers", "getMember");
this.GuildUtils = BDFDB.WebModules.findByProperties("getGuilds","getGuild");
this.LastGuildStore = BDFDB.WebModules.findByProperties("getLastSelectedGuildId");
BDFDB.WebModules.forceAllUpdates(this);
}
else {
console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
}
}
stop () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
BDFDB.removeEles(".owner-tag");
BDFDB.unloadMessage(this);
}
}
// begin of own functions
saveInputs (settingspanel) {
let inputs = {};
for (let input of settingspanel.querySelectorAll(BDFDB.dotCN.input)) {
inputs[input.getAttribute("option")] = input.value;
}
BDFDB.saveAllData(inputs, this, "inputs");
this.SettingsUpdated = true;
}
processNameTag (instance, wrapper) {
let container = null;
if (!instance.props || !wrapper.classList) return;
else if (BDFDB.containsClass(wrapper, BDFDB.disCN.membernametag) && BDFDB.getData("addInMemberList", this, "settings")) {
this.addOwnerTag(instance.props.user, wrapper, "list", BDFDB.disCN.bottagnametag + (instance.props.botClass ? (" " + instance.props.botClass) : ""), container);
}
else if ((container = BDFDB.getParentEle(BDFDB.dotCN.userpopout, wrapper)) != null && BDFDB.getData("addInUserPopout", this, "settings")) {
this.addOwnerTag(instance.props.user, wrapper, "popout", BDFDB.disCN.bottagnametag + (instance.props.botClass ? (" " + instance.props.botClass) : ""), container);
}
else if ((container = BDFDB.getParentEle(BDFDB.dotCN.userprofile, wrapper)) != null && BDFDB.getData("addInUserProfil", this, "settings")) {
this.addOwnerTag(instance.props.user, wrapper, "profile", BDFDB.disCN.bottagnametag + (instance.props.botClass ? (" " + instance.props.botClass) : ""), container);
}
}
processMessageUsername (instance, wrapper, methodnames) {
let message = BDFDB.getReactValue(instance, "props.message");
if (message && BDFDB.getData("addInChatWindow", this, "settings")) {
let username = wrapper.querySelector(BDFDB.dotCN.messageusername);
if (username) {
let messagegroup = BDFDB.getParentEle(BDFDB.dotCN.messagegroup, wrapper);
this.addOwnerTag(message.author, username.parentElement, "chat", BDFDB.disCN.bottagmessage + " " + (BDFDB.containsClass(messagegroup, BDFDB.disCN.messagegroupcozy) ? BDFDB.disCN.bottagmessagecozy : BDFDB.disCN.bottagmessagecompact), null);
}
}
}
processStandardSidebarView (instance, wrapper) {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
BDFDB.removeEles(".owner-tag");
BDFDB.WebModules.forceAllUpdates(this);
}
}
addOwnerTag (info, wrapper, type, selector = "", container) {
if (!info || !wrapper || !wrapper.parentElement) return;
BDFDB.removeEles(wrapper.querySelectorAll(".owner-tag"));
let guild = this.GuildUtils.getGuild(this.LastGuildStore.getGuildId());
if (!guild || guild.ownerId != info.id) return;
let settings = BDFDB.getAllData(this, "settings");
let member = settings.useRoleColor ? (this.MemberUtils.getMember(this.LastGuildStore.getGuildId(), info.id) || {}) : {};
let EditUsersData = BDFDB.isPluginEnabled("EditUsers") ? bdplugins.EditUsers.plugin.getUserData(info.id, wrapper) : {};
let tag = BDFDB.htmlToElement(`${BDFDB.getData("ownTagName", this, "inputs") || "Owner"}`);
let invert = false;
if (container && container.firstElementChild && !BDFDB.containsClass(container.firstElementChild, BDFDB.disCN.userpopoutheadernormal, BDFDB.disCN.userprofiletopsectionnormal), false) invert = true;
BDFDB.addClass(tag, invert ? BDFDB.disCN.bottaginvert : BDFDB.disCN.bottagregular);
let tagcolor = BDFDB.colorCONVERT(EditUsersData.color1 || member.colorString, "RGB");
let isbright = BDFDB.colorISBRIGHT(tagcolor);
tagcolor = isbright ? (settings.useBlackFont ? tagcolor : BDFDB.colorCHANGE(tagcolor, -0.3)) : tagcolor;
tag.style.setProperty(invert ? "color" : "background-color", tagcolor, "important");
if (isbright && settings.useBlackFont) tag.style.setProperty(invert ? "background-color" : "color", "black", "important");
wrapper.insertBefore(tag, wrapper.querySelector(".TRE-tag,svg[name=MobileDevice]"));
}
}