2019-01-31 17:06:48 +01:00
//META{"name":"BadgesEverywhere","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BadgesEverywhere","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/BadgesEverywhere/BadgesEverywhere.plugin.js"}*//
2018-10-16 21:33:23 +02:00
2018-10-11 10:21:26 +02:00
class BadgesEverywhere {
2019-03-06 14:00:44 +01:00
getName ( ) { return "BadgesEverywhere" ; }
2019-01-11 18:57:49 +01:00
2019-06-04 09:13:12 +02:00
getVersion ( ) { return "1.3.2" ; }
2019-01-11 18:57:49 +01:00
getAuthor ( ) { return "DevilBro" ; }
getDescription ( ) { return "Displays Badges (Nitro, HypeSquad, etc...) in the chat/memberlist/userpopout. Thanks for Zerebos' help." ; }
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
initConstructor ( ) {
2019-05-12 09:33:50 +02:00
this . changelog = {
2019-06-02 20:53:49 +02:00
"improved" : [ [ "Guild Boost" , "Changed the general guild boost badge in a way that it's displayed everywhere in all servers and added the option to add the badge for the boosting of the current server" ] ] ,
2019-06-04 09:13:12 +02:00
"fixed" : [ [ "Message Username" , "Fixed the issue that moved the message username when a badge was appended" ] , [ "Badges" , "Some badges didn't get added properly" ] ]
2019-05-12 09:33:50 +02:00
} ;
2018-12-27 10:16:30 +01:00
this . patchModules = {
"NameTag" : "componentDidMount" ,
2019-01-15 10:04:23 +01:00
"MessageUsername" : "componentDidMount" ,
2018-12-27 10:16:30 +01:00
"StandardSidebarView" : "componentWillUnmount"
} ;
2019-01-26 22:45:19 +01:00
2019-06-03 21:24:55 +02:00
this . css = `
$ { BDFDB . dotCNS . message + BDFDB . dotCN . messageheadercozy } {
padding - top : 0 ;
}
$ { BDFDB . dotCNC . userpopoutheadertagnonickname + BDFDB . dotCNC . userpopoutheadernamewrapper + BDFDB . dotCN . messageheadercozymeta } > span : first - child {
2019-06-02 20:53:49 +02:00
display : inline - flex ;
}
2018-10-11 10:21:26 +02:00
. BE - badge {
2019-06-02 14:36:54 +02:00
position : relative ;
2019-05-12 09:33:50 +02:00
background - size : contain ;
background - position : center ;
background - repeat : no - repeat ;
2019-06-02 14:36:54 +02:00
display : inline - flex ;
align - items : center ;
2019-06-04 09:17:54 +02:00
justify - content : center ;
2018-12-13 20:36:23 +01:00
height : 17 px ! important ;
margin : 0 2 px ! important ;
2018-10-11 10:21:26 +02:00
}
2019-06-02 14:36:54 +02:00
. BE - badge . BE - badge - list : not ( . BE - badge - CurrentGuildBoost ) {
top : 1 px ! important ;
2018-10-11 10:21:26 +02:00
}
2019-06-02 14:36:54 +02:00
. BE - badge . BE - badge - popout : not ( . BE - badge - CurrentGuildBoost ) {
top : 3 px ! important ;
2018-10-11 10:21:26 +02:00
}
2019-06-02 14:36:54 +02:00
. BE - badge . BE - badge - list . BE - badge - CurrentGuildBoost {
top : - 2 px ! important ;
}
2019-06-04 09:15:56 +02:00
. BE - badge . BE - badge - chat . BE - badge - CurrentGuildBoost {
top : - 3 px ! important ;
}
2019-06-02 14:36:54 +02:00
. BE - badge : not ( . BE - badge - settings ) : first - of - type {
2018-12-13 20:36:23 +01:00
margin - left : 5 px ! important ;
2018-10-11 10:21:26 +02:00
}
2019-06-02 14:36:54 +02:00
. BE - badge : not ( . BE - badge - settings ) : last - of - type {
2018-12-13 20:36:23 +01:00
margin - right : 5 px ! important ;
2018-10-11 10:21:26 +02:00
}
2019-06-02 14:36:54 +02:00
$ { BDFDB . dotCN . userprofiletopsectionplaying } . BE - badge . BE - badge - CurrentGuildBoost svg {
color : white ! important ;
}
2018-12-11 20:27:40 +01:00
. BE - badge . BE - badge - Staff { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - Partner { width : 22 px ! important ; min - width : 22 px ! important ; }
. BE - badge . BE - badge - HypeSquad { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - BugHunter { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - HypeSquadBravery { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - HypeSquadBrilliance { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - HypeSquadBalance { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - EarlySupporter { width : 24 px ! important ; min - width : 24 px ! important ; }
2019-01-11 18:57:49 +01:00
. BE - badge . BE - badge - Nitro { width : 21 px ! important ; min - width : 21 px ! important ; }
2019-06-02 14:36:54 +02:00
. BE - badge . BE - badge - NitroGuildBoost { width : 17 px ! important ; min - width : 17 px ! important ; }
. BE - badge . BE - badge - CurrentGuildBoost { width : 14 px ! important ; min - width : 14 px ! important ; }
2019-05-31 10:31:01 +02:00
2019-06-02 14:36:54 +02:00
. BE - badge . BE - badge - settings { width : 30 px ! important ; min - width : 30 px ! important ; }
2019-05-31 10:31:01 +02:00
2019-06-02 14:36:54 +02:00
$ { BDFDB . dotCNS . member + BDFDB . dotCN . memberpremiumicon } : not ( . BE - badge - CurrentGuildBoost - inner ) { display : none ; } ` ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . requestedusers = { } ;
this . loadedusers = { } ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this . defaults = {
settings : {
2018-12-12 00:11:53 +01:00
showInPopout : { value : true , description : "Show Badge in User Popout." } ,
2018-10-11 10:21:26 +02:00
showInChat : { value : true , description : "Show Badge in Chat Window." } ,
showInMemberList : { value : true , description : "Show Badge in Member List." } ,
2019-05-20 14:53:31 +02:00
useColoredVersion : { value : true , description : "Use colored version of the Badges for Chat and Members." } ,
2019-06-02 14:36:54 +02:00
showNitroDate : { value : true , description : "Show the subscription date for Nitro/Boost Badges" }
2019-01-11 18:57:49 +01:00
} ,
badges : {
2019-06-04 09:13:12 +02:00
"STAFF" : { value : true , id : "Staff" , name : "STAFF_BADGE_TOOLTIP" , selector : "profileBadgeStaff" } ,
"PARTNER" : { value : true , id : "Partner" , name : "PARTNER_BADGE_TOOLTIP" , selector : "profileBadgePartner" } ,
"HYPESQUAD" : { value : true , id : "HypeSquad" , name : "HYPESQUAD_BADGE_TOOLTIP" , selector : "profileBadgeHypesquad" } ,
"BUG_HUNTER" : { value : true , id : "BugHunter" , name : "BUG_HUNTER_BADGE_TOOLTIP" , selector : "profileBadgeBugHunter" } ,
"MFA_SMS" : { value : false , id : null , name : null , selector : false } ,
"PREMIUM_PROMO_DISMISSED" : { value : false , id : null , name : null , selector : false } ,
"HYPESQUAD_ONLINE_HOUSE_1" : { value : true , id : "HypeSquadBravery" , name : "HypeSquad Bravery" , selector : "profileBadgeHypeSquadOnlineHouse1" } ,
"HYPESQUAD_ONLINE_HOUSE_2" : { value : true , id : "HypeSquadBrilliance" , name : "HypeSquad Brilliance" , selector : "profileBadgeHypeSquadOnlineHouse2" } ,
"HYPESQUAD_ONLINE_HOUSE_3" : { value : true , id : "HypeSquadBalance" , name : "HypeSquad Balance" , selector : "profileBadgeHypeSquadOnlineHouse3" } ,
"PREMIUM_EARLY_SUPPORTER" : { value : true , id : "EarlySupporter" , name : "EARLY_SUPPORTER_TOOLTIP" , selector : "profileBadgeEarlySupporter" } ,
"NITRO" : { value : true , id : "Nitro" , name : "Nitro" , selector : "profileBadgePremium" } ,
"GUILD_BOOST" : { value : true , id : "NitroGuildBoost" , name : "Nitro Guild Boost" , selector : "profileGuildSubscriberlvl" , types : [ 1 , 2 , 3 , 4 ] } ,
2019-05-31 10:31:01 +02:00
} ,
2019-06-02 14:36:54 +02:00
indicators : {
"CURRENT_GUILD_BOOST" : { value : true , name : "Current Nitro Guild Boost" , markup : ` <div class="BE-badge BE-badge-CurrentGuildBoost"><svg aria-label="Nitro boosting since May 31, 2019" name="PremiumGuildSubscriberBadge" class="BE-badge-CurrentGuildBoost-inner ${ BDFDB . disCNS . memberpremiumicon + BDFDB . disCN . membericon } " aria-hidden="false" width="24" height="24" viewBox="0 0 8 12" style="margin: 0;"><path d="M4 0L0 4V8L4 12L8 8V4L4 0ZM7 7.59L4 10.59L1 7.59V4.41L4 1.41L7 4.41V7.59Z" fill="currentColor"></path><path d="M2 4.83V7.17L4 9.17L6 7.17V4.83L4 2.83L2 4.83Z" fill="currentColor"></path></svg></div> ` } ,
2018-10-11 10:21:26 +02:00
}
} ;
2019-05-21 15:45:43 +02:00
var UserFlags = BDFDB . WebModules . findByProperties ( "UserFlags" ) . UserFlags ;
for ( let flagname in UserFlags ) if ( this . defaults . badges [ flagname ] ) {
2019-05-31 10:31:01 +02:00
if ( BDFDB . LanguageStringsCheck [ this . defaults . badges [ flagname ] . name ] ) this . defaults . badges [ flagname ] . name = BDFDB . LanguageStrings [ this . defaults . badges [ flagname ] . name ] ;
2019-05-21 15:45:43 +02:00
this . defaults . badges [ UserFlags [ flagname ] ] = this . defaults . badges [ flagname ] ;
delete this . defaults . badges [ flagname ] ;
}
this . nitroflag = Math . pow ( 2 , Object . keys ( UserFlags ) . length ) ;
this . defaults . badges [ this . nitroflag ] = this . defaults . badges . NITRO ;
delete this . defaults . badges . NITRO ;
2019-06-02 14:36:54 +02:00
this . boostflag = Math . pow ( 2 , Object . keys ( UserFlags ) . length + 1 ) ;
this . defaults . badges [ this . boostflag ] = this . defaults . badges . GUILD _BOOST ;
delete this . defaults . badges . GUILD _BOOST ;
2019-05-21 15:45:43 +02:00
for ( let flag in this . defaults . badges ) if ( ! this . defaults . badges [ flag ] . selector || isNaN ( parseInt ( flag ) ) ) delete this . defaults . badges [ flag ] ;
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-22 11:28:32 +01:00
if ( ! global . BDFDB || typeof BDFDB != "object" || ! BDFDB . loaded || ! this . started ) return ;
2019-05-31 10:31:01 +02:00
var settings = BDFDB . getAllData ( this , "settings" ) ;
var badges = BDFDB . getAllData ( this , "badges" ) ;
2019-06-02 14:36:54 +02:00
var indicators = BDFDB . getAllData ( this , "indicators" ) ;
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"> ` ;
2018-10-11 10:21:26 +02:00
for ( let key in settings ) {
2019-01-11 18:57:49 +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-11-04 11:40:41 +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;">Display Badges:</h3></div><div class="BDFDB-settings-inner-list"> ` ;
2019-01-11 18:57:49 +01:00
for ( let flag in badges ) {
2019-06-02 14:36:54 +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: 1 1 auto;"> ${ this . defaults . badges [ flag ] . name } </h3><span class="BE-badges BE-badges-settings ${ BDFDB . disCN . userprofiletopsectionplaying } " style="all: unset !important;"> ` ;
2019-06-04 09:13:12 +02:00
if ( Array . isArray ( this . defaults . badges [ flag ] . types ) ) for ( let type of this . defaults . badges [ flag ] . types ) settingshtml += ` <div class="BE-badge BE-badge- ${ this . defaults . badges [ flag ] . id } ${ this . BadgeClasses [ this . defaults . badges [ flag ] . selector + type ] } "></div> ` ;
else settingshtml += ` <div class="BE-badge BE-badge- ${ this . defaults . badges [ flag ] . id } ${ this . BadgeClasses [ this . defaults . badges [ flag ] . selector ] } "></div> ` ;
2019-06-02 14:36:54 +02:00
settingshtml += ` </span><span class="BE-badges BE-badges-settings ${ BDFDB . disCN . userprofiletopsectionnormal } " style="all: unset !important;"> `
2019-06-04 09:13:12 +02:00
if ( Array . isArray ( this . defaults . badges [ flag ] . types ) ) for ( let type of this . defaults . badges [ flag ] . types ) settingshtml += ` <div class="BE-badge BE-badge- ${ this . defaults . badges [ flag ] . id } ${ this . BadgeClasses [ this . defaults . badges [ flag ] . selector + type ] } "></div> ` ;
else settingshtml += ` <div class="BE-badge BE-badge- ${ this . defaults . badges [ flag ] . id } ${ this . BadgeClasses [ this . defaults . badges [ flag ] . selector ] } "></div> ` ;
2019-06-02 14:36:54 +02:00
settingshtml += ` </span><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="badges ${ flag } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } settings-switch" ${ badges [ flag ] ? " checked" : "" } ></div></div> ` ;
2018-10-11 10:21:26 +02:00
}
2019-06-02 14:36:54 +02:00
for ( let flag in indicators ) {
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 . indicators [ flag ] . name } </h3><span class="BE-badges BE-badges-settings ${ BDFDB . disCN . userprofiletopsectionplaying } " style="all: unset !important;"> ${ this . defaults . indicators [ flag ] . markup } </span><span class="BE-badges BE-badges-settings ${ BDFDB . disCN . userprofiletopsectionnormal } " style="all: unset !important;"> ${ this . defaults . indicators [ flag ] . markup } </span><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="indicators ${ flag } " class=" ${ BDFDB . disCNS . switchinnerenabled + BDFDB . disCN . switchinner } settings-switch" ${ indicators [ flag ] ? " checked" : "" } ></div></div> ` ;
2019-05-31 10:31:01 +02:00
}
2019-01-26 22:45:19 +01:00
2018-11-04 11:40:41 +01:00
settingshtml += ` </div></div></div> ` ;
2019-01-26 22:45:19 +01:00
2019-01-11 18:57:49 +01:00
let settingspanel = BDFDB . htmlToElement ( settingshtml ) ;
2019-06-02 14:36:54 +02:00
BDFDB . addClass ( settingspanel . querySelectorAll ( ".BE-badge" ) , "BE-badge-settings" ) ;
2018-10-11 10:21:26 +02:00
2019-01-11 18:57:49 +01:00
BDFDB . initElements ( settingspanel , this ) ;
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02: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-05-26 13:55:26 +02:00
var libraryScript = document . querySelector ( 'head script#BDFDBLibraryScript' ) ;
if ( ! libraryScript || ( performance . now ( ) - libraryScript . getAttribute ( "date" ) ) > 600000 ) {
2018-10-11 10:21:26 +02:00
if ( libraryScript ) libraryScript . remove ( ) ;
libraryScript = document . createElement ( "script" ) ;
2019-05-26 13:55:26 +02:00
libraryScript . setAttribute ( "id" , "BDFDBLibraryScript" ) ;
2018-10-11 10:21:26 +02:00
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-05-26 13:55:26 +02:00
libraryScript . addEventListener ( "load" , ( ) => { this . initialize ( ) ; } ) ;
2018-10-11 10:21:26 +02:00
document . head . appendChild ( libraryScript ) ;
2019-05-26 13:55:26 +02:00
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 ( ) ;
2018-10-11 10:21:26 +02: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 ;
2018-10-11 10:21:26 +02:00
BDFDB . loadMessage ( this ) ;
2019-01-26 22:45:19 +01:00
2019-05-31 10:31:01 +02:00
this . MemberUtils = BDFDB . WebModules . findByProperties ( "getMembers" , "getMember" ) ;
this . GuildBoostUtils = BDFDB . WebModules . findByProperties ( "getTierName" , "getUserLevel" ) ;
this . LastGuildStore = BDFDB . WebModules . findByProperties ( "getLastSelectedGuildId" ) ;
2018-12-20 22:54:42 +01:00
this . APIModule = BDFDB . WebModules . findByProperties ( "getAPIBaseURL" ) ;
this . DiscordConstants = BDFDB . WebModules . findByProperties ( "Permissions" , "ActivityTypes" , "StatusTypes" ) ;
this . BadgeClasses = BDFDB . WebModules . findByProperties ( "profileBadgeStaff" , "profileBadgePremium" ) ;
2019-01-26 22:45:19 +01:00
2018-12-27 10:16:30 +01:00
BDFDB . WebModules . forceAllUpdates ( this ) ;
2018-10-11 10:21:26 +02: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!' ) ;
2018-10-11 10:21:26 +02:00
}
}
stop ( ) {
2019-01-17 23:48:29 +01:00
if ( global . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2018-12-27 10:51:39 +01:00
BDFDB . removeEles ( ".BE-badges" ) ;
2018-10-11 10:21:26 +02:00
BDFDB . unloadMessage ( this ) ;
}
}
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
2018-12-27 10:16:30 +01:00
processNameTag ( instance , wrapper ) {
if ( ! wrapper . classList || ! instance || ! instance . props ) return ;
2019-01-16 11:42:05 +01:00
else if ( BDFDB . containsClass ( wrapper , BDFDB . disCN . membernametag ) && BDFDB . getData ( "showInMemberList" , this , "settings" ) ) {
2018-12-27 10:16:30 +01:00
this . addBadges ( instance . props . user , wrapper , "list" ) ;
2018-10-11 10:21:26 +02:00
}
2019-01-16 11:42:05 +01:00
else if ( BDFDB . containsClass ( wrapper , BDFDB . disCN . userpopoutheadertag ) && BDFDB . getData ( "showInPopout" , this , "settings" ) ) {
wrapper = BDFDB . containsClass ( wrapper , BDFDB . disCN . userpopoutheadertagwithnickname ) && wrapper . previousSibling ? wrapper . previousSibling : wrapper ;
2018-12-27 10:16:30 +01:00
this . addBadges ( instance . props . user , wrapper , "popout" ) ;
2018-10-11 10:21:26 +02:00
}
2018-12-27 10:16:30 +01:00
}
2019-01-26 22:45:19 +01:00
2019-01-15 10:04:23 +01:00
processMessageUsername ( instance , wrapper ) {
let message = BDFDB . getReactValue ( instance , "props.message" ) ;
if ( message ) {
2018-12-27 10:16:30 +01:00
let username = wrapper . querySelector ( BDFDB . dotCN . messageusername ) ;
2019-01-15 10:04:23 +01:00
if ( username && BDFDB . getData ( "showInChat" , this , "settings" ) ) this . addBadges ( message . author , wrapper , "chat" ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2018-12-27 10:16:30 +01:00
processStandardSidebarView ( instance , wrapper ) {
2019-01-11 18:57:49 +01:00
if ( this . SettingsUpdated ) {
2019-01-11 19:02:20 +01:00
delete this . SettingsUpdated ;
2018-12-27 10:16:30 +01:00
BDFDB . WebModules . forceAllUpdates ( this ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2018-12-27 10:16:30 +01:00
addBadges ( info , wrapper , type ) {
if ( ! info || info . bot || ! wrapper ) return ;
if ( ! this . requestedusers [ info . id ] ) {
2019-01-11 19:01:49 +01:00
this . requestedusers [ info . id ] = [ [ wrapper , type ] ] ;
2018-12-27 10:16:30 +01:00
this . APIModule . get ( this . DiscordConstants . Endpoints . USER _PROFILE ( info . id ) ) . then ( result => {
let usercopy = Object . assign ( { } , result . body . user ) ;
2019-05-21 15:45:43 +02:00
if ( result . body . premium _since ) usercopy . flags += this . nitroflag ;
2019-05-20 14:53:31 +02:00
usercopy . premium _since = result . body . premium _since ;
2019-06-02 14:36:54 +02:00
if ( result . body . premium _guild _since ) usercopy . flags += this . boostflag ;
usercopy . premium _guild _since = result . body . premium _guild _since ;
2018-12-27 10:16:30 +01:00
this . loadedusers [ info . id ] = usercopy ;
for ( let queredobj of this . requestedusers [ info . id ] ) this . addToWrapper ( info , queredobj [ 0 ] , queredobj [ 1 ] ) ;
} ) ;
}
else if ( ! this . loadedusers [ info . id ] ) {
this . requestedusers [ info . id ] . push ( [ wrapper , type ] ) ;
}
else {
this . addToWrapper ( info , wrapper , type ) ;
}
}
2019-01-26 22:45:19 +01:00
2018-12-27 10:16:30 +01:00
addToWrapper ( info , wrapper , type ) {
2019-01-16 11:42:05 +01:00
BDFDB . removeEles ( wrapper . querySelectorAll ( ".BE-badges" ) ) ;
2019-01-11 18:57:49 +01:00
let badges = BDFDB . getAllData ( this , "badges" ) ;
2019-06-02 14:36:54 +02:00
let indicators = BDFDB . getAllData ( this , "indicators" ) ;
2018-12-27 10:16:30 +01:00
let settings = BDFDB . getAllData ( this , "settings" ) ;
let header = BDFDB . getParentEle ( BDFDB . dotCN . userpopoutheader , wrapper ) ;
2019-06-02 14:36:54 +02:00
let badgewrapper = BDFDB . htmlToElement ( ` <span class="BE-badges BE-badges- ${ type } ${ ! settings . useColoredVersion || ( header && ! BDFDB . containsClass ( header , BDFDB . disCN . userpopoutheadernormal ) ) ? BDFDB . disCN . userprofiletopsectionplaying : BDFDB . disCN . userprofiletopsectionnormal } " style="all: unset !important; order: 9 !important;"></span> ` ) ;
2019-01-11 18:57:49 +01:00
for ( let flag in this . defaults . badges ) {
if ( ( this . loadedusers [ info . id ] . flags | flag ) == this . loadedusers [ info . id ] . flags && badges [ flag ] ) {
2019-06-04 09:13:12 +02:00
let badge = BDFDB . htmlToElement ( ` <div class="BE-badge BE-badge- ${ this . defaults . badges [ flag ] . id } BE-badge- ${ type } ${ this . BadgeClasses [ this . defaults . badges [ flag ] . selector + ( flag == this . boostflag ? this . GuildBoostUtils . getUserLevel ( this . loadedusers [ info . id ] . premium _guild _since ) : "" ) ] } "></div> ` ) ;
2018-12-27 10:16:30 +01:00
badgewrapper . appendChild ( badge ) ;
2019-06-02 14:36:54 +02:00
badge . addEventListener ( "mouseenter" , ( ) => {
let text = this . defaults . badges [ flag ] . name ;
if ( flag == this . nitroflag && settings . showNitroDate ) text = BDFDB . LanguageStringsFormat ( "PREMIUM_BADGE_TOOLTIP" , new Date ( this . loadedusers [ info . id ] . premium _since ) ) ;
else if ( flag == this . boostflag && settings . showNitroDate ) text = BDFDB . LanguageStringsFormat ( "PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP" , new Date ( this . loadedusers [ info . id ] . premium _guild _since ) ) ;
BDFDB . createTooltip ( text , badge , { type : "top" , style : "white-space: nowrap; max-width: unset" } ) ;
} ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-05-31 10:31:01 +02:00
let member = this . MemberUtils . getMember ( this . LastGuildStore . getGuildId ( ) , info . id ) ;
2019-06-02 14:36:54 +02:00
if ( indicators . CURRENT _GUILD _BOOST && member && member . premiumSince ) {
let badge = BDFDB . htmlToElement ( this . defaults . indicators . CURRENT _GUILD _BOOST . markup ) ;
BDFDB . addClass ( badge , ` BE-badge- ${ type } ` ) ;
2019-05-31 10:31:01 +02:00
badgewrapper . appendChild ( badge ) ;
2019-06-02 14:36:54 +02:00
badge . addEventListener ( "mouseenter" , ( ) => { BDFDB . createTooltip ( settings . showNitroDate ? BDFDB . LanguageStringsFormat ( "PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP" , new Date ( member . premiumSince ) ) : "Boosting current server" , badge , { type : "top" , style : "white-space: nowrap; max-width: unset" } ) ; } ) ;
2019-05-31 10:31:01 +02:00
}
2019-01-17 10:38:58 +01:00
if ( badgewrapper . firstChild ) wrapper . insertBefore ( badgewrapper , wrapper . querySelector ( ".owner-tag,.TRE-tag,svg[name=MobileDevice]" ) ) ;
2018-10-11 10:21:26 +02:00
}
2018-12-27 12:56:10 +01:00
}