2021-05-31 14:52:40 +02:00
/ * *
* @ name ShowConnections
* @ author DevilBro
* @ authorId 278543574059057154
2024-08-16 17:34:08 +02:00
* @ version 1.2 . 5
2021-05-31 14:52:40 +02:00
* @ description Shows the connected Accounts of a User in the UserPopout
* @ invite Jx3TjNS
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //mwittrien.github.io/
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowConnections/
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/ShowConnections/ShowConnections.plugin.js
* /
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2022-09-02 12:37:10 +02:00
2021-05-31 14:52:40 +02:00
} ;
2022-02-05 21:14:17 +01:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2022-09-01 14:55:22 +02:00
constructor ( meta ) { for ( let key in meta ) this [ key ] = meta [ key ] ; }
getName ( ) { return this . name ; }
getAuthor ( ) { return this . author ; }
getVersion ( ) { return this . version ; }
getDescription ( ) { return ` The Library Plugin needed for ${ this . name } is missing. Open the Plugin Settings to download it. \n \n ${ this . description } ` ; }
2021-05-31 14:52:40 +02:00
downloadLibrary ( ) {
2023-11-18 18:31:04 +01:00
BdApi . Net . fetch ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" ) . then ( r => {
if ( ! r || r . status != 200 ) throw new Error ( ) ;
else return r . text ( ) ;
} ) . then ( b => {
if ( ! b ) throw new Error ( ) ;
else return require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
} ) . catch ( error => {
BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library" ) ;
2021-05-31 14:52:40 +02:00
} ) ;
}
load ( ) {
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2022-09-01 14:55:22 +02:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ this . name } is missing. Please click "Download Now" to install it. ` , {
2021-05-31 14:52:40 +02:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
this . downloadLibrary ( ) ;
}
} ) ;
}
2022-09-01 14:55:22 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( this . name ) ) window . BDFDB _Global . pluginQueue . push ( this . name ) ;
2021-05-31 14:52:40 +02:00
}
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
let template = document . createElement ( "template" ) ;
2022-09-01 14:55:22 +02:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ this . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-05-31 14:52:40 +02:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
return template . content . firstElementChild ;
}
} : ( ( [ Plugin , BDFDB ] ) => {
2021-07-05 21:50:35 +02:00
var _this ;
var loadedUsers , requestedUsers , queuedInstances ;
2021-05-31 14:52:40 +02:00
2022-10-20 12:18:05 +02:00
const UserConnectionsComponents = class UserConnections extends BdApi . React . Component {
render ( ) {
2022-11-03 13:02:33 +01:00
if ( ! loadedUsers [ this . props . user . id ] && ! requestedUsers [ this . props . user . id ] ) {
requestedUsers [ this . props . user . id ] = true ;
queuedInstances [ this . props . user . id ] = [ ] . concat ( queuedInstances [ this . props . user . id ] ) . filter ( n => n ) ;
BDFDB . LibraryModules . UserProfileUtils . fetchProfile ( this . props . user . id ) ;
}
2022-10-20 12:18:05 +02:00
if ( ! loadedUsers [ this . props . user . id ] ) {
if ( queuedInstances [ this . props . user . id ] . indexOf ( this ) == - 1 ) queuedInstances [ this . props . user . id ] . push ( this ) ;
return null ;
}
2022-11-03 13:02:33 +01:00
let connections = loadedUsers [ this . props . user . id ] . filter ( c => _this . settings . connections [ c . type ] ) ;
if ( ! connections . length ) return null ;
2022-11-06 12:08:58 +01:00
let isLightTheme = ( ! this . props . theme || this . props . theme == "light" ) && BDFDB . DiscordUtils . getTheme ( ) == BDFDB . disCN . themelight ;
2024-08-16 16:41:42 +02:00
return BDFDB . ReactUtils . createElement ( "section" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . userprofilesection , BDFDB . disCN . _showconnectionsconnectionswrapper ) ,
2022-11-22 00:32:47 +01:00
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Heading , {
2024-08-16 16:41:42 +02:00
className : BDFDB . disCN . userprofilesectionheading ,
variant : "text-xs/semibold" ,
style : { color : "var(--header-secondary)" } ,
2022-11-22 00:32:47 +01:00
color : null ,
children : BDFDB . LanguageUtils . LanguageStrings . CONNECTIONS
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _showconnectionsconnections ,
children : connections . map ( c => {
let provider = BDFDB . LibraryModules . ConnectionProviderUtils . get ( c . type ) ;
let url = _this . settings . general . openWebpage && provider . getPlatformUserUrl && provider . getPlatformUserUrl ( c ) ;
2023-08-17 10:59:42 +02:00
let metadata = [ ] ;
2023-08-19 23:54:32 +02:00
if ( _this . settings . general . showDetails && provider . hasMetadata && c . metadata ) {
2023-08-17 10:59:42 +02:00
if ( c . metadata . created _at ) metadata . push ( BDFDB . ReactUtils . createElement ( "span" , { children : BDFDB . LanguageUtils . LanguageStringsFormat ( "CONNECTIONS_PROFILE_MEMBER_SINCE" , ( new Date ( c . metadata . created _at ) ) . toLocaleDateString ( "default" , { year : "numeric" , month : "long" , day : "numeric" } ) ) } ) ) ;
}
2022-11-22 00:32:47 +01:00
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : ` ${ provider . name } : ${ c . name } ` ,
2023-08-17 10:59:42 +02:00
note : metadata && metadata . length ? BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
direction : BDFDB . LibraryComponents . Flex . Direction . VERTICAL ,
children : metadata
} ) : null ,
2022-11-22 00:32:47 +01:00
tooltipConfig : { backgroundColor : _this . settings . general . useColoredTooltips && BDFDB . ColorUtils . change ( provider . color , - 0.3 ) , color : ! _this . settings . general . useColoredTooltips || ! provider . color ? "black" : null } ,
children : BDFDB . ReactUtils . createElement ( ! url ? "div" : BDFDB . LibraryComponents . Anchor , Object . assign ( ! url ? { } : {
href : url
} , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _showconnectionsconnection , url && BDFDB . disCN . cursorpointer ) ,
onContextMenu : event => {
BDFDB . ContextMenuUtils . open ( _this , event , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuGroup , {
children : [
BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : BDFDB . LanguageUtils . LibraryStringsFormat ( "copy" , BDFDB . LanguageUtils . LanguageStrings . USER _SETTINGS _LABEL _USERNAME ) ,
id : BDFDB . ContextMenuUtils . createItemId ( _this . name , "copy-name" ) ,
action : _ => BDFDB . LibraryModules . WindowUtils . copy ( c . name )
} ) ,
url && BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : BDFDB . LanguageUtils . LibraryStringsFormat ( "copy" , BDFDB . LanguageUtils . LanguageStrings . SEARCH _ANSWER _HAS _LINK ) ,
id : BDFDB . ContextMenuUtils . createItemId ( _this . name , "copy-url" ) ,
action : _ => BDFDB . LibraryModules . WindowUtils . copy ( url )
} )
]
} ) ) ;
} ,
children : [
BDFDB . ReactUtils . createElement ( "img" , {
className : BDFDB . disCN . _showconnectionsicon ,
alt : BDFDB . LanguageUtils . LanguageStringsFormat ( "IMG_ALT_LOGO" , provider . name ) ,
src : provider . icon [ _this . settings . general . useColoredIcons ? ( isLightTheme ? "lightSVG" : "darkSVG" ) : "whiteSVG" ]
} ) ,
_this . settings . general . showVerifiedBadge && c . verified && BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . CONNECTION _VERIFIED ,
tooltipConfig : { color : "brand" , type : "bottom" } ,
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FlowerStar , {
className : BDFDB . disCN . _showconnectionsverifiedbadge ,
size : "50%" ,
2023-02-22 15:34:45 +01:00
color : isLightTheme ? BDFDB . DiscordConstants . Colors . PRIMARY _200 : BDFDB . DiscordConstants . Colors . PRIMARY ,
2022-11-22 00:32:47 +01:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
name : BDFDB . LibraryComponents . SvgIcon . Names . CHECKMARK ,
width : "70%" ,
height : "70%" ,
2023-02-22 15:34:45 +01:00
color : isLightTheme ? BDFDB . DiscordConstants . Colors . PRIMARY _500 : BDFDB . DiscordConstants . Colors . WHITE
2022-11-22 00:32:47 +01:00
} )
2022-10-20 12:18:05 +02:00
} )
} )
2022-11-22 00:32:47 +01:00
]
} ) )
} ) ;
} )
2022-10-20 12:18:05 +02:00
} )
2022-11-22 00:32:47 +01:00
]
2022-11-03 13:02:33 +01:00
} ) ;
2022-10-20 12:18:05 +02:00
}
} ;
2021-05-31 14:52:40 +02:00
return class ShowConnections extends Plugin {
onLoad ( ) {
2021-07-05 21:50:35 +02:00
_this = this ;
loadedUsers = { } ;
requestedUsers = { } ;
queuedInstances = { } ;
2024-07-27 13:17:45 +02:00
this . patchPriority = 9 ;
2022-10-20 12:18:05 +02:00
this . modulePatches = {
after : [
2024-07-27 13:17:45 +02:00
"UserHeaderUsername"
2022-10-20 12:18:05 +02:00
]
2021-05-31 14:52:40 +02:00
} ;
2021-05-31 22:16:42 +02:00
this . defaults = {
general : {
2021-06-01 13:57:31 +02:00
useColoredIcons : { value : true , description : "Uses colored Version of the Icons" } ,
useColoredTooltips : { value : true , description : "Uses colored Version of the Tooltips" } ,
2023-08-17 10:59:42 +02:00
showDetails : { value : true , description : "Shows Details of Connection on hover" } ,
2021-06-01 13:57:31 +02:00
showVerifiedBadge : { value : true , description : "Shows the Badge for verified Connections" } ,
openWebpage : { value : true , description : "Opens the Connection Page when clicking the Icon" }
2021-05-31 22:16:42 +02:00
} ,
connections : { }
} ;
2021-06-01 09:34:05 +02:00
for ( let connection of BDFDB . LibraryModules . ConnectionProviderUtils . filter ( n => n ) ) this . defaults . connections [ connection . type ] = Object . assign ( { } , connection , { value : true } ) ;
2021-05-31 22:16:42 +02:00
2021-05-31 14:52:40 +02:00
this . css = `
2024-06-25 18:39:04 +02:00
$ { BDFDB . dotCN . _showconnectionsconnectionswrapper } {
order : 999 ;
}
2021-05-31 14:52:40 +02:00
$ { BDFDB . dotCN . _showconnectionsconnections } {
display : flex ;
flex - wrap : wrap ;
}
$ { BDFDB . dotCN . _showconnectionsconnection } {
position : relative ;
width : 28 px ;
height : 28 px ;
2022-09-03 16:02:56 +02:00
margin : 4 px 10 px 6 px 0 ;
2021-05-31 14:52:40 +02:00
}
$ { BDFDB . dotCN . _showconnectionsicon } {
margin : - 15 % 0 0 - 15 % ;
width : 130 % ;
height : 130 % ;
}
$ { BDFDB . dotCN . _showconnectionsverifiedbadge } {
position : absolute ;
2021-05-31 22:16:42 +02:00
bottom : - 10 % ;
right : - 10 % ;
2021-05-31 14:52:40 +02:00
}
` ;
}
onStart ( ) {
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . DispatchApiUtils , "dispatch" , { after : e => {
2022-08-01 22:55:52 +02:00
if ( BDFDB . ObjectUtils . is ( e . methodArguments [ 0 ] ) && e . methodArguments [ 0 ] . type == "USER_PROFILE_FETCH_SUCCESS" && e . methodArguments [ 0 ] . user && e . methodArguments [ 0 ] . connected _accounts ) {
2021-07-05 21:50:35 +02:00
const user = e . methodArguments [ 0 ] . user ;
delete requestedUsers [ user . id ] ;
loadedUsers [ user . id ] = e . methodArguments [ 0 ] . connected _accounts ;
BDFDB . ReactUtils . forceUpdate ( queuedInstances [ user . id ] ) ;
delete queuedInstances [ user . id ] ;
2021-05-31 14:52:40 +02:00
}
} } ) ;
}
2022-10-20 12:18:05 +02:00
onStop ( ) { }
2021-05-31 14:52:40 +02:00
2021-05-31 22:16:42 +02:00
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
collapseStates : collapseStates ,
children : _ => {
let settingsItems = [ ] ;
for ( let key in this . defaults . general ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "general" , key ] ,
label : this . defaults . general [ key ] . description ,
value : this . settings . general [ key ]
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
title : "Display Connections:" ,
children : Object . keys ( this . defaults . connections ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "connections" , key ] ,
label : this . defaults . connections [ key ] . name ,
value : this . settings . connections [ key ] ,
labelChildren : [
2021-10-18 15:28:28 +02:00
BDFDB . ReactUtils . createElement ( "img" , { style : { width : 28 , height : 28 } , src : this . defaults . connections [ key ] . icon . lightSVG } ) ,
BDFDB . ReactUtils . createElement ( "img" , { style : { width : 28 , height : 28 } , src : this . defaults . connections [ key ] . icon . whiteSVG } )
2021-05-31 22:16:42 +02:00
]
} ) )
} ) ) ;
return settingsItems ;
}
} ) ;
}
2024-07-27 13:17:45 +02:00
processUserHeaderUsername ( e ) {
2024-07-31 18:10:12 +02:00
if ( e . instance . props . profileType != "BITE_SIZE" || e . instance . props . className ) return ;
2024-06-23 19:55:46 +02:00
let user = e . instance . props . user || BDFDB . LibraryStores . UserStore . getUser ( e . instance . props . userId ) ;
if ( ! user || user . isNonUserBot ( ) ) return ;
2024-07-27 13:17:45 +02:00
e . returnvalue = [ e . returnvalue ] . flat ( 10 ) ;
e . returnvalue . push ( BDFDB . ReactUtils . createElement ( UserConnectionsComponents , {
2024-06-23 19:55:46 +02:00
user : user ,
isSimplified : true ,
theme : e . instance . props . theme
} , true ) ) ;
}
2021-05-31 14:52:40 +02:00
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-05-31 23:58:10 +02:00
} ) ( ) ;