2019-01-31 17:06:48 +01:00
//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"}*//
2019-01-09 12:56:24 +01:00
class OwnerTag {
getName ( ) { return "OwnerTag" ; }
2019-05-13 22:31:55 +02:00
getVersion ( ) { return "1.1.1" ; }
2019-01-09 12:56:24 +01:00
getAuthor ( ) { return "DevilBro" ; }
getDescription ( ) { return "Adds a Tag like Bottags to the Serverowner." ; }
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
initConstructor ( ) {
2019-01-28 13:42:22 +01:00
this . changelog = {
2019-05-13 22:31:55 +02:00
"added" : [ [ "Native Crown Option" , "Added an option to disable the hiding of the native crown, allowing you to have the written owner tag and the crown" ] ]
2019-01-28 13:42:22 +01:00
} ;
2019-01-09 12:56:24 +01:00
this . patchModules = {
2019-01-15 10:04:23 +01:00
"NameTag" : [ "componentDidMount" , "componentDidUpdate" ] ,
"MessageUsername" : [ "componentDidMount" , "componentDidUpdate" ] ,
2019-01-09 12:56:24 +01:00
"StandardSidebarView" : "componentWillUnmount"
} ;
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
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" } ,
2019-01-09 13:05:51 +01:00
addInUserProfil : { value : true , inner : true , description : "User Profile Modal" } ,
2019-01-10 20:17:42 +01:00
useRoleColor : { value : true , inner : false , description : "Use the Rolecolor instead of the default blue." } ,
2019-01-28 13:42:22 +01:00
useBlackFont : { value : false , inner : false , description : "Instead of darkening the Rolecolor on bright colors use black font." } ,
2019-05-13 22:31:55 +02:00
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)." } ,
2019-02-13 13:29:23 +01:00
addForAdmins : { value : false , inner : false , description : "Also add the Tag for any user with Admin rights." }
2019-01-09 12:56:24 +01:00
} ,
inputs : {
2019-02-13 13:29:23 +01:00
ownTagName : { value : "Owner" , description : "Owner Tag Text for Owners" } ,
ownAdminTagName : { value : "Admin" , description : "Owner Tag Text for Admins" }
2019-01-09 12:56:24 +01:00
}
} ;
}
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
getSettingsPanel ( ) {
2019-01-22 11:28:32 +01:00
if ( ! global . BDFDB || typeof BDFDB != "object" || ! BDFDB . loaded || ! this . started ) return ;
2019-05-11 18:04:29 +02:00
var settings = BDFDB . getAllData ( this , "settings" ) ;
2019-01-09 12:56:24 +01:00
var inputs = BDFDB . getAllData ( this , "inputs" ) ;
2019-04-18 09:28:20 +02:00
var settingshtml = ` <div class=" ${ this . name } -settings BDFDB-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="BDFDB-settings-inner"> ` ;
2019-01-09 12:56:24 +01:00
for ( let key in inputs ) {
2019-02-13 13:29:23 +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 . weightmedium + BDFDB . disCNS . size16 + BDFDB . disCN . flexchild } " style="flex: 0 0 50%;"> ${ this . defaults . inputs [ key ] . description } </h3><div class=" ${ BDFDB . disCNS . inputwrapper + BDFDB . disCNS . vertical + BDFDB . disCNS . flex + BDFDB . disCN . directioncolumn } " style="flex: 1 1 auto;"><input type="text" option=" ${ key } " value=" ${ inputs [ key ] } " placeholder=" ${ this . defaults . inputs [ key ] . value } " class=" ${ BDFDB . disCNS . inputdefault + BDFDB . disCNS . input + BDFDB . disCN . size16 } "></div></div> ` ;
2019-01-09 12:56:24 +01:00
}
for ( let key in settings ) {
2019-01-15 10:04:23 +01:00
if ( ! this . defaults . settings [ key ] . inner ) 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> ` ;
2019-01-09 12:56:24 +01:00
}
2019-04-18 09:28:20 +02: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: 0 0 auto;">Add Owner Tag in:</h3></div><div class="BDFDB-settings-inner-list"> ` ;
2019-01-09 12:56:24 +01:00
for ( let key in settings ) {
2019-01-15 10:04:23 +01:00
if ( this . defaults . settings [ key ] . inner ) 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> ` ;
2019-01-09 12:56:24 +01:00
}
settingshtml += ` </div> ` ;
settingshtml += ` </div></div> ` ;
2019-01-26 22:45:19 +01:00
2019-01-10 20:17:42 +01:00
let settingspanel = BDFDB . htmlToElement ( settingshtml ) ;
2019-01-09 12:56:24 +01:00
2019-01-15 10:04:23 +01:00
BDFDB . initElements ( settingspanel , this ) ;
2019-01-09 12:56:24 +01:00
2019-01-17 23:48:29 +01:00
BDFDB . addEventListener ( this , settingspanel , "keyup" , BDFDB . dotCN . input , ( ) => { this . saveInputs ( settingspanel ) ; } ) ;
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
return settingspanel ;
}
//legacy
load ( ) { }
start ( ) {
2019-02-04 09:13:15 +01:00
if ( ! global . BDFDB ) global . BDFDB = { myPlugins : { } } ;
if ( global . BDFDB && global . BDFDB . myPlugins && typeof global . BDFDB . myPlugins == "object" ) global . BDFDB . myPlugins [ this . getName ( ) ] = this ;
2019-01-17 23:48:29 +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 ) {
2019-01-09 12:56:24 +01: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-17 23:48:29 +01:00
libraryScript . setAttribute ( "date" , performance . now ( ) ) ;
2019-01-30 21:23:49 +01:00
libraryScript . addEventListener ( "load" , ( ) => { if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ; } ) ;
2019-01-09 12:56:24 +01:00
document . head . appendChild ( libraryScript ) ;
}
2019-01-17 23:48:29 +01:00
else if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ;
2019-01-09 12:56:24 +01:00
this . startTimeout = setTimeout ( ( ) => { this . initialize ( ) ; } , 30000 ) ;
}
initialize ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-22 11:05:54 +01:00
if ( this . started ) return ;
2019-01-09 12:56:24 +01:00
BDFDB . loadMessage ( this ) ;
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
this . MemberUtils = BDFDB . WebModules . findByProperties ( "getMembers" , "getMember" ) ;
this . GuildUtils = BDFDB . WebModules . findByProperties ( "getGuilds" , "getGuild" ) ;
2019-02-13 13:29:23 +01:00
this . ChannelUtils = BDFDB . WebModules . findByProperties ( "getChannels" , "getChannel" ) ;
this . LastChannelStore = BDFDB . WebModules . findByProperties ( "getLastSelectedChannelId" ) ;
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
BDFDB . WebModules . forceAllUpdates ( this ) ;
2019-05-13 22:31:55 +02:00
this . addHideCSS ( ) ;
2019-01-09 12:56:24 +01:00
}
else {
2019-02-12 21:56:34 +01:00
console . error ( ` %c[ ${ this . getName ( ) } ]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , 'Fatal Error: Could not load BD functions!' ) ;
2019-01-09 12:56:24 +01:00
}
}
stop ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-28 13:42:22 +01:00
BDFDB . removeEles ( ".owner-tag, .owner-tag-crown" ) ;
2019-01-09 12:56:24 +01:00
BDFDB . unloadMessage ( this ) ;
}
}
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
// 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" ) ;
2019-01-17 23:48:29 +01:00
this . SettingsUpdated = true ;
2019-01-09 12:56:24 +01:00
}
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
processNameTag ( instance , wrapper ) {
2019-01-09 14:21:55 +01:00
let container = null ;
2019-01-09 12:56:24 +01:00
if ( ! instance . props || ! wrapper . classList ) return ;
2019-01-17 10:02:26 +01:00
else if ( BDFDB . containsClass ( wrapper , BDFDB . disCN . membernametag ) && BDFDB . getData ( "addInMemberList" , this , "settings" ) ) {
2019-02-13 13:29:23 +01:00
this . addOwnerTag ( instance . props . user , null , wrapper , "list" , BDFDB . disCN . bottagnametag + ( instance . props . botClass ? ( " " + instance . props . botClass ) : "" ) , container ) ;
2019-01-09 12:56:24 +01:00
}
2019-01-09 14:21:55 +01:00
else if ( ( container = BDFDB . getParentEle ( BDFDB . dotCN . userpopout , wrapper ) ) != null && BDFDB . getData ( "addInUserPopout" , this , "settings" ) ) {
2019-02-13 13:29:23 +01:00
this . addOwnerTag ( instance . props . user , null , wrapper , "popout" , BDFDB . disCN . bottagnametag + ( instance . props . botClass ? ( " " + instance . props . botClass ) : "" ) , container ) ;
2019-01-09 12:56:24 +01:00
}
2019-01-09 14:21:55 +01:00
else if ( ( container = BDFDB . getParentEle ( BDFDB . dotCN . userprofile , wrapper ) ) != null && BDFDB . getData ( "addInUserProfil" , this , "settings" ) ) {
2019-02-13 13:29:23 +01:00
this . addOwnerTag ( instance . props . user , null , wrapper , "profile" , BDFDB . disCN . bottagnametag + ( instance . props . botClass ? ( " " + instance . props . botClass ) : "" ) , container ) ;
2019-01-09 12:56:24 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-01-15 10:04:23 +01:00
processMessageUsername ( instance , wrapper , methodnames ) {
let message = BDFDB . getReactValue ( instance , "props.message" ) ;
if ( message && BDFDB . getData ( "addInChatWindow" , this , "settings" ) ) {
2019-01-09 12:56:24 +01:00
let username = wrapper . querySelector ( BDFDB . dotCN . messageusername ) ;
if ( username ) {
2019-01-15 10:04:23 +01:00
let messagegroup = BDFDB . getParentEle ( BDFDB . dotCN . messagegroup , wrapper ) ;
2019-02-13 13:29:23 +01:00
this . addOwnerTag ( message . author , message . channel _id , username . parentElement , "chat" , BDFDB . disCN . bottagmessage + " " + ( BDFDB . containsClass ( messagegroup , BDFDB . disCN . messagegroupcozy ) ? BDFDB . disCN . bottagmessagecozy : BDFDB . disCN . bottagmessagecompact ) , null ) ;
2019-01-09 12:56:24 +01:00
}
}
}
2019-01-26 22:45:19 +01:00
2019-01-09 12:56:24 +01:00
processStandardSidebarView ( instance , wrapper ) {
2019-01-15 10:04:23 +01:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
2019-02-13 13:45:13 +01:00
BDFDB . removeEles ( ".owner-tag, .owner-tag-crown" ) ;
2019-01-09 12:56:24 +01:00
BDFDB . WebModules . forceAllUpdates ( this ) ;
2019-05-13 22:31:55 +02:00
this . addHideCSS ( ) ;
2019-01-09 12:56:24 +01:00
}
}
2019-01-26 22:45:19 +01:00
2019-02-13 13:29:23 +01:00
addOwnerTag ( info , channelid , wrapper , type , selector = "" , container ) {
2019-01-09 12:56:24 +01:00
if ( ! info || ! wrapper || ! wrapper . parentElement ) return ;
2019-01-28 13:42:22 +01:00
BDFDB . removeEles ( wrapper . querySelectorAll ( ".owner-tag, .owner-tag-crown" ) ) ;
2019-02-13 13:29:23 +01:00
let channel = this . ChannelUtils . getChannel ( channelid || this . LastChannelStore . getChannelId ( ) ) ;
if ( ! channel ) return ;
let guild = this . GuildUtils . getGuild ( channel . guild _id ) ;
2019-01-10 20:17:42 +01:00
let settings = BDFDB . getAllData ( this , "settings" ) ;
2019-02-13 13:29:23 +01:00
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 ) || { } ) : { } ;
2019-01-09 12:56:24 +01:00
let EditUsersData = BDFDB . isPluginEnabled ( "EditUsers" ) ? bdplugins . EditUsers . plugin . getUserData ( info . id , wrapper ) : { } ;
2019-01-28 13:42:22 +01:00
if ( ! settings . useCrown ) {
2019-02-13 13:45:13 +01:00
let tag = BDFDB . htmlToElement ( ` <span class="owner-tag ${ isowner ? "owner-tag-owner" : "owner-tag-admin" } owner- ${ type } -tag ${ ( settings . useRoleColor ? "owner-tag-rolecolor " : "" ) + BDFDB . disCN . bottag + ( selector ? ( " " + selector ) : "" ) } " style="order: 10 !important;"> ${ BDFDB . getData ( isowner ? "ownTagName" : "ownAdminTagName" , this , "inputs" ) } </span> ` ) ;
2019-01-28 13:42:22 +01:00
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]" ) ) ;
}
2019-05-11 18:04:29 +02:00
else {
let crown = BDFDB . htmlToElement ( ` <svg name="Crown" class="owner-tag-crown ${ isowner ? "owner-tag-owner" : "owner-tag-admin" } ${ BDFDB . disCNS . membericon + BDFDB . disCN . memberownericon } " width="24" height="24" viewBox="0 0 24 24"><g fill="none" fill-rule="evenodd"><path fill=" ${ isowner ? "#faa61a" : "#b3b3b3" } " fill-rule="nonzero" d="M2,11 L0,0 L5.5,7 L9,0 L12.5,7 L18,0 L16,11 L2,11 L2,11 Z M16,14 C16,14.5522847 15.5522847,15 15,15 L3,15 C2.44771525,15 2,14.5522847 2,14 L2,13 L16,13 L16,14 Z" transform="translate(3 4)"></path><rect width="24" height="24"></rect></g></svg> ` ) ;
2019-01-28 13:42:22 +01:00
crown . addEventListener ( "mouseenter" , ( ) => {
2019-02-13 13:29:23 +01:00
BDFDB . createTooltip ( isowner ? ( channel . type == 3 ? BDFDB . LanguageStrings . GROUP _OWNER : BDFDB . LanguageStrings . GUILD _OWNER ) : BDFDB . LanguageStrings . ADMINISTRATOR , crown , { type : "top" } ) ;
2019-01-28 13:42:22 +01:00
} ) ;
wrapper . insertBefore ( crown , wrapper . querySelector ( ".TRE-tag,svg[name=MobileDevice]" ) ) ;
}
2019-01-09 12:56:24 +01:00
}
2019-05-13 22:31:55 +02:00
addHideCSS ( ) {
if ( BDFDB . getData ( "hideNativeCrown" , this , "settings" ) ) BDFDB . appendLocalStyle ( this . name + "HideCrown" , ` ${ BDFDB . dotCNS . member + BDFDB . dotCN . memberownericon } :not(.owner-tag-crown) {display: none;} ` ) ;
else BDFDB . removeLocalstyle ( this . name + "HideCrown" ) ;
}
2019-01-09 15:17:35 +01:00
}