//META{"name":"OwnerTag","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/OwnerTag","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/OwnerTag/OwnerTag.plugin.js"}*// class OwnerTag { getName () {return "OwnerTag";} getVersion () {return "1.1.6";} getAuthor () {return "DevilBro";} getDescription () {return "Adds a Tag like Bottags to the Serverowner.";} initConstructor () { this.changelog = { "fixed":[["DM Groups","Now works properly in DM Groups"]] }; this.patchModules = { "MemberListItem":["componentDidMount","componentDidUpdate"], "MessageUsername":["componentDidMount","componentDidUpdate"], "UserPopout":["componentDidMount","componentDidUpdate"], "UserProfile":["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."}, useCrown: {value:false, inner:false, description:"Use the Crown Icon instead of the OwnerTag."}, hideNativeCrown: {value:true, inner:false, description:"Hide the native Crown Icon (not the Plugin one)."}, addForAdmins: {value:false, inner:false, description:"Also add the Tag for any user with Admin rights."} }, inputs: { ownTagName: {value:"Owner", description:"Owner Tag Text for Owners"}, ownAdminTagName: {value:"Admin", description:"Owner Tag Text for Admins"} } }; } 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 += `

${this.defaults.inputs[key].description}

`; } for (let key in settings) { if (!this.defaults.settings[key].inner) settingshtml += `

${this.defaults.settings[key].description}

`; } settingshtml += `

Add Owner Tag in:

`; for (let key in settings) { if (this.defaults.settings[key].inner) settingshtml += `

${this.defaults.settings[key].description}

`; } 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 () { if (!global.BDFDB) global.BDFDB = {myPlugins:{}}; if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this; var libraryScript = document.querySelector('head script#BDFDBLibraryScript'); if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) { if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("id", "BDFDBLibraryScript"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); libraryScript.setAttribute("date", performance.now()); libraryScript.addEventListener("load", () => {this.initialize();}); document.head.appendChild(libraryScript); this.libLoadTimeout = setTimeout(() => { libraryScript.remove(); require("request")("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => { if (body) { libraryScript = document.createElement("script"); libraryScript.setAttribute("id", "BDFDBLibraryScript"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("date", performance.now()); libraryScript.innerText = body; document.head.appendChild(libraryScript); } this.initialize(); }); }, 15000); } 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.ChannelUtils = BDFDB.WebModules.findByProperties("getChannels","getChannel"); this.LastChannelStore = BDFDB.WebModules.findByProperties("getLastSelectedChannelId"); BDFDB.WebModules.forceAllUpdates(this); this.addHideCSS(); } else { console.error(`%c[${this.getName()}]%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, .owner-tag-crown"); BDFDB.removeLocalStyle(this.name + "HideCrown"); 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; } processMemberListItem (instance, wrapper) { if (instance.props && BDFDB.getData("addInMemberList", this, "settings")) this.addOwnerTag(instance.props.user, null, wrapper.querySelector(BDFDB.dotCN.nametag), "list", BDFDB.disCN.bottagnametag, null); } processUserPopout (instance, wrapper) { if (instance.props && BDFDB.getData("addInUserPopout", this, "settings")) this.addOwnerTag(instance.props.user, null, wrapper.querySelector(BDFDB.dotCN.nametag), "popout", BDFDB.disCN.bottagnametag, wrapper); } processUserProfile (instance, wrapper) { if (instance.props && BDFDB.getData("addInUserProfil", this, "settings")) this.addOwnerTag(instance.props.user, null, wrapper.querySelector(BDFDB.dotCN.nametag), "profile", BDFDB.disCNS.bottagnametag + BDFDB.disCN.userprofilebottag, wrapper); } 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, message.channel_id, username.parentElement, "chat", 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, .owner-tag-crown"); BDFDB.WebModules.forceAllUpdates(this); this.addHideCSS(); } } addOwnerTag (info, channelid, wrapper, type, selector = "", container) { if (!info || !wrapper || !wrapper.parentElement) return; BDFDB.removeEles(wrapper.querySelectorAll(".owner-tag, .owner-tag-crown")); let channel = this.ChannelUtils.getChannel(channelid || this.LastChannelStore.getChannelId()); if (!channel) return; let guild = this.GuildUtils.getGuild(channel.guild_id); let settings = BDFDB.getAllData(this, "settings"); let isowner = channel.ownerId == info.id || guild && guild.ownerId == info.id; if (!(isowner || (settings.addForAdmins && BDFDB.isUserAllowedTo("ADMINISTRATOR", info.id)))) return; let member = settings.useRoleColor ? (this.MemberUtils.getMember(channel.guild_id, info.id) || {}) : {}; let EditUsersData = BDFDB.isPluginEnabled("EditUsers") ? window.bdplugins.EditUsers.plugin.getUserData(info.id, wrapper) : {}; if (!settings.useCrown) { let tag = BDFDB.htmlToElement(`${BDFDB.getData(isowner ? "ownTagName" : "ownAdminTagName", this, "inputs")}`); let invert = container && container.firstElementChild && !(BDFDB.containsClass(container.firstElementChild, BDFDB.disCN.userpopoutheadernormal) || BDFDB.containsClass(container.firstElementChild, BDFDB.disCN.userprofiletopsectionnormal)); 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]")); } else { let crown = BDFDB.htmlToElement(``); crown.addEventListener("mouseenter", () => { BDFDB.createTooltip(isowner ? (channel.type == 3 ? BDFDB.LanguageStrings.GROUP_OWNER : BDFDB.LanguageStrings.GUILD_OWNER) : BDFDB.LanguageStrings.ADMINISTRATOR, crown, {type: "top"}); }); wrapper.insertBefore(crown, wrapper.querySelector(".TRE-tag,svg[name=MobileDevice]")); } } addHideCSS () { var settings = BDFDB.getAllData(this, "settings"); if (settings.hideNativeCrown || settings.useCrown) BDFDB.appendLocalStyle(this.name + "HideCrown", `${BDFDB.dotCNS.member + BDFDB.dotCN.memberownericon}:not(.owner-tag-crown) {display: none;}`); else BDFDB.removeLocalStyle(this.name + "HideCrown"); } }