2020-10-20 23:25:34 +02:00
/ * *
* @ name BDFDB
* @ authorId 278543574059057154
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
* @ website https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Library
* @ source https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Library/0BDFDB.plugin.js
* @ updateUrl https : //raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Library/0BDFDB.plugin.js
2020-10-20 23:25:34 +02:00
* /
2020-09-10 13:08:22 +02:00
2020-09-19 21:32:19 +02:00
module . exports = ( _ => {
2020-11-11 00:25:33 +01:00
const isBeta = ! ( window . BdApi && ! Array . isArray ( BdApi . settings ) ) ;
2020-09-19 21:32:19 +02:00
const config = {
"info" : {
"name" : "BDFDB" ,
"author" : "DevilBro" ,
2021-02-24 17:32:17 +01:00
"version" : "1.4.0" ,
2020-10-16 10:25:30 +02:00
"description" : "Give other plugins utility functions"
2020-09-19 21:32:19 +02:00
} ,
2021-01-26 21:14:48 +01:00
"rawUrl" : "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" ,
"changeLog" : {
2021-02-24 17:32:17 +01:00
"progress" : {
"New Meta Headers" : "Adjusted Update Check for new Plugin Meta Headers"
2021-01-26 21:14:48 +01:00
}
}
2020-09-19 21:32:19 +02:00
} ;
const DiscordObjects = { } ;
const LibraryRequires = { } ;
const LibraryModules = { } ;
const InternalComponents = { NativeSubComponents : { } , LibraryComponents : { } } ;
const Cache = { data : { } , modules : { } } ;
2020-09-22 23:30:15 +02:00
var libraryInstance ;
2021-01-27 18:14:10 +01:00
var settings = { } , choices = { } , changeLogs = { } ;
2020-09-19 21:32:19 +02:00
if ( window . BDFDB _Global && window . BDFDB _Global . PluginUtils && typeof window . BDFDB _Global . PluginUtils . cleanUp == "function" ) {
window . BDFDB _Global . PluginUtils . cleanUp ( window . BDFDB _Global ) ;
}
2020-10-14 19:24:48 +02:00
const BDFDB = {
2020-09-19 21:32:19 +02:00
started : true
2020-10-14 19:24:48 +02:00
} ;
for ( let key in config ) key == "info" ? Object . assign ( BDFDB , config [ key ] ) : ( BDFDB [ key ] = config [ key ] ) ;
2020-09-19 21:32:19 +02:00
const InternalBDFDB = Object . assign ( { } , BDFDB , {
patchPriority : 0 ,
defaults : {
settings : {
2021-02-04 20:51:20 +01:00
showToasts : {
value : true ,
isDisabled : data => data . nativeValue ,
hasNote : data => data . disabled && data . value
} ,
showSupportBadges : {
value : true
} ,
useChromium : {
value : false ,
isDisabled : data => ! LibraryRequires . electron || ! LibraryRequires . electron . remote ,
getValue : data => ! data . disabled
}
2021-01-27 18:14:10 +01:00
} ,
choices : {
2021-02-04 20:51:20 +01:00
toastPosition : {
value : "right" ,
items : "ToastPositions"
}
2020-09-19 21:32:19 +02:00
}
} ,
} ) ;
2021-01-27 18:14:10 +01:00
const LibraryConstants = {
ToastIcons : {
info : "INFO" ,
danger : "CLOSE_CIRCLE" ,
success : "CHECKMARK_CIRCLE" ,
warning : "WARNING"
} ,
ToastPositions : {
center : "toastscenter" ,
left : "toastsleft" ,
right : "toastsright"
}
2021-02-04 18:22:04 +01:00
} ;
2021-01-27 18:14:10 +01:00
2020-09-19 21:32:19 +02:00
const PluginStores = {
2020-10-08 17:35:36 +02:00
loaded : { } ,
2021-02-05 21:45:34 +01:00
delayed : {
loads : [ ] ,
starts : [ ]
} ,
updateData : {
plugins : { } ,
timeouts : [ ] ,
downloaded : [ ] ,
interval : null
} ,
2020-09-19 21:32:19 +02:00
patchQueues : { }
} ;
const Plugin = function ( config ) {
return class Plugin {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
getDescription ( ) { return config . info . description ; }
load ( ) {
2020-09-23 08:41:34 +02:00
this . loaded = true ;
2020-09-19 21:32:19 +02:00
if ( window . BDFDB _Global . loading ) {
2021-02-05 21:45:34 +01:00
if ( ! PluginStores . delayed . loads . includes ( this ) ) PluginStores . delayed . loads . push ( this ) ;
2020-09-19 21:32:19 +02:00
}
else {
Object . assign ( this , config . info , BDFDB . ObjectUtils . exclude ( config , "info" ) ) ;
BDFDB . TimeUtils . suppress ( _ => {
2020-10-08 17:35:36 +02:00
PluginStores . loaded [ config . info . name ] = this ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . load ( this ) ;
if ( typeof this . onLoad == "function" ) this . onLoad ( ) ;
} , "Failed to load plugin!" , config . info . name ) ( ) ;
}
}
2021-01-06 12:38:36 +01:00
start ( ) {
2020-09-23 08:41:34 +02:00
if ( ! this . loaded ) this . load ( ) ;
2020-09-19 21:32:19 +02:00
if ( window . BDFDB _Global . loading ) {
2021-02-05 21:45:34 +01:00
if ( ! PluginStores . delayed . starts . includes ( this ) ) PluginStores . delayed . starts . push ( this ) ;
2020-09-19 21:32:19 +02:00
}
else {
if ( this . started ) return ;
this . started = true ;
BDFDB . TimeUtils . suppress ( _ => {
BDFDB . PluginUtils . init ( this ) ;
if ( typeof this . onStart == "function" ) this . onStart ( ) ;
} , "Failed to start plugin!" , config . info . name ) ( ) ;
delete this . stopping ;
}
}
2021-01-06 12:38:36 +01:00
stop ( ) {
2020-09-19 21:32:19 +02:00
if ( this . stopping ) return ;
this . stopping = true ;
BDFDB . TimeUtils . timeout ( _ => { delete this . stopping ; } ) ;
BDFDB . TimeUtils . suppress ( _ => {
if ( typeof this . onStop == "function" ) this . onStop ( ) ;
BDFDB . PluginUtils . clear ( this ) ;
} , "Failed to stop plugin!" , config . info . name ) ( ) ;
delete this . started ;
}
} ;
} ;
BDFDB . LogUtils = { } ;
BDFDB . LogUtils . log = function ( string , name ) {
console . log ( ` %c[ ${ typeof name == "string" && name || "BDFDB" } ] ` , "color: #3a71c1; font-weight: 700;" , ( typeof string == "string" && string || "" ) . trim ( ) ) ;
} ;
BDFDB . LogUtils . warn = function ( string , name ) {
console . warn ( ` %c[ ${ typeof name == "string" && name || "BDFDB" } ] ` , "color: #3a71c1; font-weight: 700;" , ( typeof string == "string" && string || "" ) . trim ( ) ) ;
} ;
BDFDB . LogUtils . error = function ( string , name ) {
console . error ( ` %c[ ${ typeof name == "string" && name || "BDFDB" } ] ` , "color: #3a71c1; font-weight: 700;" , "Fatal Error: " + ( typeof string == "string" && string || "" ) . trim ( ) ) ;
} ;
BDFDB . TimeUtils = { } ;
BDFDB . TimeUtils . interval = function ( callback , delay , ... args ) {
if ( typeof callback != "function" || typeof delay != "number" || delay < 1 ) return ;
else {
let count = 0 , interval = setInterval ( _ => { BDFDB . TimeUtils . suppress ( callback , "Interval" ) ( ... [ interval , count ++ , args ] . flat ( ) ) ; } , delay ) ;
return interval ;
}
} ;
BDFDB . TimeUtils . timeout = function ( callback , delay , ... args ) {
delay = parseFloat ( delay ) ;
if ( typeof callback != "function" ) return ;
else if ( isNaN ( delay ) || typeof delay != "number" || delay < 1 ) {
let immediate = setImmediate ( _ => { BDFDB . TimeUtils . suppress ( callback , "Immediate" ) ( ... [ immediate , args ] . flat ( ) ) ; } ) ;
return immediate ;
}
else {
let timeout = setTimeout ( _ => { BDFDB . TimeUtils . suppress ( callback , "Timeout" ) ( ... [ timeout , args ] . flat ( ) ) ; } , delay ) ;
return timeout ;
}
} ;
BDFDB . TimeUtils . clear = function ( ... timeObjects ) {
for ( let t of timeObjects . flat ( 10 ) . filter ( n => n ) ) {
if ( typeof t == "number" ) {
clearInterval ( t ) ;
clearTimeout ( t ) ;
}
else if ( typeof t == "object" ) clearImmediate ( t ) ;
}
} ;
BDFDB . TimeUtils . suppress = function ( callback , string , name ) { return function ( ... args ) {
try { return callback ( ... args ) ; }
catch ( err ) { BDFDB . LogUtils . error ( ( typeof string == "string" && string || "" ) + " " + err , name ) ; }
} } ;
BDFDB . LogUtils . log ( "Loading library." ) ;
BDFDB . sameProto = function ( a , b ) {
if ( a != null && typeof a == "object" ) return a . constructor && a . constructor . prototype && typeof a . constructor . prototype . isPrototypeOf == "function" && a . constructor . prototype . isPrototypeOf ( b ) ;
else return typeof a == typeof b ;
} ;
BDFDB . equals = function ( mainA , mainB , sorted ) {
let i = - 1 ;
if ( sorted === undefined || typeof sorted !== "boolean" ) sorted = false ;
return equal ( mainA , mainB ) ;
function equal ( a , b ) {
i ++ ;
let result = true ;
if ( i > 1000 ) result = null ;
else {
if ( typeof a !== typeof b ) result = false ;
2021-02-09 13:05:30 +01:00
else if ( typeof a == "function" ) result = a . toString ( ) == b . toString ( ) ;
2020-09-19 21:32:19 +02:00
else if ( typeof a === "undefined" ) result = true ;
else if ( typeof a === "symbol" ) result = true ;
else if ( typeof a === "boolean" ) result = a == b ;
else if ( typeof a === "string" ) result = a == b ;
else if ( typeof a === "number" ) {
if ( isNaN ( a ) || isNaN ( b ) ) result = isNaN ( a ) == isNaN ( b ) ;
else result = a == b ;
}
else if ( ! a && ! b ) result = true ;
else if ( ! a || ! b ) result = false ;
else if ( typeof a === "object" ) {
let keysA = Object . getOwnPropertyNames ( a ) ;
let keysB = Object . getOwnPropertyNames ( b ) ;
if ( keysA . length !== keysB . length ) result = false ;
else for ( let j = 0 ; result === true && j < keysA . length ; j ++ ) {
if ( sorted ) result = equal ( a [ keysA [ j ] ] , b [ keysB [ j ] ] ) ;
else result = equal ( a [ keysA [ j ] ] , b [ keysA [ j ] ] ) ;
}
}
}
i -- ;
return result ;
}
} ;
BDFDB . ObjectUtils = { } ;
BDFDB . ObjectUtils . is = function ( obj ) {
2021-01-28 17:47:49 +01:00
return obj && ! Array . isArray ( obj ) && ! Set . prototype . isPrototypeOf ( obj ) && ( typeof obj == "function" || typeof obj == "object" ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . ObjectUtils . get = function ( nodeOrObj , valuePath ) {
if ( ! nodeOrObj || ! valuePath ) return null ;
let obj = Node . prototype . isPrototypeOf ( nodeOrObj ) ? BDFDB . ReactUtils . getInstance ( nodeOrObj ) : nodeOrObj ;
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return null ;
let found = obj , values = valuePath . split ( "." ) . filter ( n => n ) ;
for ( value of values ) {
if ( ! found ) return null ;
found = found [ value ] ;
}
return found ;
} ;
BDFDB . ObjectUtils . extract = function ( obj , ... keys ) {
let newObj = { } ;
if ( BDFDB . ObjectUtils . is ( obj ) ) for ( let key of keys . flat ( 10 ) . filter ( n => n ) ) if ( obj [ key ] ) newObj [ key ] = obj [ key ] ;
return newObj ;
} ;
BDFDB . ObjectUtils . exclude = function ( obj , ... keys ) {
let newObj = Object . assign ( { } , obj ) ;
BDFDB . ObjectUtils . delete ( newObj , ... keys )
return newObj ;
} ;
BDFDB . ObjectUtils . delete = function ( obj , ... keys ) {
if ( BDFDB . ObjectUtils . is ( obj ) ) for ( let key of keys . flat ( 10 ) . filter ( n => n ) ) delete obj [ key ] ;
} ;
BDFDB . ObjectUtils . sort = function ( obj , sort , except ) {
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return { } ;
let newObj = { } ;
if ( sort === undefined || ! sort ) for ( let key of Object . keys ( obj ) . sort ( ) ) newObj [ key ] = obj [ key ] ;
else {
let values = [ ] ;
for ( let key in obj ) values . push ( obj [ key ] ) ;
values = BDFDB . ArrayUtils . keySort ( values , sort , except ) ;
for ( let value of values ) for ( let key in obj ) if ( BDFDB . equals ( value , obj [ key ] ) ) {
newObj [ key ] = value ;
break ;
}
}
return newObj ;
} ;
BDFDB . ObjectUtils . reverse = function ( obj , sort ) {
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return { } ;
let newObj = { } ;
for ( let key of ( sort === undefined || ! sort ) ? Object . keys ( obj ) . reverse ( ) : Object . keys ( obj ) . sort ( ) . reverse ( ) ) newObj [ key ] = obj [ key ] ;
return newObj ;
} ;
BDFDB . ObjectUtils . filter = function ( obj , filter , byKey = false ) {
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return { } ;
if ( typeof filter != "function" ) return obj ;
return Object . keys ( obj ) . filter ( key => filter ( byKey ? key : obj [ key ] ) ) . reduce ( ( newObj , key ) => ( newObj [ key ] = obj [ key ] , newObj ) , { } ) ;
} ;
BDFDB . ObjectUtils . push = function ( obj , value ) {
if ( BDFDB . ObjectUtils . is ( obj ) ) obj [ Object . keys ( obj ) . length ] = value ;
} ;
BDFDB . ObjectUtils . pop = function ( obj , value ) {
if ( BDFDB . ObjectUtils . is ( obj ) ) {
let keys = Object . keys ( obj ) ;
if ( ! keys . length ) return ;
let value = obj [ keys [ keys . length - 1 ] ] ;
delete obj [ keys [ keys . length - 1 ] ] ;
return value ;
}
} ;
2021-01-02 12:51:18 +01:00
BDFDB . ObjectUtils . map = function ( obj , mapFunc ) {
2020-09-19 21:32:19 +02:00
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return { } ;
2021-01-02 12:51:18 +01:00
if ( typeof mapFunc != "string" && typeof mapFunc != "function" ) return obj ;
2020-09-19 21:32:19 +02:00
let newObj = { } ;
2021-01-02 12:51:18 +01:00
for ( let key in obj ) if ( BDFDB . ObjectUtils . is ( obj [ key ] ) ) newObj [ key ] = typeof mapFunc == "string" ? obj [ key ] [ mapFunc ] : mapFunc ( obj [ key ] , key ) ;
2020-09-19 21:32:19 +02:00
return newObj ;
} ;
BDFDB . ObjectUtils . toArray = function ( obj ) {
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return [ ] ;
return Object . entries ( obj ) . map ( n => n [ 1 ] ) ;
} ;
BDFDB . ObjectUtils . deepAssign = function ( obj , ... objs ) {
if ( ! objs . length ) return obj ;
let nextObj = objs . shift ( ) ;
if ( BDFDB . ObjectUtils . is ( obj ) && BDFDB . ObjectUtils . is ( nextObj ) ) {
for ( let key in nextObj ) {
if ( BDFDB . ObjectUtils . is ( nextObj [ key ] ) ) {
if ( ! obj [ key ] ) Object . assign ( obj , { [ key ] : { } } ) ;
BDFDB . ObjectUtils . deepAssign ( obj [ key ] , nextObj [ key ] ) ;
}
else Object . assign ( obj , { [ key ] : nextObj [ key ] } ) ;
}
}
return BDFDB . ObjectUtils . deepAssign ( obj , ... objs ) ;
} ;
BDFDB . ObjectUtils . isEmpty = function ( obj ) {
return ! BDFDB . ObjectUtils . is ( obj ) || Object . getOwnPropertyNames ( obj ) . length == 0 ;
} ;
2021-01-29 11:39:02 +01:00
BDFDB . ObjectUtils . mirror = function ( obj ) {
if ( ! BDFDB . ObjectUtils . is ( obj ) ) return { } ;
let newObj = Object . assign ( { } , obj ) ;
2021-01-29 11:41:27 +01:00
for ( let key in newObj ) if ( newObj [ newObj [ key ] ] == undefined && ( typeof key == "number" || typeof key == "string" ) ) newObj [ newObj [ key ] ] = key ;
2021-01-29 11:39:02 +01:00
return newObj ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . ArrayUtils = { } ;
BDFDB . ArrayUtils . is = function ( array ) {
return array && Array . isArray ( array ) ;
} ;
BDFDB . ArrayUtils . sum = function ( array ) {
return Array . isArray ( array ) ? array . reduce ( ( total , num ) => total + Math . round ( num ) , 0 ) : 0 ;
} ;
BDFDB . ArrayUtils . keySort = function ( array , key , except ) {
if ( ! BDFDB . ArrayUtils . is ( array ) ) return [ ] ;
if ( key == null ) return array ;
if ( except === undefined ) except = null ;
return array . sort ( ( x , y ) => {
let xValue = x [ key ] , yValue = y [ key ] ;
if ( xValue !== except ) return xValue < yValue ? - 1 : xValue > yValue ? 1 : 0 ;
} ) ;
} ;
BDFDB . ArrayUtils . numSort = function ( array ) {
return array . sort ( ( x , y ) => ( x < y ? - 1 : x > y ? 1 : 0 ) ) ;
} ;
BDFDB . ArrayUtils . includes = function ( array , ... values ) {
if ( ! BDFDB . ArrayUtils . is ( array ) ) return null ;
if ( ! array . length ) return false ;
let all = values . pop ( ) ;
if ( typeof all != "boolean" ) {
values . push ( all ) ;
all = true ;
}
if ( ! values . length ) return false ;
let contained = undefined ;
for ( let v of values ) {
if ( contained === undefined ) contained = all ;
if ( all && ! array . includes ( v ) ) contained = false ;
if ( ! all && array . includes ( v ) ) contained = true ;
}
return contained ;
} ;
BDFDB . ArrayUtils . remove = function ( array , value , all = false ) {
if ( ! BDFDB . ArrayUtils . is ( array ) ) return [ ] ;
if ( ! array . includes ( value ) ) return array ;
if ( ! all ) array . splice ( array . indexOf ( value ) , 1 ) ;
else while ( array . indexOf ( value ) > - 1 ) array . splice ( array . indexOf ( value ) , 1 ) ;
return array ;
} ;
BDFDB . ArrayUtils . getAllIndexes = function ( array , value ) {
if ( ! BDFDB . ArrayUtils . is ( array ) && typeof array != "string" ) return [ ] ;
var indexes = [ ] , index = - 1 ;
while ( ( index = array . indexOf ( value , index + 1 ) ) !== - 1 ) indexes . push ( index ) ;
return indexes ;
} ;
BDFDB . ArrayUtils . removeCopies = function ( array ) {
if ( ! BDFDB . ArrayUtils . is ( array ) ) return [ ] ;
return [ ... new Set ( array ) ] ;
} ;
BDFDB . BDUtils = { } ;
BDFDB . BDUtils . getPluginsFolder = function ( ) {
if ( window . BdApi && BdApi . Plugins . folder && typeof BdApi . Plugins . folder == "string" ) return BdApi . Plugins . folder ;
else if ( LibraryRequires . process . env . injDir ) return LibraryRequires . path . resolve ( LibraryRequires . process . env . injDir , "plugins/" ) ;
else switch ( LibraryRequires . process . platform ) {
case "win32" :
return LibraryRequires . path . resolve ( LibraryRequires . process . env . appdata , "BetterDiscord/plugins/" ) ;
case "darwin" :
return LibraryRequires . path . resolve ( LibraryRequires . process . env . HOME , "Library/Preferences/BetterDiscord/plugins/" ) ;
default :
if ( LibraryRequires . process . env . XDG _CONFIG _HOME ) return LibraryRequires . path . resolve ( LibraryRequires . process . env . XDG _CONFIG _HOME , "BetterDiscord/plugins/" ) ;
else return LibraryRequires . path . resolve ( LibraryRequires . process . env . HOME , ".config/BetterDiscord/plugins/" ) ;
}
} ;
BDFDB . BDUtils . getThemesFolder = function ( ) {
if ( window . BdApi && BdApi . Themes . folder && typeof BdApi . Themes . folder == "string" ) return BdApi . Themes . folder ;
else if ( LibraryRequires . process . env . injDir ) return LibraryRequires . path . resolve ( LibraryRequires . process . env . injDir , "plugins/" ) ;
else switch ( LibraryRequires . process . platform ) {
case "win32" :
return LibraryRequires . path . resolve ( LibraryRequires . process . env . appdata , "BetterDiscord/themes/" ) ;
case "darwin" :
return LibraryRequires . path . resolve ( LibraryRequires . process . env . HOME , "Library/Preferences/BetterDiscord/themes/" ) ;
default :
if ( LibraryRequires . process . env . XDG _CONFIG _HOME ) return LibraryRequires . path . resolve ( LibraryRequires . process . env . XDG _CONFIG _HOME , "BetterDiscord/themes/" ) ;
else return LibraryRequires . path . resolve ( LibraryRequires . process . env . HOME , ".config/BetterDiscord/themes/" ) ;
}
} ;
BDFDB . BDUtils . isPluginEnabled = function ( pluginName ) {
if ( ! window . BdApi ) return null ;
else if ( BdApi . Plugins && typeof BdApi . Plugins . isEnabled == "function" ) return BdApi . Plugins . isEnabled ( pluginName ) ;
else if ( typeof BdApi . isPluginEnabled == "function" ) return BdApi . isPluginEnabled ( pluginName ) ;
} ;
BDFDB . BDUtils . reloadPlugin = function ( pluginName ) {
if ( ! window . BdApi ) return ;
else if ( BdApi . Plugins && typeof BdApi . Plugins . reload == "function" ) BdApi . Plugins . reload ( pluginName ) ;
else if ( window . pluginModule ) window . pluginModule . reloadPlugin ( pluginName ) ;
} ;
BDFDB . BDUtils . enablePlugin = function ( pluginName ) {
if ( ! window . BdApi ) return ;
else if ( BdApi . Plugins && typeof BdApi . Plugins . enable == "function" ) BdApi . Plugins . enable ( pluginName ) ;
else if ( window . pluginModule ) window . pluginModule . startPlugin ( pluginName ) ;
} ;
BDFDB . BDUtils . disablePlugin = function ( pluginName ) {
if ( ! window . BdApi ) return ;
else if ( BdApi . Plugins && typeof BdApi . Plugins . disable == "function" ) BdApi . Plugins . disable ( pluginName ) ;
else if ( window . pluginModule ) window . pluginModule . stopPlugin ( pluginName ) ;
} ;
BDFDB . BDUtils . getPlugin = function ( pluginName , hasToBeEnabled = false , overHead = false ) {
if ( window . BdApi && ! hasToBeEnabled || BDFDB . BDUtils . isPluginEnabled ( pluginName ) ) {
if ( BdApi . Plugins . get && typeof BdApi . Plugins . get == "function" ) {
let plugin = BdApi . Plugins . get ( pluginName ) ;
if ( overHead ) return plugin ? { filename : LibraryRequires . fs . existsSync ( LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , ` ${ pluginName } .plugin.js ` ) ) ? ` ${ pluginName } .plugin.js ` : null , id : pluginName , name : pluginName , plugin : plugin } : null ;
else return plugin ;
}
else if ( window . bdplugins ) overHead ? window . bdplugins [ pluginName ] : ( window . bdplugins [ pluginName ] || { } ) . plugin ;
}
return null ;
} ;
BDFDB . BDUtils . isThemeEnabled = function ( themeName ) {
if ( ! window . BdApi ) return null ;
else if ( BdApi . Themes && typeof BdApi . Themes . isEnabled == "function" ) return BdApi . Themes . isEnabled ( themeName ) ;
else if ( typeof BdApi . isThemeEnabled == "function" ) return BdApi . isThemeEnabled ( themeName ) ;
} ;
BDFDB . BDUtils . enableTheme = function ( themeName ) {
if ( ! window . BdApi ) return ;
else if ( BdApi . Themes && typeof BdApi . Themes . enable == "function" ) BdApi . Themes . enable ( themeName ) ;
else if ( window . themeModule ) window . themeModule . enableTheme ( themeName ) ;
} ;
BDFDB . BDUtils . disableTheme = function ( themeName ) {
if ( ! window . BdApi ) return ;
else if ( BdApi . Themes && typeof BdApi . Themes . disable == "function" ) BdApi . Themes . disable ( themeName ) ;
else if ( window . themeModule ) window . themeModule . disableTheme ( themeName ) ;
} ;
BDFDB . BDUtils . getTheme = function ( themeName , hasToBeEnabled = false ) {
if ( window . BdApi && ! hasToBeEnabled || BDFDB . BDUtils . isThemeEnabled ( themeName ) ) {
if ( BdApi . Themes && typeof BdApi . Themes . get == "function" ) return BdApi . Themes . get ( themeName ) ;
else if ( window . bdthemes ) window . bdthemes [ themeName ] ;
}
return null ;
} ;
2020-11-11 00:25:33 +01:00
BDFDB . BDUtils . settingsIds = ! isBeta ? {
2020-09-19 21:32:19 +02:00
automaticLoading : "fork-ps-5" ,
coloredText : "bda-gs-7" ,
normalizedClasses : "fork-ps-4" ,
showToasts : "fork-ps-2"
} : {
2020-09-17 08:16:37 +02:00
automaticLoading : "settings.addons.autoReload" ,
coloredText : "settings.appearance.coloredText" ,
normalizedClasses : "settings.general.classNormalizer" ,
showToasts : "settings.general.showToasts"
} ;
BDFDB . BDUtils . toggleSettings = function ( key , state ) {
if ( window . BdApi && typeof key == "string" ) {
let path = key . split ( "." ) ;
let currentState = BDFDB . BDUtils . getSettings ( key ) ;
if ( state === true ) {
if ( currentState === false ) BdApi . enableSetting ( ... path ) ;
}
else if ( state === false ) {
if ( currentState === true ) BdApi . disableSetting ( ... path ) ;
}
else if ( currentState === true || currentState === false ) BDFDB . BDUtils . toggleSettings ( key , ! currentState ) ;
}
} ;
BDFDB . BDUtils . getSettings = function ( key ) {
if ( ! window . BdApi ) return { } ;
if ( typeof key == "string" ) return BdApi . isSettingEnabled ( ... key . split ( "." ) ) ;
2021-02-03 13:00:57 +01:00
else return ! isBeta && typeof BdApi . getBDData == "function" ? BDFDB . ObjectUtils . get ( BdApi . getBDData ( "settings" ) , ` ${ BDFDB . DiscordUtils . getBuild ( ) } .settings ` ) : ( BDFDB . ArrayUtils . is ( BdApi . settings ) ? BdApi . settings . map ( n => n . settings . map ( m => m . settings . map ( l => ( { id : [ n . id , m . id , l . id ] . join ( "." ) , value : l . value } ) ) ) ) . flat ( 10 ) . reduce ( ( newObj , setting ) => ( newObj [ setting . id ] = setting . value , newObj ) , { } ) : { } ) ;
2020-09-19 21:32:19 +02:00
} ;
2020-12-24 11:46:03 +01:00
BDFDB . BDUtils . getSettingsProperty = function ( property , key ) {
2020-12-24 11:56:49 +01:00
if ( ! window . BdApi || ! isBeta ) return key ? "" : { } ;
2020-12-24 11:46:03 +01:00
else {
let settingsMap = BdApi . settings . map ( n => n . settings . map ( m => m . settings . map ( l => ( { id : [ n . id , m . id , l . id ] . join ( "." ) , value : l [ property ] } ) ) ) ) . flat ( 10 ) . reduce ( ( newObj , setting ) => ( newObj [ setting . id ] = setting . value , newObj ) , { } ) ;
return key ? ( settingsMap [ key ] != null ? settingsMap [ key ] : "" ) : "" ;
}
} ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils = { } ;
BDFDB . PluginUtils . buildPlugin = function ( config ) {
return [ Plugin ( config ) , BDFDB ] ;
} ;
BDFDB . PluginUtils . load = function ( plugin ) {
2021-02-05 21:45:34 +01:00
if ( ! PluginStores . updateData . timeouts . includes ( plugin . name ) ) {
PluginStores . updateData . timeouts . push ( plugin . name ) ;
2021-02-04 18:22:04 +01:00
let url = InternalBDFDB . getPluginURL ( plugin ) ;
2020-09-19 21:32:19 +02:00
2021-02-05 21:45:34 +01:00
PluginStores . updateData . plugins [ url ] = { name : plugin . name , raw : url , version : plugin . version } ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . checkUpdate ( plugin . name , url ) ;
2021-02-05 21:45:34 +01:00
if ( ! PluginStores . updateData . interval ) PluginStores . updateData . interval = BDFDB . TimeUtils . interval ( _ => {
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . checkAllUpdates ( ) ;
2021-02-06 17:30:26 +01:00
} , 1000 * 60 * 60 * 4 ) ;
2020-09-19 21:32:19 +02:00
2021-02-05 21:45:34 +01:00
BDFDB . TimeUtils . timeout ( _ => { BDFDB . ArrayUtils . remove ( PluginStores . updateData . timeouts , plugin . name , true ) ; } , 30000 ) ;
2020-09-19 21:32:19 +02:00
}
} ;
BDFDB . PluginUtils . init = function ( plugin ) {
BDFDB . PluginUtils . load ( plugin ) ;
let startMsg = BDFDB . LanguageUtils . LibraryStringsFormat ( "toast_plugin_started" , "v" + plugin . version ) ;
BDFDB . LogUtils . log ( startMsg , plugin . name ) ;
2020-12-24 11:46:03 +01:00
if ( settings . showToasts && ! BDFDB . BDUtils . getSettings ( BDFDB . BDUtils . settingsIds . showToasts ) ) BDFDB . NotificationUtils . toast ( ` ${ plugin . name } ${ startMsg } ` , {
2021-01-27 18:14:10 +01:00
disableInteractions : true ,
barColor : BDFDB . DiscordConstants . Colors . STATUS _GREEN
2020-12-24 11:46:03 +01:00
} ) ;
2020-09-19 21:32:19 +02:00
if ( plugin . css ) BDFDB . DOMUtils . appendLocalStyle ( plugin . name , plugin . css ) ;
InternalBDFDB . patchPlugin ( plugin ) ;
InternalBDFDB . addSpecialListeners ( plugin ) ;
BDFDB . PluginUtils . translate ( plugin ) ;
BDFDB . PluginUtils . checkChangeLog ( plugin ) ;
} ;
BDFDB . PluginUtils . clear = function ( plugin ) {
let stopMsg = BDFDB . LanguageUtils . LibraryStringsFormat ( "toast_plugin_stopped" , "v" + plugin . version ) ;
BDFDB . LogUtils . log ( stopMsg , plugin . name ) ;
2020-12-24 11:46:03 +01:00
if ( settings . showToasts && ! BDFDB . BDUtils . getSettings ( BDFDB . BDUtils . settingsIds . showToasts ) ) BDFDB . NotificationUtils . toast ( ` ${ plugin . name } ${ stopMsg } ` , {
2021-01-27 18:14:10 +01:00
disableInteractions : true ,
barColor : BDFDB . DiscordConstants . Colors . STATUS _RED
2020-12-24 11:46:03 +01:00
} ) ;
2020-09-19 21:32:19 +02:00
2020-11-19 16:45:36 +01:00
let url = plugin . rawUrl || ` https://mwittrien.github.io/BetterDiscordAddons/Plugins/ ${ plugin . name } / ${ plugin . name } .plugin.js ` ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . cleanUp ( plugin ) ;
for ( let type in PluginStores . patchQueues ) BDFDB . ArrayUtils . remove ( PluginStores . patchQueues [ type ] . query , plugin , true ) ;
for ( let modal of document . querySelectorAll ( ` . ${ plugin . name } -modal, . ${ plugin . name . toLowerCase ( ) } -modal, . ${ plugin . name } -settingsmodal, . ${ plugin . name . toLowerCase ( ) } -settingsmodal ` ) ) {
let closeButton = modal . querySelector ( BDFDB . dotCN . modalclose ) ;
if ( closeButton ) closeButton . click ( ) ;
}
delete Cache . data [ plugin . name ]
2021-02-05 21:45:34 +01:00
delete PluginStores . updateData . plugins [ url ] ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . PluginUtils . translate = function ( plugin ) {
plugin . labels = { } ;
2021-02-09 13:05:30 +01:00
if ( typeof plugin . setLabelsByLanguage == "function" || typeof plugin . changeLanguageStrings == "function" ) {
2020-09-19 21:32:19 +02:00
if ( LibraryModules . LanguageStore . chosenLocale ) translate ( ) ;
else BDFDB . TimeUtils . interval ( interval => {
if ( LibraryModules . LanguageStore . chosenLocale ) {
BDFDB . TimeUtils . clear ( interval ) ;
translate ( ) ;
}
} , 100 ) ;
function translate ( ) {
let language = BDFDB . LanguageUtils . getLanguage ( ) ;
2021-02-09 13:05:30 +01:00
if ( typeof plugin . setLabelsByLanguage == "function" ) plugin . labels = plugin . setLabelsByLanguage ( language . id ) ;
if ( typeof plugin . changeLanguageStrings == "function" ) plugin . changeLanguageStrings ( ) ;
2020-09-19 21:32:19 +02:00
}
}
} ;
BDFDB . PluginUtils . cleanUp = function ( plugin ) {
BDFDB . TimeUtils . suppress ( _ => {
if ( ! BDFDB . ObjectUtils . is ( plugin ) ) return ;
2021-01-10 11:41:01 +01:00
if ( plugin == window . BDFDB _Global ) {
2021-02-07 22:30:09 +01:00
let updateNotice = document . querySelector ( BDFDB . dotCN . noticeupdate ) ;
if ( updateNotice ) updateNotice . close ( ) ;
2021-02-05 21:45:34 +01:00
BDFDB . TimeUtils . clear ( PluginStores . updateData . interval ) ;
2020-09-19 21:32:19 +02:00
delete window . BDFDB _Global . loaded ;
BDFDB . TimeUtils . interval ( ( interval , count ) => {
if ( count > 60 || window . BDFDB _Global . loaded ) BDFDB . TimeUtils . clear ( interval ) ;
2021-01-10 11:41:01 +01:00
if ( window . BDFDB _Global . loaded ) for ( let pluginName in BDFDB . ObjectUtils . sort ( PluginStores . loaded ) ) BDFDB . TimeUtils . timeout ( _ => {
2020-10-08 17:35:36 +02:00
if ( PluginStores . loaded [ pluginName ] . started ) BDFDB . BDUtils . reloadPlugin ( pluginName ) ;
} ) ;
2020-09-19 21:32:19 +02:00
} , 1000 ) ;
}
2020-10-23 19:07:35 +02:00
if ( BDFDB . DOMUtils ) BDFDB . DOMUtils . removeLocalStyle ( plugin . name ) ;
if ( BDFDB . ListenerUtils ) BDFDB . ListenerUtils . remove ( plugin ) ;
if ( BDFDB . StoreChangeUtils ) BDFDB . StoreChangeUtils . remove ( plugin ) ;
if ( BDFDB . ObserverUtils ) BDFDB . ObserverUtils . disconnect ( plugin ) ;
if ( BDFDB . PatchUtils ) BDFDB . PatchUtils . unpatch ( plugin ) ;
if ( BDFDB . WindowUtils ) {
BDFDB . WindowUtils . closeAll ( plugin ) ;
BDFDB . WindowUtils . removeListener ( plugin ) ;
}
2020-09-19 21:32:19 +02:00
} , "Failed to clean up plugin!" , plugin . name ) ( ) ;
} ;
BDFDB . PluginUtils . checkUpdate = function ( pluginName , url ) {
2021-02-06 20:29:22 +01:00
if ( pluginName && url && PluginStores . updateData . plugins [ url ] ) return new Promise ( callback => {
2020-09-19 21:32:19 +02:00
LibraryRequires . request ( url , ( error , response , body ) => {
2021-02-06 20:29:22 +01:00
if ( error || ! PluginStores . updateData . plugins [ url ] ) return callback ( null ) ;
2020-09-19 21:32:19 +02:00
let newName = ( body . match ( /"name"\s*:\s*"([^"]+)"/ ) || [ ] ) [ 1 ] || pluginName ;
2021-02-24 17:32:17 +01:00
let newVersion = ( body . match ( /@version ([0-9]+\.[0-9]+\.[0-9]+)|['"]([0-9]+\.[0-9]+\.[0-9]+)['"]/i ) || [ ] ) . filter ( n => n ) [ 1 ] ;
2020-09-19 21:32:19 +02:00
if ( ! newVersion ) return callback ( null ) ;
2021-02-06 20:29:22 +01:00
if ( pluginName == newName && BDFDB . NumberUtils . getVersionDifference ( newVersion , PluginStores . updateData . plugins [ url ] . version ) > 0.2 ) {
2020-12-24 11:46:03 +01:00
BDFDB . NotificationUtils . toast ( BDFDB . LanguageUtils . LibraryStringsFormat ( "toast_plugin_force_updated" , pluginName ) , {
2021-01-24 12:57:02 +01:00
type : "warning" ,
2021-01-25 14:10:20 +01:00
disableInteractions : true
2020-09-19 21:32:19 +02:00
} ) ;
BDFDB . PluginUtils . downloadUpdate ( pluginName , url ) ;
return callback ( 2 ) ;
}
2021-02-06 20:29:22 +01:00
else if ( BDFDB . NumberUtils . compareVersions ( newVersion , PluginStores . updateData . plugins [ url ] . version ) ) {
2021-02-05 21:45:34 +01:00
if ( PluginStores . updateData . plugins [ url ] ) PluginStores . updateData . plugins [ url ] . outdated = true ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . showUpdateNotice ( pluginName , url ) ;
return callback ( 1 ) ;
}
else {
BDFDB . PluginUtils . removeUpdateNotice ( pluginName ) ;
return callback ( 0 ) ;
}
} ) ;
} ) ;
return new Promise ( callback => { callback ( null ) ; } ) ;
} ;
2021-02-06 20:29:22 +01:00
BDFDB . PluginUtils . checkAllUpdates = function ( ) {
2020-09-19 21:32:19 +02:00
return new Promise ( callback => {
let finished = 0 , amount = 0 ;
2021-02-06 20:29:22 +01:00
for ( let url in PluginStores . updateData . plugins ) {
let plugin = PluginStores . updateData . plugins [ url ] ;
2020-09-19 21:32:19 +02:00
if ( plugin ) BDFDB . PluginUtils . checkUpdate ( plugin . name , plugin . raw ) . then ( state => {
finished ++ ;
if ( state == 1 ) amount ++ ;
2021-02-06 20:29:22 +01:00
if ( finished >= Object . keys ( PluginStores . updateData . plugins ) . length ) callback ( amount ) ;
2020-09-19 21:32:19 +02:00
} ) ;
}
} ) ;
} ;
2021-02-05 21:45:34 +01:00
BDFDB . PluginUtils . hasUpdateCheck = function ( url ) {
2021-02-12 10:08:36 +01:00
if ( ! url || typeof url != "string" ) return false ;
2021-02-05 21:45:34 +01:00
let updateStore = Object . assign ( { } , window . PluginUpdates && window . PluginUpdates . plugins , PluginStores . updateData . plugins ) ;
if ( updateStore [ url ] ) return true ;
else {
2021-02-12 10:08:36 +01:00
let temp = url . replace ( "//raw.githubusercontent.com" , "//" ) . split ( "/" ) ;
2021-02-05 21:45:34 +01:00
let gitName = temp . splice ( 3 , 1 ) ;
temp . splice ( 4 , 1 ) ;
temp . splice ( 2 , 1 , gitName + ".github.io" ) ;
let pagesUrl = temp . join ( "/" ) ;
2021-02-12 10:08:36 +01:00
return ! ! updateStore [ pagesUrl ] ;
2021-02-05 21:45:34 +01:00
}
} ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . showUpdateNotice = function ( pluginName , url ) {
if ( ! pluginName || ! url ) return ;
2021-02-05 21:45:34 +01:00
let updateNotice = document . querySelector ( BDFDB . dotCN . noticeupdate ) ;
2020-09-19 21:32:19 +02:00
if ( ! updateNotice ) {
2020-10-31 11:43:29 +01:00
let vanishObserver = new MutationObserver ( changes => {
if ( ! document . contains ( updateNotice ) ) {
2021-02-05 21:45:34 +01:00
if ( updateNotice . querySelector ( BDFDB . dotCN . noticeupdateentry ) ) {
2020-10-31 11:43:29 +01:00
let layers = document . querySelector ( BDFDB . dotCN . layers ) || document . querySelector ( BDFDB . dotCN . appmount ) ;
if ( layers ) layers . parentElement . insertBefore ( updateNotice , layers ) ;
}
else vanishObserver . disconnect ( ) ;
}
2021-02-05 21:45:34 +01:00
else if ( document . contains ( updateNotice ) && ! updateNotice . querySelector ( BDFDB . dotCNC . noticeupdateentry + BDFDB . dotCN . noticebutton ) ) vanishObserver . disconnect ( ) ;
2020-10-31 11:43:29 +01:00
} ) ;
2020-11-19 16:51:14 +01:00
vanishObserver . observe ( document . body , { childList : true , subtree : true } ) ;
2021-02-05 21:45:34 +01:00
updateNotice = BDFDB . NotificationUtils . notice ( ` ${ BDFDB . LanguageUtils . LibraryStrings . update _notice _update } <div class=" ${ BDFDB . disCN . noticeupdateentries } "></div> ` , {
2020-11-19 16:51:14 +01:00
type : "info" ,
2021-02-05 21:45:34 +01:00
className : BDFDB . disCN . noticeupdate ,
2020-11-19 16:51:14 +01:00
html : true ,
2021-01-12 19:09:01 +01:00
forceStyle : true ,
2021-02-05 21:45:34 +01:00
customIcon : ` <svg width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M 15.46875 0.859375 C 15.772992 1.030675 16.059675 1.2229406 16.326172 1.4316406 C 17.134815 2.0640406 17.768634 2.8677594 18.208984 3.8183594 C 18.665347 4.8050594 18.913286 5.9512625 18.945312 7.2265625 L 18.945312 7.2421875 L 18.945312 7.2597656 L 18.945312 16.753906 L 18.945312 16.769531 L 18.945312 16.785156 C 18.914433 18.060356 18.666491 19.206759 18.208984 20.193359 C 17.768634 21.144059 17.135961 21.947578 16.326172 22.580078 C 16.06768 22.782278 15.790044 22.967366 15.496094 23.134766 L 16.326172 23.134766 C 20.285895 23.158766 24 20.930212 24 15.820312 L 24 8.3535156 C 24.021728 3.1431156 20.305428 0.86132812 16.345703 0.86132812 L 15.46875 0.859375 z M 0 0.8671875 L 0 10.064453 L 4.4492188 15.191406 L 4.4492188 5.4394531 L 8.4394531 5.4394531 C 11.753741 5.4394531 11.753741 9.8828125 8.4394531 9.8828125 L 7.0234375 9.8828125 L 7.0234375 14.126953 L 8.4394531 14.126953 C 11.753741 14.126953 11.753741 18.568359 8.4394531 18.568359 L 0 18.568359 L 0 23.138672 L 8.3457031 23.138672 C 12.647637 23.138672 15.987145 21.3021 16.105469 16.75 C 16.105469 14.6555 15.567688 13.090453 14.621094 12.001953 C 15.567688 10.914853 16.105469 9.3502594 16.105469 7.2558594 C 15.988351 2.7036594 12.648845 0.8671875 8.3457031 0.8671875 L 0 0.8671875 z"/></svg> ` ,
2021-02-03 11:20:50 +01:00
buttons : ! BDFDB . BDUtils . getSettings ( BDFDB . BDUtils . settingsIds . automaticLoading ) && [ {
2021-02-05 21:45:34 +01:00
className : BDFDB . disCN . noticeupdatebuttonreload ,
2021-02-03 11:20:50 +01:00
contents : BDFDB . LanguageUtils . LanguageStrings . ERRORS _RELOAD ,
2021-02-05 21:45:34 +01:00
onClick : _ => location . reload ( ) ,
onMouseEnter : _ => {
if ( PluginStores . updateData . downloaded ) BDFDB . TooltipUtils . create ( reloadButton , PluginStores . updateData . downloaded . join ( ", " ) , {
type : "bottom" ,
style : "max-width: 420px"
} ) ;
}
} ] ,
buttons : [ {
className : BDFDB . disCN . noticeupdatebuttonall ,
contents : BDFDB . LanguageUtils . LanguageStrings . FORM _LABEL _ALL ,
onClick : _ => { for ( let notice of updateNotice . querySelectorAll ( BDFDB . dotCN . noticeupdateentry ) ) notice . click ( ) ; }
2021-02-03 11:20:50 +01:00
} ] ,
2020-10-31 11:43:29 +01:00
onClose : _ => { vanishObserver . disconnect ( ) ; }
} ) ;
2020-09-19 21:32:19 +02:00
updateNotice . style . setProperty ( "z-index" , "100000" , "important" ) ;
updateNotice . style . setProperty ( "display" , "block" , "important" ) ;
2021-01-12 19:09:01 +01:00
updateNotice . style . setProperty ( "position" , "relative" , "important" ) ;
2020-09-19 21:32:19 +02:00
updateNotice . style . setProperty ( "visibility" , "visible" , "important" ) ;
updateNotice . style . setProperty ( "opacity" , "1" , "important" ) ;
2021-02-05 21:45:34 +01:00
let reloadButton = updateNotice . querySelector ( BDFDB . dotCN . noticeupdatebuttonreload ) ;
if ( reloadButton ) BDFDB . DOMUtils . hide ( reloadButton ) ;
2020-09-19 21:32:19 +02:00
}
if ( updateNotice ) {
2021-02-05 21:45:34 +01:00
let updateNoticeList = updateNotice . querySelector ( BDFDB . dotCN . noticeupdateentries ) ;
2020-09-19 21:32:19 +02:00
if ( updateNoticeList && ! updateNoticeList . querySelector ( ` # ${ pluginName } -notice ` ) ) {
2021-02-05 21:45:34 +01:00
if ( updateNoticeList . childElementCount ) updateNoticeList . appendChild ( BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCN . noticeupdateseparator } ">, </div> ` ) ) ;
let updateEntry = BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCN . noticeupdateentry } " id=" ${ pluginName } -notice"> ${ pluginName } </div> ` ) ;
2020-09-19 21:32:19 +02:00
updateEntry . addEventListener ( "click" , _ => {
if ( ! updateEntry . wasClicked ) {
updateEntry . wasClicked = true ;
BDFDB . PluginUtils . downloadUpdate ( pluginName , url ) ;
}
} ) ;
updateNoticeList . appendChild ( updateEntry ) ;
if ( ! updateNoticeList . hasTooltip ) {
updateNoticeList . hasTooltip = true ;
updateNotice . tooltip = BDFDB . TooltipUtils . create ( updateNoticeList , BDFDB . LanguageUtils . LibraryStrings . update _notice _click , {
type : "bottom" ,
zIndex : 100001 ,
delay : 500 ,
onHide : _ => { updateNoticeList . hasTooltip = false ; }
} ) ;
}
}
}
} ;
2021-02-05 21:45:34 +01:00
BDFDB . PluginUtils . removeUpdateNotice = function ( pluginName , updateNotice = document . querySelector ( BDFDB . dotCN . noticeupdate ) ) {
2020-09-19 21:32:19 +02:00
if ( ! pluginName || ! updateNotice ) return ;
2021-02-05 21:45:34 +01:00
let updateNoticeList = updateNotice . querySelector ( BDFDB . dotCN . noticeupdateentries ) ;
2020-09-19 21:32:19 +02:00
if ( updateNoticeList ) {
let noticeEntry = updateNoticeList . querySelector ( ` # ${ pluginName } -notice ` ) ;
if ( noticeEntry ) {
let nextSibling = noticeEntry . nextSibling ;
let prevSibling = noticeEntry . prevSibling ;
2021-02-05 21:45:34 +01:00
if ( nextSibling && BDFDB . DOMUtils . containsClass ( nextSibling , BDFDB . disCN . noticeupdateseparator ) ) nextSibling . remove ( ) ;
else if ( prevSibling && BDFDB . DOMUtils . containsClass ( prevSibling , BDFDB . disCN . noticeupdateseparator ) ) prevSibling . remove ( ) ;
2020-09-19 21:32:19 +02:00
noticeEntry . remove ( ) ;
}
2021-02-05 21:45:34 +01:00
if ( ! updateNoticeList . childElementCount ) {
let reloadButton = updateNotice . querySelector ( BDFDB . dotCN . noticeupdatebuttonreload ) ;
2020-09-19 21:32:19 +02:00
if ( reloadButton ) {
2021-02-05 21:45:34 +01:00
updateNotice . querySelector ( BDFDB . dotCN . noticetext ) . innerText = BDFDB . LanguageUtils . LibraryStrings . update _notice _reload ;
2021-02-03 11:27:30 +01:00
BDFDB . DOMUtils . show ( reloadButton ) ;
2020-09-19 21:32:19 +02:00
}
else updateNotice . querySelector ( BDFDB . dotCN . noticedismiss ) . click ( ) ;
}
}
} ;
BDFDB . PluginUtils . downloadUpdate = function ( pluginName , url ) {
if ( pluginName && url ) LibraryRequires . request ( url , ( error , response , body ) => {
if ( error ) {
2021-02-05 21:45:34 +01:00
BDFDB . PluginUtils . removeUpdateNotice ( pluginName ) ;
2020-12-24 11:46:03 +01:00
BDFDB . NotificationUtils . toast ( BDFDB . LanguageUtils . LibraryStringsFormat ( "toast_plugin_update_failed" , pluginName ) , {
2021-01-24 13:27:39 +01:00
type : "danger" ,
2021-01-25 14:10:20 +01:00
disableInteractions : true
2020-12-24 11:46:03 +01:00
} ) ;
2020-09-19 21:32:19 +02:00
}
else {
let wasEnabled = BDFDB . BDUtils . isPluginEnabled ( pluginName ) ;
let newName = ( body . match ( /"name"\s*:\s*"([^"]+)"/ ) || [ ] ) [ 1 ] || pluginName ;
2021-02-24 17:32:17 +01:00
let newVersion = ( body . match ( /@version ([0-9]+\.[0-9]+\.[0-9]+)|['"]([0-9]+\.[0-9]+\.[0-9]+)['"]/i ) || [ ] ) . filter ( n => n ) [ 1 ] ;
2021-02-06 20:29:22 +01:00
let oldVersion = PluginStores . updateData . plugins [ url ] . version ;
2020-09-19 21:32:19 +02:00
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName ;
let newFileName = newName == "BDFDB" ? "0BDFDB" : newName ;
LibraryRequires . fs . writeFile ( LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , newFileName + ".plugin.js" ) , body , _ => {
2021-02-05 21:45:34 +01:00
if ( PluginStores . updateData . plugins [ url ] ) PluginStores . updateData . plugins [ url ] . version = newVersion ;
2020-09-19 21:32:19 +02:00
if ( fileName != newFileName ) {
LibraryRequires . fs . unlink ( LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , fileName + ".plugin.js" ) , _ => { } ) ;
let configPath = LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , fileName + ".config.json" ) ;
LibraryRequires . fs . exists ( configPath , exists => {
if ( exists ) LibraryRequires . fs . rename ( configPath , LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , newFileName + ".config.json" ) , _ => { } ) ;
} ) ;
BDFDB . TimeUtils . timeout ( _ => { if ( wasEnabled && ! BDFDB . BDUtils . isPluginEnabled ( newName ) ) BDFDB . BDUtils . enablePlugin ( newName ) ; } , 3000 ) ;
}
2020-12-24 11:46:03 +01:00
BDFDB . NotificationUtils . toast ( BDFDB . LanguageUtils . LibraryStringsFormat ( "toast_plugin_updated" , pluginName , "v" + oldVersion , newName , "v" + newVersion ) , {
2021-01-25 14:10:20 +01:00
disableInteractions : true
2020-12-24 11:46:03 +01:00
} ) ;
2021-02-05 21:45:34 +01:00
let updateNotice = document . querySelector ( BDFDB . dotCN . noticeupdate ) ;
2020-09-19 21:32:19 +02:00
if ( updateNotice ) {
2021-02-05 21:45:34 +01:00
if ( updateNotice . querySelector ( BDFDB . dotCN . noticebutton ) && ! PluginStores . updateData . downloaded . includes ( pluginName ) ) {
PluginStores . updateData . downloaded . push ( pluginName ) ;
2020-09-19 21:32:19 +02:00
}
BDFDB . PluginUtils . removeUpdateNotice ( pluginName , updateNotice ) ;
}
} ) ;
}
} ) ;
} ;
BDFDB . PluginUtils . checkChangeLog = function ( plugin ) {
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ObjectUtils . is ( plugin . changeLog ) ) return ;
2020-11-14 15:52:37 +01:00
if ( ! changeLogs [ plugin . name ] || BDFDB . NumberUtils . compareVersions ( plugin . version , changeLogs [ plugin . name ] ) ) {
changeLogs [ plugin . name ] = plugin . version ;
BDFDB . DataUtils . save ( changeLogs , BDFDB , "changeLogs" ) ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . openChangeLog ( plugin ) ;
}
} ;
BDFDB . PluginUtils . openChangeLog = function ( plugin ) {
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ObjectUtils . is ( plugin . changeLog ) ) return ;
let changeLogHTML = "" , headers = {
added : "New Features" ,
fixed : "Bug Fixes" ,
improved : "Improvements" ,
progress : "Progress"
} ;
for ( let type in plugin . changeLog ) {
type = type . toLowerCase ( ) ;
let className = BDFDB . disCN [ "changelog" + type ] ;
if ( className ) {
2020-12-24 11:46:03 +01:00
changeLogHTML += ` <h1 class=" ${ className } ${ BDFDB . disCN . margintop20 } " ${ changeLogHTML . indexOf ( "<h1" ) == - 1 ? ` style="margin-top: 0px !important;" ` : "" } > ${ BDFDB . LanguageUtils && BDFDB . LanguageUtils . LibraryStrings ? BDFDB . LanguageUtils . LibraryStrings [ "changelog_" + type ] : headers [ type ] } </h1><ul> ` ;
2020-09-19 21:32:19 +02:00
for ( let key in plugin . changeLog [ type ] ) changeLogHTML += ` <li><strong> ${ key } </strong> ${ plugin . changeLog [ type ] [ key ] ? ( ": " + plugin . changeLog [ type ] [ key ] + "." ) : "" } </li> ` ;
changeLogHTML += ` </ul> `
}
}
2020-10-08 17:35:36 +02:00
if ( changeLogHTML ) BDFDB . ModalUtils . open ( plugin , {
header : ` ${ plugin . name } ${ BDFDB . LanguageUtils . LanguageStrings . CHANGE _LOG } ` ,
2021-01-23 20:18:05 +01:00
subHeader : ` Version ${ plugin . version } ` ,
2020-10-08 17:35:36 +02:00
className : BDFDB . disCN . modalchangelogmodal ,
contentClassName : BDFDB . disCNS . changelogcontainer + BDFDB . disCN . modalminicontent ,
footerDirection : InternalComponents . LibraryComponents . Flex . Direction . HORIZONTAL ,
children : BDFDB . ReactUtils . elementToReact ( BDFDB . DOMUtils . create ( changeLogHTML ) ) ,
2020-10-17 09:27:56 +02:00
footerChildren : ( plugin == BDFDB || plugin == libraryInstance || PluginStores . loaded [ plugin . name ] && PluginStores . loaded [ plugin . name ] == plugin && plugin . author == "DevilBro" ) && BDFDB . ReactUtils . createElement ( "div" , {
2020-10-08 17:35:36 +02:00
className : BDFDB . disCN . changelogfooter ,
children : [
2020-11-19 16:45:36 +01:00
{ href : "https://www.paypal.me/MircoWittrien" , name : "PayPal" , icon : "PAYPAL" } ,
{ href : "https://www.patreon.com/MircoWittrien" , name : "Patreon" , icon : "PATREON" }
2020-10-08 17:35:36 +02:00
] . map ( data => BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Anchor , {
className : BDFDB . disCN . changelogsociallink ,
href : data . href ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
text : data . name ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : InternalComponents . LibraryComponents . SvgIcon . Names [ data . icon ] ,
width : 16 ,
height : 16
} )
} )
} ) ) . concat ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextElement , {
size : InternalComponents . LibraryComponents . TextElement . Sizes . SIZE _12 ,
2020-10-08 19:37:46 +02:00
children : BDFDB . LanguageUtils . LibraryStrings . donate _message
2020-10-08 17:35:36 +02:00
} ) )
} )
} ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . PluginUtils . addLoadingIcon = function ( icon ) {
if ( ! Node . prototype . isPrototypeOf ( icon ) ) return ;
let app = document . querySelector ( BDFDB . dotCN . app ) ;
if ( ! app ) return ;
BDFDB . DOMUtils . addClass ( icon , BDFDB . disCN . loadingicon ) ;
let loadingIconWrapper = document . querySelector ( BDFDB . dotCN . app + ">" + BDFDB . dotCN . loadingiconwrapper )
if ( ! loadingIconWrapper ) {
loadingIconWrapper = BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCN . loadingiconwrapper } "></div> ` ) ;
app . appendChild ( loadingIconWrapper ) ;
let killObserver = new MutationObserver ( changes => { if ( ! loadingIconWrapper . firstElementChild ) BDFDB . DOMUtils . remove ( loadingIconWrapper ) ; } ) ;
2020-11-19 16:51:14 +01:00
killObserver . observe ( loadingIconWrapper , { childList : true } ) ;
2020-09-19 21:32:19 +02:00
}
loadingIconWrapper . appendChild ( icon ) ;
} ;
2020-11-22 18:33:22 +01:00
BDFDB . PluginUtils . createSettingsPanel = function ( addon , props ) {
addon = addon == BDFDB && InternalBDFDB || addon ;
if ( ! BDFDB . ObjectUtils . is ( addon ) ) return ;
2020-11-23 17:52:58 +01:00
let settingsProps = props ;
if ( settingsProps && ! BDFDB . ObjectUtils . is ( settingsProps ) && ( BDFDB . ReactUtils . isValidElement ( settingsProps ) || BDFDB . ArrayUtils . is ( settingsProps ) ) ) settingsProps = {
children : settingsProps
} ;
2020-11-28 22:54:00 +01:00
let settingsPanel = BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SettingsPanel , Object . assign ( {
2020-11-23 17:52:58 +01:00
addon : addon ,
collapseStates : settingsProps && settingsProps . collapseStates
} , settingsProps ) ) ;
2020-11-28 22:54:00 +01:00
if ( isBeta || ! document . querySelector ( "#bd-settingspane-container" ) ) return settingsPanel ;
2020-11-28 18:54:08 +01:00
else {
2020-11-28 22:54:00 +01:00
let div = document . createElement ( "div" ) ;
div . props = settingsPanel . props ;
2020-11-28 18:54:08 +01:00
BDFDB . TimeUtils . timeout ( _ => {
BDFDB . ModalUtils . open ( addon , {
header : ` ${ addon . name } ${ BDFDB . LanguageUtils . LanguageStrings . SETTINGS } ` ,
2021-01-23 18:50:24 +01:00
subHeader : "" ,
2020-11-28 18:54:08 +01:00
className : BDFDB . disCN . _repomodal ,
headerClassName : BDFDB . disCN . _repomodalheader ,
contentClassName : BDFDB . disCN . _repomodalsettings ,
footerClassName : BDFDB . disCN . _repomodalfooter ,
size : "MEDIUM" ,
2020-11-28 22:54:00 +01:00
children : settingsPanel ,
2020-11-28 18:54:08 +01:00
buttons : [ { contents : BDFDB . LanguageUtils . LanguageStrings . DONE , color : "BRAND" , close : true } ]
} ) ;
} ) ;
BDFDB . TimeUtils . timeout ( _ => {
let settings = document . querySelector ( ` ${ BDFDB . dotCN . _reposettingsopen } #plugin-settings- ${ addon . name } ` ) ;
if ( settings && settings . previousElementSibling && ! settings . previousElementSibling . className ) settings . previousElementSibling . click ( ) ;
2020-11-28 19:01:00 +01:00
} , 1000 ) ;
2020-11-28 22:54:00 +01:00
return div ;
2020-11-28 18:54:08 +01:00
}
2020-09-19 21:32:19 +02:00
} ;
BDFDB . PluginUtils . refreshSettingsPanel = function ( plugin , settingsPanel , ... args ) {
2020-11-22 18:33:22 +01:00
if ( BDFDB . ObjectUtils . is ( plugin ) ) {
2020-11-28 22:54:00 +01:00
if ( settingsPanel && settingsPanel . props && BDFDB . ObjectUtils . is ( settingsPanel . props . _instance ) ) {
2020-11-22 18:48:06 +01:00
settingsPanel . props . _instance . props = Object . assign ( { } , settingsPanel . props . _instance . props , ... args ) ;
BDFDB . ReactUtils . forceUpdate ( settingsPanel . props . _instance ) ;
2020-11-22 18:33:22 +01:00
}
else if ( typeof plugin . getSettingsPanel == "function" && Node . prototype . isPrototypeOf ( settingsPanel ) && settingsPanel . parentElement ) {
settingsPanel . parentElement . appendChild ( plugin . getSettingsPanel ( ... args ) ) ;
settingsPanel . remove ( ) ;
}
}
2020-09-19 21:32:19 +02:00
} ;
InternalBDFDB . addSpecialListeners = function ( plugin ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( BDFDB . ObjectUtils . is ( plugin ) ) {
2021-02-09 13:05:30 +01:00
if ( typeof plugin . onSwitch == "function" ) {
2020-09-19 21:32:19 +02:00
let spacer = document . querySelector ( ` ${ BDFDB . dotCN . guildswrapper } ~ * > ${ BDFDB . dotCN . chatspacer } ` ) ;
if ( spacer ) {
let noChannelObserver = new MutationObserver ( changes => { changes . forEach ( change => {
if ( change . target && BDFDB . DOMUtils . containsClass ( change . target , BDFDB . disCN . nochannel ) ) plugin . onSwitch ( ) ;
} ) ; } ) ;
2020-11-19 16:51:14 +01:00
BDFDB . ObserverUtils . connect ( plugin , spacer . querySelector ( BDFDB . dotCNC . chat + BDFDB . dotCN . nochannel ) , { name : "switchFixNoChannelObserver" , instance : noChannelObserver } , { attributes : true } ) ;
2020-09-19 21:32:19 +02:00
let spacerObserver = new MutationObserver ( changes => { changes . forEach ( change => { if ( change . addedNodes ) { change . addedNodes . forEach ( node => {
if ( BDFDB . DOMUtils . containsClass ( node , BDFDB . disCN . chat , BDFDB . disCN . nochannel , false ) ) {
2020-11-19 16:51:14 +01:00
BDFDB . ObserverUtils . connect ( plugin , node , { name : "switchFixNoChannelObserver" , instance : noChannelObserver } , { attributes : true } ) ;
2020-09-19 21:32:19 +02:00
}
} ) ; } } ) ; } ) ;
2020-11-19 16:51:14 +01:00
BDFDB . ObserverUtils . connect ( plugin , spacer , { name : "switchFixSpacerObserver" , instance : spacerObserver } , { childList : true } ) ;
2020-09-19 21:32:19 +02:00
}
}
InternalBDFDB . addContextListeners ( plugin ) ;
}
} ;
window . BDFDB _Global = Object . assign ( {
started : true ,
loading : true ,
PluginUtils : {
buildPlugin : BDFDB . PluginUtils . buildPlugin ,
cleanUp : BDFDB . PluginUtils . cleanUp
}
} , config , window . BDFDB _Global ) ;
const loadLibrary = tryAgain => {
2020-11-19 16:45:36 +01:00
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/_res/BDFDB.raw.css" , ( error , response , body ) => {
2020-09-19 21:32:19 +02:00
if ( ( error || ! body ) && tryAgain ) return BDFDB . TimeUtils . timeout ( _ => { loadLibrary ( ) ; } , 10000 ) ;
const css = body ;
2020-11-19 16:45:36 +01:00
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/_res/BDFDB.data.json" , BDFDB . TimeUtils . suppress ( ( error2 , response2 , body2 ) => {
2020-09-19 21:32:19 +02:00
if ( ( error2 || ! body2 ) && tryAgain ) return BDFDB . TimeUtils . timeout ( _ => { loadLibrary ( ) ; } , 10000 ) ;
const InternalData = JSON . parse ( body2 ) ;
2021-02-04 18:22:04 +01:00
InternalBDFDB . getPluginURL = function ( plugin ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( BDFDB . ObjectUtils . is ( plugin ) ) {
if ( plugin . rawUrl ) return plugin . rawUrl ;
else {
let name = InternalData && InternalData . PluginNameMap && InternalData . PluginNameMap [ plugin . name ] || plugin . name ;
return ` https://mwittrien.github.io/BetterDiscordAddons/Plugins/ ${ name } / ${ name } .plugin.js ` ;
}
}
else return "" ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . ObserverUtils = { } ;
BDFDB . ObserverUtils . connect = function ( plugin , eleOrSelec , observer , config = { childList : true } ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! eleOrSelec || ! observer ) return ;
if ( BDFDB . ObjectUtils . isEmpty ( plugin . observers ) ) plugin . observers = { } ;
if ( ! BDFDB . ArrayUtils . is ( plugin . observers [ observer . name ] ) ) plugin . observers [ observer . name ] = [ ] ;
if ( ! observer . multi ) for ( let subinstance of plugin . observers [ observer . name ] ) subinstance . disconnect ( ) ;
if ( observer . instance ) plugin . observers [ observer . name ] . push ( observer . instance ) ;
let instance = plugin . observers [ observer . name ] [ plugin . observers [ observer . name ] . length - 1 ] ;
if ( instance ) {
let node = Node . prototype . isPrototypeOf ( eleOrSelec ) ? eleOrSelec : typeof eleOrSelec === "string" ? document . querySelector ( eleOrSelec ) : null ;
if ( node ) instance . observe ( node , config ) ;
}
} ;
BDFDB . ObserverUtils . disconnect = function ( plugin , observer ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( BDFDB . ObjectUtils . is ( plugin ) && ! BDFDB . ObjectUtils . isEmpty ( plugin . observers ) ) {
let observername = typeof observer == "string" ? observer : ( BDFDB . ObjectUtils . is ( observer ) ? observer . name : null ) ;
if ( ! observername ) {
for ( let observer in plugin . observers ) for ( let instance of plugin . observers [ observer ] ) instance . disconnect ( ) ;
delete plugin . observers ;
}
else if ( ! BDFDB . ArrayUtils . is ( plugin . observers [ observername ] ) ) {
for ( let instance of plugin . observers [ observername ] ) instance . disconnect ( ) ;
delete plugin . observers [ observername ] ;
}
}
} ;
BDFDB . StoreChangeUtils = { } ;
BDFDB . StoreChangeUtils . add = function ( plugin , store , callback ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ObjectUtils . is ( store ) || typeof store . addChangeListener != "function" || typeof callback != "function" ) return ;
2020-10-06 11:30:21 +02:00
BDFDB . StoreChangeUtils . remove ( plugin , store , callback ) ;
2020-09-19 21:32:19 +02:00
if ( ! BDFDB . ArrayUtils . is ( plugin . changeListeners ) ) plugin . changeListeners = [ ] ;
plugin . changeListeners . push ( { store , callback } ) ;
store . addChangeListener ( callback ) ;
} ;
BDFDB . StoreChangeUtils . remove = function ( plugin , store , callback ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ArrayUtils . is ( plugin . changeListeners ) ) return ;
if ( ! store ) {
while ( plugin . changeListeners . length ) {
let listener = plugin . changeListeners . pop ( ) ;
listener . store . removeChangeListener ( listener . callback ) ;
}
}
else if ( BDFDB . ObjectUtils . is ( store ) && typeof store . addChangeListener == "function" ) {
if ( ! callback ) {
for ( let listener of plugin . changeListeners ) {
let removedListeners = [ ] ;
if ( listener . store == store ) {
listener . store . removeChangeListener ( listener . callback ) ;
removedListeners . push ( listener ) ;
}
if ( removedListeners . length ) plugin . changeListeners = plugin . changeListeners . filter ( listener => ! removedListeners . includes ( listener ) ) ;
}
}
else if ( typeof callback == "function" ) {
store . removeChangeListener ( callback ) ;
plugin . changeListeners = plugin . changeListeners . filter ( listener => listener . store == store && listener . callback == callback ) ;
}
}
} ;
var pressedKeys = [ ] , mousePosition ;
BDFDB . ListenerUtils = { } ;
BDFDB . ListenerUtils . isPressed = function ( key ) {
return pressedKeys . includes ( key ) ;
} ;
BDFDB . ListenerUtils . getPosition = function ( key ) {
return mousePosition ;
} ;
BDFDB . ListenerUtils . add = function ( plugin , ele , actions , selectorOrCallback , callbackOrNothing ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ( ! Node . prototype . isPrototypeOf ( ele ) && ele !== window ) || ! actions ) return ;
let callbackIs4th = typeof selectorOrCallback == "function" ;
let selector = callbackIs4th ? undefined : selectorOrCallback ;
let callback = callbackIs4th ? selectorOrCallback : callbackOrNothing ;
if ( typeof callback != "function" ) return ;
BDFDB . ListenerUtils . remove ( plugin , ele , actions , selector ) ;
for ( let action of actions . split ( " " ) ) {
action = action . split ( "." ) ;
let eventName = action . shift ( ) . toLowerCase ( ) ;
if ( ! eventName ) return ;
let origEventName = eventName ;
eventName = eventName == "mouseenter" || eventName == "mouseleave" ? "mouseover" : eventName ;
let namespace = ( action . join ( "." ) || "" ) + plugin . name ;
if ( ! BDFDB . ArrayUtils . is ( plugin . eventListeners ) ) plugin . eventListeners = [ ] ;
let eventCallback = null ;
if ( selector ) {
if ( origEventName == "mouseenter" || origEventName == "mouseleave" ) {
eventCallback = e => {
for ( let child of e . path ) if ( typeof child . matches == "function" && child . matches ( selector ) && ! child [ namespace + "BDFDB" + origEventName ] ) {
child [ namespace + "BDFDB" + origEventName ] = true ;
if ( origEventName == "mouseenter" ) callback ( BDFDB . ListenerUtils . copyEvent ( e , child ) ) ;
2020-11-17 17:24:56 +01:00
let mouseOut = e2 => {
2020-09-19 21:32:19 +02:00
if ( e2 . target . contains ( child ) || e2 . target == child || ! child . contains ( e2 . target ) ) {
if ( origEventName == "mouseleave" ) callback ( BDFDB . ListenerUtils . copyEvent ( e , child ) ) ;
delete child [ namespace + "BDFDB" + origEventName ] ;
2020-11-17 17:24:56 +01:00
document . removeEventListener ( "mouseout" , mouseOut ) ;
2020-09-19 21:32:19 +02:00
}
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mouseout" , mouseOut ) ;
2020-09-19 21:32:19 +02:00
break ;
}
} ;
}
else {
eventCallback = e => {
for ( let child of e . path ) if ( typeof child . matches == "function" && child . matches ( selector ) ) {
callback ( BDFDB . ListenerUtils . copyEvent ( e , child ) ) ;
break ;
}
} ;
}
}
else eventCallback = e => { callback ( BDFDB . ListenerUtils . copyEvent ( e , ele ) ) ; } ;
plugin . eventListeners . push ( { ele , eventName , origEventName , namespace , selector , eventCallback } ) ;
ele . addEventListener ( eventName , eventCallback , true ) ;
}
} ;
BDFDB . ListenerUtils . remove = function ( plugin , ele , actions = "" , selector ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ArrayUtils . is ( plugin . eventListeners ) ) return ;
if ( ! ele ) {
while ( plugin . eventListeners . length ) {
let listener = plugin . eventListeners . pop ( ) ;
listener . ele . removeEventListener ( listener . eventName , listener . eventCallback , true ) ;
}
}
else if ( Node . prototype . isPrototypeOf ( ele ) || ele === window ) {
for ( let action of actions . split ( " " ) ) {
action = action . split ( "." ) ;
let eventName = action . shift ( ) . toLowerCase ( ) ;
let namespace = ( action . join ( "." ) || "" ) + plugin . name ;
for ( let listener of plugin . eventListeners ) {
let removedListeners = [ ] ;
if ( listener . ele == ele && ( ! eventName || listener . origEventName == eventName ) && listener . namespace == namespace && ( selector === undefined || listener . selector == selector ) ) {
listener . ele . removeEventListener ( listener . eventName , listener . eventCallback , true ) ;
removedListeners . push ( listener ) ;
}
if ( removedListeners . length ) plugin . eventListeners = plugin . eventListeners . filter ( listener => ! removedListeners . includes ( listener ) ) ;
}
}
}
} ;
BDFDB . ListenerUtils . multiAdd = function ( node , actions , callback ) {
if ( ! Node . prototype . isPrototypeOf ( node ) || ! actions || typeof callback != "function" ) return ;
for ( let action of actions . trim ( ) . split ( " " ) . filter ( n => n ) ) node . addEventListener ( action , callback , true ) ;
} ;
BDFDB . ListenerUtils . multiRemove = function ( node , actions , callback ) {
if ( ! Node . prototype . isPrototypeOf ( node ) || ! actions || typeof callback != "function" ) return ;
for ( let action of actions . trim ( ) . split ( " " ) . filter ( n => n ) ) node . removeEventListener ( action , callback , true ) ;
} ;
BDFDB . ListenerUtils . addToChildren = function ( node , actions , selector , callback ) {
if ( ! Node . prototype . isPrototypeOf ( node ) || ! actions || ! selector || ! selector . trim ( ) || typeof callback != "function" ) return ;
for ( let action of actions . trim ( ) . split ( " " ) . filter ( n => n ) ) {
let eventCallback = callback ;
if ( action == "mouseenter" || action == "mouseleave" ) eventCallback = e => { if ( e . target . matches ( selector ) ) callback ( e ) ; } ;
node . querySelectorAll ( selector . trim ( ) ) . forEach ( child => { child . addEventListener ( action , eventCallback , true ) ; } ) ;
}
} ;
BDFDB . ListenerUtils . copyEvent = function ( e , ele ) {
if ( ! e || ! e . constructor || ! e . type ) return e ;
let eCopy = new e . constructor ( e . type , e ) ;
Object . defineProperty ( eCopy , "originalEvent" , { value : e } ) ;
Object . defineProperty ( eCopy , "which" , { value : e . which } ) ;
Object . defineProperty ( eCopy , "keyCode" , { value : e . keyCode } ) ;
Object . defineProperty ( eCopy , "path" , { value : e . path } ) ;
Object . defineProperty ( eCopy , "relatedTarget" , { value : e . relatedTarget } ) ;
Object . defineProperty ( eCopy , "srcElement" , { value : e . srcElement } ) ;
Object . defineProperty ( eCopy , "target" , { value : e . target } ) ;
Object . defineProperty ( eCopy , "toElement" , { value : e . toElement } ) ;
if ( ele ) Object . defineProperty ( eCopy , "currentTarget" , { value : ele } ) ;
return eCopy ;
} ;
BDFDB . ListenerUtils . stopEvent = function ( e ) {
if ( BDFDB . ObjectUtils . is ( e ) ) {
if ( typeof e . preventDefault == "function" ) e . preventDefault ( ) ;
if ( typeof e . stopPropagation == "function" ) e . stopPropagation ( ) ;
if ( typeof e . stopImmediatePropagation == "function" ) e . stopImmediatePropagation ( ) ;
if ( BDFDB . ObjectUtils . is ( e . originalEvent ) ) {
if ( typeof e . originalEvent . preventDefault == "function" ) e . originalEvent . preventDefault ( ) ;
if ( typeof e . originalEvent . stopPropagation == "function" ) e . originalEvent . stopPropagation ( ) ;
if ( typeof e . originalEvent . stopImmediatePropagation == "function" ) e . originalEvent . stopImmediatePropagation ( ) ;
}
}
} ;
2021-01-26 21:14:48 +01:00
var Toasts = [ ] , NotificationBars = [ ] ;
var ToastQueues = { } , DesktopNotificationQueue = { queue : [ ] , running : false } ;
2021-01-27 18:14:10 +01:00
for ( let key in LibraryConstants . ToastPositions ) ToastQueues [ LibraryConstants . ToastPositions [ key ] ] = { queue : [ ] , full : false } ;
2021-01-26 21:14:48 +01:00
2020-09-19 21:32:19 +02:00
BDFDB . NotificationUtils = { } ;
2021-01-26 21:14:48 +01:00
BDFDB . NotificationUtils . toast = function ( children , config = { } ) {
2021-01-29 18:32:31 +01:00
if ( ! children ) return ;
let app = document . querySelector ( BDFDB . dotCN . appmount ) || document . body ;
if ( ! app ) return ;
let position = config . position && LibraryConstants . ToastPositions [ config . position ] || choices . toastPosition && LibraryConstants . ToastPositions [ choices . toastPosition ] || LibraryConstants . ToastPositions . right ;
2021-01-26 21:14:48 +01:00
2021-01-29 18:32:31 +01:00
const runQueue = _ => {
if ( ToastQueues [ position ] . full ) return ;
let data = ToastQueues [ position ] . queue . shift ( ) ;
if ( ! data ) return ;
let id = BDFDB . NumberUtils . generateId ( Toasts ) ;
let toasts = document . querySelector ( BDFDB . dotCN . toasts + BDFDB . dotCN [ position ] ) ;
if ( ! toasts ) {
toasts = BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . toasts , BDFDB . disCN [ position ] ) } "></div> ` ) ;
app . appendChild ( toasts ) ;
2021-01-26 21:14:48 +01:00
}
2021-01-29 18:32:31 +01:00
if ( data . config . id ) data . toast . id = data . config . id . split ( " " ) . join ( "" ) ;
if ( data . config . className ) BDFDB . DOMUtils . addClass ( data . toast , data . config . className ) ;
if ( data . config . css ) BDFDB . DOMUtils . appendLocalStyle ( "BDFDBcustomToast" + id , data . config . css ) ;
if ( data . config . style ) data . toast . style = Object . assign ( { } , data . toast . style , data . config . style ) ;
let backgroundColor , fontColor , barColor ;
let type = data . config . type && BDFDB . disCN [ "toast" + data . config . type ] ;
if ( ! type ) {
barColor = BDFDB . ColorUtils . convert ( data . config . barColor , "HEX" ) ;
let comp = BDFDB . ColorUtils . convert ( data . config . color , "RGBCOMP" ) ;
if ( comp ) {
backgroundColor = BDFDB . ColorUtils . convert ( comp , "HEX" ) ;
fontColor = comp [ 0 ] > 180 && comp [ 1 ] > 180 && comp [ 2 ] > 180 ? "#000" : "#FFF" ;
BDFDB . DOMUtils . addClass ( data . toast , BDFDB . disCN . toastcustom ) ;
}
else BDFDB . DOMUtils . addClass ( data . toast , BDFDB . disCN . toastdefault ) ;
2021-01-26 21:14:48 +01:00
}
2021-01-29 18:32:31 +01:00
else BDFDB . DOMUtils . addClass ( data . toast , type ) ;
let disableInteractions = data . config . disableInteractions && typeof data . config . onClick != "function" ;
if ( disableInteractions ) data . toast . style . setProperty ( "pointer-events" , "none" , "important" ) ;
else {
BDFDB . DOMUtils . addClass ( data . toast , BDFDB . disCN . toastclosable ) ;
2021-02-04 15:03:17 +01:00
data . toast . addEventListener ( "click" , event => {
if ( typeof data . config . onClick == "function" && ! BDFDB . DOMUtils . getParent ( BDFDB . dotCN . toastcloseicon , event . target ) ) data . config . onClick ( ) ;
2021-01-29 18:32:31 +01:00
data . toast . close ( ) ;
2021-01-26 21:14:48 +01:00
} ) ;
}
2021-01-29 18:32:31 +01:00
toasts . appendChild ( data . toast ) ;
let timeout = typeof data . config . timeout == "number" && ! disableInteractions ? data . config . timeout : 3000 ;
timeout = ( timeout > 0 ? timeout : 600000 ) + 300 ;
let closeTimeout = BDFDB . TimeUtils . timeout ( _ => {
data . toast . close ( ) ;
} , timeout ) ;
BDFDB . TimeUtils . timeout ( _ => { BDFDB . DOMUtils . removeClass ( data . toast , BDFDB . disCN . toastopening ) ; } ) ;
data . toast . close = _ => {
clearTimeout ( closeTimeout ) ;
if ( document . contains ( data . toast ) ) {
BDFDB . DOMUtils . addClass ( data . toast , BDFDB . disCN . toastclosing ) ;
data . toast . style . setProperty ( "pointer-events" , "none" , "important" ) ;
BDFDB . TimeUtils . timeout ( _ => {
if ( typeof data . config . onClose == "function" ) data . config . onClose ( ) ;
BDFDB . ArrayUtils . remove ( Toasts , id ) ;
BDFDB . DOMUtils . removeLocalStyle ( "BDFDBcustomToast" + id ) ;
data . toast . remove ( ) ;
if ( ! toasts . querySelectorAll ( BDFDB . dotCN . toast ) . length ) toasts . remove ( ) ;
} , 300 ) ;
}
ToastQueues [ position ] . full = false ;
runQueue ( ) ;
} ;
let icon = data . config . avatar ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . AvatarComponents . default , {
src : data . config . avatar ,
size : InternalComponents . LibraryComponents . AvatarComponents . Sizes . SIZE _24
} ) : ( ( data . config . icon || data . config . type && LibraryConstants . ToastIcons [ data . config . type ] ) ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : data . config . type && LibraryConstants . ToastIcons [ data . config . type ] && InternalComponents . LibraryComponents . SvgIcon . Names [ LibraryConstants . ToastIcons [ data . config . type ] ] ,
iconSVG : data . config . icon ,
width : 18 ,
height : 18 ,
nativeClass : true
} ) : null ) ;
BDFDB . ReactUtils . render ( BDFDB . ReactUtils . createElement ( class BDFDB _Toast extends BDFDB . ReactUtils . Component {
componentDidMount ( ) {
data . toast . update = newChildren => {
if ( ! newChildren ) return ;
this . props . children = newChildren ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
} ;
this . _start = performance . now ( ) ;
this . _progress = BDFDB . TimeUtils . interval ( _ => { BDFDB . ReactUtils . forceUpdate ( this ) ; } , 10 ) ;
}
componentWillUnmount ( ) {
BDFDB . TimeUtils . clear ( this . _progress ) ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( BDFDB . ReactUtils . Fragment , {
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . toastbg ,
style : { backgroundColor : backgroundColor }
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . toastinner ,
style : { color : fontColor } ,
children : [
icon && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( data . config . avatar && BDFDB . disCN . toastavatar , BDFDB . disCN . toasticon , data . config . iconClassName ) ,
children : icon
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . toasttext , data . config . textClassName ) ,
children : this . props . children
} ) ,
! disableInteractions && BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . toastcloseicon ,
name : InternalComponents . LibraryComponents . SvgIcon . Names . CLOSE ,
width : 16 ,
height : 16
} )
] . filter ( n => n )
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . div , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . toastbar , barColor && BDFDB . disCN . toastcustombar ) ,
style : {
backgroundColor : barColor ,
right : ` ${ 100 - ( performance . now ( ) - this . _start ) * 100 / timeout } % `
}
} )
]
} ) ;
}
} , { children : data . children } ) , data . toast ) ;
ToastQueues [ position ] . full = ( BDFDB . ArrayUtils . sum ( Array . from ( toasts . childNodes ) . map ( c => {
let height = BDFDB . DOMUtils . getRects ( c ) . height ;
return height > 50 ? height : 50 ;
} ) ) - 100 ) > BDFDB . DOMUtils . getRects ( app ) . height ;
if ( typeof data . config . onShow == "function" ) data . config . onShow ( ) ;
} ;
2021-01-26 21:14:48 +01:00
2021-01-29 18:32:31 +01:00
let toast = BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCNS . toast + BDFDB . disCN . toastopening } "></div> ` ) ;
toast . update = _ => { } ;
ToastQueues [ position ] . queue . push ( { children , config , toast } ) ;
runQueue ( ) ;
return toast ;
2021-01-26 21:14:48 +01:00
} ;
BDFDB . NotificationUtils . desktop = function ( content , config = { } ) {
if ( ! content ) return ;
2020-09-19 21:32:19 +02:00
const queue = _ => {
2021-01-26 21:14:48 +01:00
DesktopNotificationQueue . queue . push ( { content , config } ) ;
2021-01-25 14:10:20 +01:00
runQueue ( ) ;
2020-09-19 21:32:19 +02:00
} ;
2021-01-25 14:10:20 +01:00
const runQueue = _ => {
2021-01-26 21:14:48 +01:00
if ( DesktopNotificationQueue . running ) return ;
let data = DesktopNotificationQueue . queue . shift ( ) ;
if ( ! data ) return ;
2020-09-19 21:32:19 +02:00
DesktopNotificationQueue . running = true ;
2021-01-26 21:14:48 +01:00
let muted = data . config . silent ;
data . config . silent = data . config . silent || data . config . sound ? true : false ;
2020-09-19 21:32:19 +02:00
let audio = new Audio ( ) ;
2021-01-26 21:14:48 +01:00
if ( ! muted && data . config . sound ) {
audio . src = data . config . sound ;
2020-09-19 21:32:19 +02:00
audio . play ( ) ;
}
2021-01-26 21:14:48 +01:00
let notification = new Notification ( data . content , data . config ) ;
2021-01-25 14:34:19 +01:00
2021-01-26 21:14:48 +01:00
let disableInteractions = data . config . disableInteractions && typeof data . config . onClick != "function" ;
2021-01-25 14:34:19 +01:00
if ( disableInteractions ) notification . onclick = _ => { } ;
else notification . onclick = _ => {
2021-01-26 21:14:48 +01:00
if ( typeof data . config . onClick == "function" ) data . config . onClick ( ) ;
2020-09-19 21:32:19 +02:00
notification . close ( ) ;
2021-01-25 14:34:19 +01:00
} ;
2021-01-25 15:34:43 +01:00
notification . onclose = _ => {
2021-01-25 14:34:19 +01:00
audio . pause ( ) ;
2020-09-19 21:32:19 +02:00
DesktopNotificationQueue . running = false ;
2021-01-26 21:14:48 +01:00
BDFDB . TimeUtils . timeout ( runQueue , 1000 ) ;
2021-01-25 15:34:43 +01:00
}
2020-09-19 21:32:19 +02:00
} ;
2021-01-26 21:14:48 +01:00
2020-09-19 21:32:19 +02:00
if ( ! ( "Notification" in window ) ) { }
else if ( Notification . permission === "granted" ) queue ( ) ;
else if ( Notification . permission !== "denied" ) Notification . requestPermission ( function ( response ) { if ( response === "granted" ) queue ( ) ; } ) ;
} ;
2021-01-23 19:03:55 +01:00
BDFDB . NotificationUtils . notice = function ( text , config = { } ) {
2020-09-19 21:32:19 +02:00
if ( ! text ) return ;
2020-10-31 11:43:29 +01:00
let layers = document . querySelector ( BDFDB . dotCN . layers ) || document . querySelector ( BDFDB . dotCN . appmount ) ;
2020-09-19 21:32:19 +02:00
if ( ! layers ) return ;
let id = BDFDB . NumberUtils . generateId ( NotificationBars ) ;
2021-02-05 21:45:34 +01:00
let notice = BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCNS . notice + BDFDB . disCN . noticewrapper } " notice-id=" ${ id } "><div class=" ${ BDFDB . disCN . noticedismiss } " ${ config . forceStyle ? ` style="width: 36px !important; height: 36px !important; position: absolute !important; top: 0 !important; right: 0 !important; left: unset !important;" ` : "" } ></div><div class=" ${ BDFDB . disCN . noticetext } "></div></div> ` ) ;
2020-09-19 21:32:19 +02:00
layers . parentElement . insertBefore ( notice , layers ) ;
2021-01-12 19:09:01 +01:00
let noticeText = notice . querySelector ( BDFDB . dotCN . noticetext ) ;
2021-01-23 19:03:55 +01:00
if ( config . platform ) for ( let platform of config . platform . split ( " " ) ) if ( DiscordClasses [ "noticeicon" + platform ] ) {
2020-09-19 21:32:19 +02:00
let icon = BDFDB . DOMUtils . create ( ` <i class=" ${ BDFDB . disCN [ "noticeicon" + platform ] } "></i> ` ) ;
BDFDB . DOMUtils . addClass ( icon , BDFDB . disCN . noticeplatformicon ) ;
BDFDB . DOMUtils . removeClass ( icon , BDFDB . disCN . noticeicon ) ;
2021-01-12 19:09:01 +01:00
notice . insertBefore ( icon , noticeText ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-23 19:03:55 +01:00
if ( config . customIcon ) {
2021-01-24 14:20:52 +01:00
let icon = document . createElement ( "i" ) , iconInner = BDFDB . DOMUtils . create ( config . customIcon ) ;
if ( iconInner . nodeType == Node . TEXT _NODE ) icon . style . setProperty ( "background" , ` url( ${ config . customIcon } ) center/cover no-repeat ` ) ;
2021-02-05 21:45:34 +01:00
else {
icon = iconInner ;
if ( ( icon . tagName || "" ) . toUpperCase ( ) == "SVG" ) {
icon . removeAttribute ( "width" ) ;
icon . setAttribute ( "height" , "100%" ) ;
}
}
2020-09-19 21:32:19 +02:00
BDFDB . DOMUtils . addClass ( icon , BDFDB . disCN . noticeplatformicon ) ;
BDFDB . DOMUtils . removeClass ( icon , BDFDB . disCN . noticeicon ) ;
2021-01-12 19:09:01 +01:00
notice . insertBefore ( icon , noticeText ) ;
2020-09-19 21:32:19 +02:00
}
2021-02-05 21:45:34 +01:00
if ( BDFDB . ArrayUtils . is ( config . buttons ) ) for ( let data of config . buttons ) {
let contents = typeof data . contents == "string" && data . contents ;
2021-01-23 19:03:55 +01:00
if ( contents ) {
2021-02-05 21:45:34 +01:00
let button = BDFDB . DOMUtils . create ( ` <button class=" ${ BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . noticebutton , data . className ) } "> ${ contents } </button> ` ) ;
button . addEventListener ( "click" , event => {
if ( data . close ) notice . close ( ) ;
if ( typeof data . onClick == "function" ) data . onClick ( event , notice ) ;
2021-01-23 19:03:55 +01:00
} ) ;
2021-02-05 21:45:34 +01:00
if ( typeof data . onMouseEnter == "function" ) button . addEventListener ( "mouseenter" , event => data . onMouseEnter ( event , notice ) ) ;
if ( typeof data . onMouseLeave == "function" ) button . addEventListener ( "mouseleave" , event => data . onMouseLeave ( event , notice ) ) ;
notice . appendChild ( button ) ;
2021-01-23 19:03:55 +01:00
}
}
if ( config . id ) notice . id = config . id . split ( " " ) . join ( "" ) ;
if ( config . className ) BDFDB . DOMUtils . addClass ( notice , config . className ) ;
if ( config . textClassName ) BDFDB . DOMUtils . addClass ( noticeText , config . textClassName ) ;
if ( config . css ) BDFDB . DOMUtils . appendLocalStyle ( "BDFDBcustomNotificationBar" + id , config . css ) ;
if ( config . style ) notice . style = config . style ;
2021-01-24 13:27:39 +01:00
if ( config . html ) noticeText . innerHTML = text ;
2020-09-19 21:32:19 +02:00
else {
let link = document . createElement ( "a" ) ;
let newText = [ ] ;
for ( let word of text . split ( " " ) ) {
let encodedWord = BDFDB . StringUtils . htmlEscape ( word ) ;
link . href = word ;
2020-09-19 23:10:13 +02:00
newText . push ( link . host && link . host !== window . location . host ? ` <label class=" ${ BDFDB . disCN . noticetextlink } "> ${ encodedWord } </label> ` : encodedWord ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-12 19:09:01 +01:00
noticeText . innerHTML = newText . join ( " " ) ;
2020-09-19 21:32:19 +02:00
}
let type = null ;
2021-01-23 19:03:55 +01:00
if ( config . type && ! document . querySelector ( BDFDB . dotCNS . chatbase + BDFDB . dotCN . noticestreamer ) ) {
if ( type = BDFDB . disCN [ "notice" + config . type ] ) BDFDB . DOMUtils . addClass ( notice , type ) ;
if ( config . type == "premium" ) {
2020-09-19 21:32:19 +02:00
let noticeButton = notice . querySelector ( BDFDB . dotCN . noticebutton ) ;
if ( noticeButton ) BDFDB . DOMUtils . addClass ( noticeButton , BDFDB . disCN . noticepremiumaction ) ;
2021-01-12 19:09:01 +01:00
BDFDB . DOMUtils . addClass ( noticeText , BDFDB . disCN . noticepremiumtext ) ;
notice . insertBefore ( BDFDB . DOMUtils . create ( ` <i class=" ${ BDFDB . disCN . noticepremiumlogo } "></i> ` ) , noticeText ) ;
2020-09-19 21:32:19 +02:00
}
}
if ( ! type ) {
2021-01-23 19:03:55 +01:00
let comp = BDFDB . ColorUtils . convert ( config . color , "RGBCOMP" ) ;
2020-09-19 21:32:19 +02:00
if ( comp ) {
let fontColor = comp [ 0 ] > 180 && comp [ 1 ] > 180 && comp [ 2 ] > 180 ? "#000" : "#FFF" ;
2021-01-12 19:09:01 +01:00
let backgroundColor = BDFDB . ColorUtils . convert ( comp , "HEX" ) ;
2020-09-19 21:32:19 +02:00
let filter = comp [ 0 ] > 180 && comp [ 1 ] > 180 && comp [ 2 ] > 180 ? "brightness(0%)" : "brightness(100%)" ;
2021-01-12 19:09:01 +01:00
BDFDB . DOMUtils . appendLocalStyle ( "BDFDBcustomNotificationBarColorCorrection" + id , ` ${ BDFDB . dotCN . noticewrapper } [notice-id=" ${ id } "]{background-color: ${ backgroundColor } !important;} ${ BDFDB . dotCN . noticewrapper } [notice-id=" ${ id } "] ${ BDFDB . dotCN . noticetext } {color: ${ fontColor } !important;} ${ BDFDB . dotCN . noticewrapper } [notice-id=" ${ id } "] ${ BDFDB . dotCN . noticebutton } {color: ${ fontColor } !important;border-color: ${ BDFDB . ColorUtils . setAlpha ( fontColor , 0.25 , "RGBA" ) } !important;} ${ BDFDB . dotCN . noticewrapper } [notice-id=" ${ id } "] ${ BDFDB . dotCN . noticebutton } :hover {color: ${ backgroundColor } !important;background-color: ${ fontColor } !important;} ${ BDFDB . dotCN . noticewrapper } [notice-id=" ${ id } "] ${ BDFDB . dotCN . noticedismiss } {filter: ${ filter } !important;} ` ) ;
2021-01-03 16:00:42 +01:00
BDFDB . DOMUtils . addClass ( notice , BDFDB . disCN . noticecustom ) ;
2020-09-19 21:32:19 +02:00
}
else BDFDB . DOMUtils . addClass ( notice , BDFDB . disCN . noticedefault ) ;
}
2021-01-23 19:03:55 +01:00
if ( config . forceStyle ) {
2021-01-12 19:09:01 +01:00
notice . style . setProperty ( "display" , "block" , "important" ) ;
notice . style . setProperty ( "height" , "36px" , "important" ) ;
notice . style . setProperty ( "min-width" , "70vw" , "important" ) ;
notice . style . setProperty ( "left" , "unset" , "important" ) ;
notice . style . setProperty ( "right" , "unset" , "important" ) ;
let sideMargin = ( ( BDFDB . DOMUtils . getWidth ( document . body . firstElementChild ) - BDFDB . DOMUtils . getWidth ( notice ) ) / 2 ) ;
notice . style . setProperty ( "left" , ` ${ sideMargin } px ` , "important" ) ;
notice . style . setProperty ( "right" , ` ${ sideMargin } px ` , "important" ) ;
notice . style . setProperty ( "min-width" , "unset" , "important" ) ;
notice . style . setProperty ( "width" , "unset" , "important" ) ;
notice . style . setProperty ( "max-width" , ` calc(100vw - ${ sideMargin * 2 } px) ` , "important" ) ;
}
2021-01-23 19:03:55 +01:00
notice . close = _ => {
2021-01-12 19:45:23 +01:00
BDFDB . DOMUtils . addClass ( notice , BDFDB . disCN . noticeclosing ) ;
2021-01-23 19:03:55 +01:00
if ( config . forceStyle ) {
2021-01-12 19:45:23 +01:00
notice . style . setProperty ( "overflow" , "hidden" , "important" ) ;
notice . style . setProperty ( "height" , "0px" , "important" ) ;
}
2020-09-19 21:32:19 +02:00
if ( notice . tooltip && typeof notice . tooltip . removeTooltip == "function" ) notice . tooltip . removeTooltip ( ) ;
BDFDB . TimeUtils . timeout ( _ => {
2021-01-23 19:03:55 +01:00
if ( typeof config . onClose == "function" ) config . onClose ( ) ;
2020-09-19 21:32:19 +02:00
BDFDB . ArrayUtils . remove ( NotificationBars , id ) ;
BDFDB . DOMUtils . removeLocalStyle ( "BDFDBcustomNotificationBar" + id ) ;
BDFDB . DOMUtils . removeLocalStyle ( "BDFDBcustomNotificationBarColorCorrection" + id ) ;
BDFDB . DOMUtils . remove ( notice ) ;
} , 500 ) ;
2021-01-23 19:03:55 +01:00
} ;
notice . querySelector ( BDFDB . dotCN . noticedismiss ) . addEventListener ( "click" , notice . close ) ;
2020-09-19 21:32:19 +02:00
return notice ;
} ;
BDFDB . NotificationUtils . alert = function ( header , body ) {
if ( typeof header == "string" && typeof header == "string" && window . BdApi && typeof BdApi . alert == "function" ) BdApi . alert ( header , body ) ;
} ;
var Tooltips = [ ] ;
BDFDB . TooltipUtils = { } ;
2021-01-23 19:03:55 +01:00
BDFDB . TooltipUtils . create = function ( anker , text , config = { } ) {
2020-09-19 21:32:19 +02:00
let itemLayerContainer = document . querySelector ( BDFDB . dotCN . appmount + " > " + BDFDB . dotCN . itemlayercontainer ) ;
if ( ! itemLayerContainer || ! Node . prototype . isPrototypeOf ( anker ) || ! document . contains ( anker ) ) return null ;
text = typeof text == "function" ? text ( ) : text ;
2021-01-23 19:03:55 +01:00
if ( typeof text != "string" && ! BDFDB . ReactUtils . isValidElement ( text ) && ! BDFDB . ObjectUtils . is ( config . guild ) ) return null ;
2020-09-19 21:32:19 +02:00
let id = BDFDB . NumberUtils . generateId ( Tooltips ) ;
2021-01-23 19:03:55 +01:00
let zIndexed = typeof config . zIndex == "number" ;
2020-09-19 21:32:19 +02:00
let itemLayer = BDFDB . DOMUtils . create ( ` <div class=" ${ BDFDB . disCNS . itemlayer + BDFDB . disCN . itemlayerdisabledpointerevents } "><div class=" ${ BDFDB . disCN . tooltip } " tooltip-id=" ${ id } "><div class=" ${ BDFDB . disCN . tooltippointer } "></div><div class=" ${ BDFDB . disCN . tooltipcontent } "></div></div></div> ` ) ;
if ( zIndexed ) {
let itemLayerContainerClone = itemLayerContainer . cloneNode ( ) ;
2021-01-23 19:03:55 +01:00
itemLayerContainerClone . style . setProperty ( "z-index" , config . zIndex || 1002 , "important" ) ;
2020-09-23 07:51:49 +02:00
itemLayerContainer . parentElement . insertBefore ( itemLayerContainerClone , itemLayerContainer . nextElementSibling ) ;
2020-09-19 21:32:19 +02:00
itemLayerContainer = itemLayerContainerClone ;
}
itemLayerContainer . appendChild ( itemLayer ) ;
let tooltip = itemLayer . firstElementChild ;
let tooltipContent = itemLayer . querySelector ( BDFDB . dotCN . tooltipcontent ) ;
let tooltipPointer = itemLayer . querySelector ( BDFDB . dotCN . tooltippointer ) ;
2021-01-23 19:03:55 +01:00
if ( config . id ) tooltip . id = config . id . split ( " " ) . join ( "" ) ;
2020-09-19 21:32:19 +02:00
2021-01-23 19:03:55 +01:00
if ( typeof config . type != "string" || ! BDFDB . disCN [ "tooltip" + config . type . toLowerCase ( ) ] ) config . type = "top" ;
let type = config . type . toLowerCase ( ) ;
BDFDB . DOMUtils . addClass ( tooltip , BDFDB . disCN [ "tooltip" + type ] , config . className ) ;
2020-09-19 21:32:19 +02:00
let fontColorIsGradient = false , customBackgroundColor = false , style = "" ;
2021-01-23 19:03:55 +01:00
if ( config . style ) style += config . style ;
if ( config . fontColor ) {
fontColorIsGradient = BDFDB . ObjectUtils . is ( config . fontColor ) ;
if ( ! fontColorIsGradient ) style = ( style ? ( style + " " ) : "" ) + ` color: ${ BDFDB . ColorUtils . convert ( config . fontColor , "RGBA" ) } !important; `
2020-09-19 21:32:19 +02:00
}
2021-01-23 19:03:55 +01:00
if ( config . backgroundColor ) {
2020-09-19 21:32:19 +02:00
customBackgroundColor = true ;
2021-01-23 19:03:55 +01:00
let backgroundColorIsGradient = BDFDB . ObjectUtils . is ( config . backgroundColor ) ;
let backgroundColor = ! backgroundColorIsGradient ? BDFDB . ColorUtils . convert ( config . backgroundColor , "RGBA" ) : BDFDB . ColorUtils . createGradient ( config . backgroundColor ) ;
style = ( style ? ( style + " " ) : "" ) + ` background: ${ backgroundColor } !important; border-color: ${ backgroundColorIsGradient ? BDFDB . ColorUtils . convert ( config . backgroundColor [ type == "left" ? 100 : 0 ] , "RGBA" ) : backgroundColor } !important; ` ;
2020-09-19 21:32:19 +02:00
}
if ( style ) tooltip . style = style ;
if ( zIndexed ) {
2021-01-23 19:03:55 +01:00
itemLayer . style . setProperty ( "z-index" , config . zIndex || 1002 , "important" ) ;
tooltip . style . setProperty ( "z-index" , config . zIndex || 1002 , "important" ) ;
tooltipContent . style . setProperty ( "z-index" , config . zIndex || 1002 , "important" ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-23 19:03:55 +01:00
if ( typeof config . width == "number" && config . width > 196 ) {
tooltip . style . setProperty ( "width" , ` ${ config . width } px ` , "important" ) ;
tooltip . style . setProperty ( "max-width" , ` ${ config . width } px ` , "important" ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-23 19:03:55 +01:00
if ( typeof config . maxWidth == "number" && config . maxWidth > 196 ) {
tooltip . style . setProperty ( "max-width" , ` ${ config . maxWidth } px ` , "important" ) ;
2020-09-19 21:32:19 +02:00
}
2020-09-23 07:51:49 +02:00
if ( customBackgroundColor ) BDFDB . DOMUtils . addClass ( tooltip , BDFDB . disCN . tooltipcustom ) ;
2021-01-23 19:03:55 +01:00
else if ( config . color && BDFDB . disCN [ "tooltip" + config . color . toLowerCase ( ) ] ) BDFDB . DOMUtils . addClass ( tooltip , BDFDB . disCN [ "tooltip" + config . color . toLowerCase ( ) ] ) ;
2021-01-09 16:20:58 +01:00
else BDFDB . DOMUtils . addClass ( tooltip , BDFDB . disCN . tooltipprimary ) ;
2020-09-19 21:32:19 +02:00
2021-01-23 19:03:55 +01:00
if ( config . list || BDFDB . ObjectUtils . is ( config . guild ) ) BDFDB . DOMUtils . addClass ( tooltip , BDFDB . disCN . tooltiplistitem ) ;
2020-09-19 21:32:19 +02:00
2020-11-17 17:24:56 +01:00
let mouseMove = e => {
let parent = e . target . parentElement . querySelector ( ":hover" ) ;
if ( parent && anker != parent && ! anker . contains ( parent ) ) itemLayer . removeTooltip ( ) ;
} ;
let mouseLeave = e => { itemLayer . removeTooltip ( ) ; } ;
2021-01-23 19:03:55 +01:00
if ( ! config . perssist ) {
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mousemove" , mouseMove ) ;
document . addEventListener ( "mouseleave" , mouseLeave ) ;
}
2020-09-19 21:32:19 +02:00
let observer = new MutationObserver ( changes => changes . forEach ( change => {
let nodes = Array . from ( change . removedNodes ) ;
2020-11-17 17:24:56 +01:00
if ( nodes . indexOf ( itemLayer ) > - 1 || nodes . indexOf ( anker ) > - 1 || nodes . some ( n => n . contains ( anker ) ) ) itemLayer . removeTooltip ( ) ;
2020-09-19 21:32:19 +02:00
} ) ) ;
2020-11-19 16:51:14 +01:00
observer . observe ( document . body , { subtree : true , childList : true } ) ;
2020-09-19 21:32:19 +02:00
( tooltip . setText = itemLayer . setText = newText => {
2021-01-23 19:03:55 +01:00
if ( BDFDB . ObjectUtils . is ( config . guild ) ) {
2021-02-06 17:53:02 +01:00
let voiceChannels = LibraryModules . GuildChannelStore . getChannels ( config . guild . id ) [ BDFDB . DiscordConstants . ChannelTypes . GUILD _VOICE ] . map ( c => c . channel . id ) ;
2021-01-23 19:03:55 +01:00
let streamOwnerIds = LibraryModules . StreamUtils . getAllApplicationStreams ( ) . filter ( app => app . guildId === config . guild . id ) . map ( app => app . ownerId ) || [ ] ;
2020-09-19 21:32:19 +02:00
let streamOwners = streamOwnerIds . map ( ownerId => LibraryModules . UserStore . getUser ( ownerId ) ) . filter ( n => n ) ;
2021-02-06 17:53:02 +01:00
let connectedUsers = BDFDB . ObjectUtils . toArray ( LibraryModules . VoiceUtils . getVoiceStates ( config . guild . id ) ) . map ( state => voiceChannels . includes ( state . channelId ) && state . channelId != config . guild . afkChannelId && ! streamOwnerIds . includes ( state . userId ) && LibraryModules . UserStore . getUser ( state . userId ) ) . filter ( n => n ) ;
2021-02-13 21:56:48 +01:00
2021-01-23 19:03:55 +01:00
let tooltipText = config . guild . toString ( ) ;
if ( fontColorIsGradient ) tooltipText = ` <span style="pointer-events: none; -webkit-background-clip: text !important; color: transparent !important; background-image: ${ BDFDB . ColorUtils . createGradient ( config . fontColor ) } !important;"> ${ BDFDB . StringUtils . htmlEscape ( tooltipText ) } </span> ` ;
2021-02-13 21:56:48 +01:00
let isMuted = LibraryModules . MutedUtils . isMuted ( config . guild . id ) ;
let muteConfig = LibraryModules . MutedUtils . getMuteConfig ( config . guild . id ) ;
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . render ( BDFDB . ReactUtils . createElement ( BDFDB . ReactUtils . Fragment , {
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tooltiprow , BDFDB . disCN . tooltiprowguildname ) ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . Badge , {
2021-01-23 19:03:55 +01:00
guild : config . guild ,
2020-09-19 21:32:19 +02:00
size : LibraryModules . StringUtils . cssValueToNumber ( DiscordClassModules . TooltipGuild . iconSize ) ,
className : BDFDB . disCN . tooltiprowicon
} ) ,
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tooltipguildnametext , ( connectedUsers . length || streamOwners . length ) && BDFDB . disCN . tooltipguildnametextlimitedsize ) ,
2021-01-23 19:03:55 +01:00
children : fontColorIsGradient || config . html ? BDFDB . ReactUtils . elementToReact ( BDFDB . DOMUtils . create ( tooltipText ) ) : tooltipText
2020-09-19 21:32:19 +02:00
} ) ,
]
} ) ,
newText && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tooltiprow , BDFDB . disCN . tooltiprowextra ) ,
children : newText
} ) ,
connectedUsers . length && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . tooltiprow ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : InternalComponents . LibraryComponents . SvgIcon . Names . SPEAKER ,
className : BDFDB . disCN . tooltipactivityicon
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . UserSummaryItem , {
users : connectedUsers ,
max : 6
} )
]
} ) ,
streamOwners . length && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . tooltiprow ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : InternalComponents . LibraryComponents . SvgIcon . Names . STREAM ,
className : BDFDB . disCN . tooltipactivityicon
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . UserSummaryItem , {
users : streamOwners ,
max : 6
} )
]
2021-02-13 21:56:48 +01:00
} ) ,
2021-02-13 21:59:38 +01:00
isMuted && muteConfig && ( muteConfig . end _time == null ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextElement , {
2021-02-13 22:19:19 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tooltipmutetext , ( connectedUsers . length || streamOwners . length ) && BDFDB . disCN . tooltipmutetextwithactivity ) ,
2021-02-13 21:56:48 +01:00
size : InternalComponents . LibraryComponents . TextElement . Sizes . SIZE _12 ,
color : InternalComponents . LibraryComponents . TextElement . Colors . MUTED ,
children : BDFDB . LanguageUtils . LanguageStrings . VOICE _CHANNEL _MUTED
} ) : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . MutedText , {
2021-02-13 22:19:19 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tooltipmutetext , ( connectedUsers . length || streamOwners . length ) && BDFDB . disCN . tooltipmutetextwithactivity ) ,
2021-02-13 21:56:48 +01:00
muteConfig : muteConfig
} ) )
2020-09-19 21:32:19 +02:00
] . filter ( n => n )
} ) , tooltipContent ) ;
}
else {
2021-01-23 19:03:55 +01:00
if ( fontColorIsGradient ) tooltipContent . innerHTML = ` <span style="pointer-events: none; -webkit-background-clip: text !important; color: transparent !important; background-image: ${ BDFDB . ColorUtils . createGradient ( config . fontColor ) } !important;"> ${ BDFDB . StringUtils . htmlEscape ( newText ) } </span> ` ;
2021-01-25 15:39:41 +01:00
else if ( config . html ) tooltipContent . innerHTML = newText ;
2020-09-19 21:32:19 +02:00
else tooltipContent . innerText = newText ;
}
} ) ( text ) ;
( tooltip . removeTooltip = itemLayer . removeTooltip = _ => {
2020-11-17 17:24:56 +01:00
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseleave" , mouseLeave ) ;
2020-09-19 21:32:19 +02:00
BDFDB . DOMUtils . remove ( itemLayer ) ;
2020-11-17 17:24:56 +01:00
BDFDB . ArrayUtils . remove ( Tooltips , id ) ;
observer . disconnect ( ) ;
2020-09-19 21:32:19 +02:00
if ( zIndexed ) BDFDB . DOMUtils . remove ( itemLayerContainer ) ;
2021-01-23 19:03:55 +01:00
if ( typeof config . onHide == "function" ) config . onHide ( itemLayer , anker ) ;
2020-09-19 21:32:19 +02:00
} ) ;
( tooltip . update = itemLayer . update = newText => {
if ( newText ) tooltip . setText ( newText ) ;
2020-09-23 07:51:49 +02:00
let left , top ;
const tRects = BDFDB . DOMUtils . getRects ( anker ) ;
const iRects = BDFDB . DOMUtils . getRects ( itemLayer ) ;
const aRects = BDFDB . DOMUtils . getRects ( document . querySelector ( BDFDB . dotCN . appmount ) ) ;
const positionOffsets = { height : 10 , width : 10 } ;
2021-01-23 19:03:55 +01:00
const offset = typeof config . offset == "number" ? config . offset : 0 ;
2020-09-19 21:32:19 +02:00
switch ( type ) {
case "top" :
top = tRects . top - iRects . height - positionOffsets . height + 2 - offset ;
left = tRects . left + ( tRects . width - iRects . width ) / 2 ;
break ;
case "bottom" :
top = tRects . top + tRects . height + positionOffsets . height - 2 + offset ;
left = tRects . left + ( tRects . width - iRects . width ) / 2 ;
break ;
case "left" :
top = tRects . top + ( tRects . height - iRects . height ) / 2 ;
left = tRects . left - iRects . width - positionOffsets . width + 2 - offset ;
break ;
case "right" :
top = tRects . top + ( tRects . height - iRects . height ) / 2 ;
left = tRects . left + tRects . width + positionOffsets . width - 2 + offset ;
break ;
}
itemLayer . style . setProperty ( "top" , ` ${ top } px ` , "important" ) ;
itemLayer . style . setProperty ( "left" , ` ${ left } px ` , "important" ) ;
tooltipPointer . style . removeProperty ( "margin-left" ) ;
tooltipPointer . style . removeProperty ( "margin-top" ) ;
if ( type == "top" || type == "bottom" ) {
if ( left < 0 ) {
itemLayer . style . setProperty ( "left" , "5px" , "important" ) ;
tooltipPointer . style . setProperty ( "margin-left" , ` ${ left - 10 } px ` , "important" ) ;
}
else {
2020-09-23 07:51:49 +02:00
const rightMargin = aRects . width - ( left + iRects . width ) ;
2020-09-19 21:32:19 +02:00
if ( rightMargin < 0 ) {
itemLayer . style . setProperty ( "left" , ` ${ aRects . width - iRects . width - 5 } px ` , "important" ) ;
tooltipPointer . style . setProperty ( "margin-left" , ` ${ - 1 * rightMargin } px ` , "important" ) ;
}
}
}
else if ( type == "left" || type == "right" ) {
if ( top < 0 ) {
2020-09-23 07:51:49 +02:00
const bRects = BDFDB . DOMUtils . getRects ( document . querySelector ( BDFDB . dotCN . titlebar ) ) ;
2020-09-23 07:54:14 +02:00
const barCorrection = ( bRects . width || 0 ) >= Math . round ( 75 * window . outerWidth / aRects . width ) ? ( bRects . height + 5 ) : 0 ;
2020-09-23 07:51:49 +02:00
itemLayer . style . setProperty ( "top" , ` ${ 5 + barCorrection } px ` , "important" ) ;
tooltipPointer . style . setProperty ( "margin-top" , ` ${ top - 10 - barCorrection } px ` , "important" ) ;
2020-09-19 21:32:19 +02:00
}
else {
2020-09-23 07:51:49 +02:00
const bottomMargin = aRects . height - ( top + iRects . height ) ;
2020-09-19 21:32:19 +02:00
if ( bottomMargin < 0 ) {
itemLayer . style . setProperty ( "top" , ` ${ aRects . height - iRects . height - 5 } px ` , "important" ) ;
tooltipPointer . style . setProperty ( "margin-top" , ` ${ - 1 * bottomMargin } px ` , "important" ) ;
}
}
}
} ) ( ) ;
2021-01-23 19:03:55 +01:00
if ( config . delay ) {
2020-09-19 21:32:19 +02:00
BDFDB . DOMUtils . toggle ( itemLayer ) ;
BDFDB . TimeUtils . timeout ( _ => {
BDFDB . DOMUtils . toggle ( itemLayer ) ;
2021-01-23 19:03:55 +01:00
if ( typeof config . onShow == "function" ) config . onShow ( itemLayer , anker ) ;
} , config . delay ) ;
2020-09-19 21:32:19 +02:00
}
else {
2021-01-23 19:03:55 +01:00
if ( typeof config . onShow == "function" ) config . onShow ( itemLayer , anker ) ;
2020-09-19 21:32:19 +02:00
}
return itemLayer ;
} ;
InternalBDFDB . findModule = function ( type , cachestring , filter , getExport ) {
2020-11-19 16:51:14 +01:00
if ( ! BDFDB . ObjectUtils . is ( Cache . modules [ type ] ) ) Cache . modules [ type ] = { module : { } , export : { } } ;
2020-09-19 21:32:19 +02:00
if ( getExport && Cache . modules [ type ] . export [ cachestring ] ) return Cache . modules [ type ] . export [ cachestring ] ;
else if ( ! getExport && Cache . modules [ type ] . module [ cachestring ] ) return Cache . modules [ type ] . module [ cachestring ] ;
else {
let m = BDFDB . ModuleUtils . find ( filter , getExport ) ;
if ( m ) {
if ( getExport ) Cache . modules [ type ] . export [ cachestring ] = m ;
else Cache . modules [ type ] . module [ cachestring ] = m ;
return m ;
}
else BDFDB . LogUtils . warn ( ` ${ cachestring } [ ${ type } ] not found in WebModules ` ) ;
}
} ;
InternalBDFDB . getWebModuleReq = function ( ) {
if ( ! InternalBDFDB . getWebModuleReq . req ) {
const id = "BDFDB-WebModules" ;
const req = window . webpackJsonp . push ( [ [ ] , { [ id ] : ( module , exports , req ) => module . exports = req } , [ [ id ] ] ] ) ;
delete req . m [ id ] ;
delete req . c [ id ] ;
InternalBDFDB . getWebModuleReq . req = req ;
}
return InternalBDFDB . getWebModuleReq . req ;
} ;
BDFDB . ModuleUtils = { } ;
BDFDB . ModuleUtils . find = function ( filter , getExport ) {
getExport = typeof getExport != "boolean" ? true : getExport ;
let req = InternalBDFDB . getWebModuleReq ( ) ;
for ( let i in req . c ) if ( req . c . hasOwnProperty ( i ) ) {
let m = req . c [ i ] . exports ;
if ( m && ( typeof m == "object" || typeof m == "function" ) && filter ( m ) ) return getExport ? m : req . c [ i ] ;
if ( m && m . _ _esModule ) {
for ( let j in m ) if ( m [ j ] && ( typeof m [ j ] == "object" || typeof m [ j ] == "function" ) && filter ( m [ j ] ) ) return getExport ? m [ j ] : req . c [ i ] ;
if ( m . default && ( typeof m . default == "object" || typeof m . default == "function" ) ) for ( let j in m . default ) if ( m . default [ j ] && ( typeof m . default [ j ] == "object" || typeof m . default [ j ] == "function" ) && filter ( m . default [ j ] ) ) return getExport ? m . default [ j ] : req . c [ i ] ;
}
}
for ( let i in req . m ) if ( req . m . hasOwnProperty ( i ) ) {
let m = req . m [ i ] ;
if ( m && typeof m == "function" && filter ( m ) ) {
if ( req . c [ i ] ) return getExport ? req . c [ i ] . exports : req . c [ i ] ;
else {
let resolved = { } ;
req . m [ i ] ( resolved , null , req ) ;
return getExport ? resolved . exports : resolved ;
}
}
}
} ;
BDFDB . ModuleUtils . findByProperties = function ( ... properties ) {
properties = properties . flat ( 10 ) ;
let getExport = properties . pop ( ) ;
if ( typeof getExport != "boolean" ) {
properties . push ( getExport ) ;
getExport = true ;
}
return InternalBDFDB . findModule ( "prop" , JSON . stringify ( properties ) , m => properties . every ( prop => m [ prop ] !== undefined ) , getExport ) ;
} ;
BDFDB . ModuleUtils . findByName = function ( name , getExport ) {
return InternalBDFDB . findModule ( "name" , JSON . stringify ( name ) , m => m . displayName === name || m . render && m . render . displayName === name , typeof getExport != "boolean" ? true : getExport ) ;
} ;
BDFDB . ModuleUtils . findByString = function ( ... strings ) {
strings = strings . flat ( 10 ) ;
let getExport = strings . pop ( ) ;
if ( typeof getExport != "boolean" ) {
strings . push ( getExport ) ;
getExport = true ;
}
return InternalBDFDB . findModule ( "string" , JSON . stringify ( strings ) , m => strings . every ( string => typeof m == "function" && ( m . toString ( ) . indexOf ( string ) > - 1 || typeof m . _ _originalMethod == "function" && m . _ _originalMethod . toString ( ) . indexOf ( string ) > - 1 || typeof m . _ _originalFunction == "function" && m . _ _originalFunction . toString ( ) . indexOf ( string ) > - 1 ) || BDFDB . ObjectUtils . is ( m ) && typeof m . type == "function" && m . type . toString ( ) . indexOf ( string ) > - 1 ) , getExport ) ;
} ;
BDFDB . ModuleUtils . findByPrototypes = function ( ... protoProps ) {
protoProps = protoProps . flat ( 10 ) ;
let getExport = protoProps . pop ( ) ;
if ( typeof getExport != "boolean" ) {
protoProps . push ( getExport ) ;
getExport = true ;
}
return InternalBDFDB . findModule ( "proto" , JSON . stringify ( protoProps ) , m => m . prototype && protoProps . every ( prop => m . prototype [ prop ] !== undefined ) , getExport ) ;
} ;
InternalBDFDB . forceInitiateProcess = function ( pluginDataObjs , instance , type ) {
pluginDataObjs = [ pluginDataObjs ] . flat ( 10 ) . filter ( n => n ) ;
if ( pluginDataObjs . length && instance && type ) {
let forceRender = false ;
for ( let pluginData of pluginDataObjs ) {
let plugin = pluginData . plugin == BDFDB && InternalBDFDB || pluginData . plugin , methodNames = [ ] ;
for ( let patchType in plugin . patchedModules ) {
if ( plugin . patchedModules [ patchType ] [ type ] ) methodNames . push ( plugin . patchedModules [ patchType ] [ type ] ) ;
}
methodNames = BDFDB . ArrayUtils . removeCopies ( methodNames ) . flat ( 10 ) . filter ( n => n ) ;
if ( methodNames . includes ( "componentDidMount" ) ) InternalBDFDB . initiateProcess ( plugin , type , {
instance : instance ,
methodname : "componentDidMount" ,
patchtypes : pluginData . patchTypes [ type ]
} ) ;
if ( methodNames . includes ( "render" ) ) forceRender = true ;
else if ( ! forceRender && methodNames . includes ( "componentDidUpdate" ) ) InternalBDFDB . initiateProcess ( plugin , type , {
instance : instance ,
methodname : "componentDidUpdate" ,
patchtypes : pluginData . patchTypes [ type ]
} ) ;
}
if ( forceRender ) BDFDB . ReactUtils . forceUpdate ( instance ) ;
}
} ;
InternalBDFDB . initiateProcess = function ( plugin , type , e ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( BDFDB . ObjectUtils . is ( plugin ) && ! plugin . stopping && e . instance ) {
type = LibraryModules . StringUtils . upperCaseFirstChar ( type . split ( " _ _ " ) [ 1 ] || type ) . replace ( /[^A-z0-9]|_/g , "" ) ;
if ( typeof plugin [ ` process ${ type } ` ] == "function" ) {
if ( typeof e . methodname == "string" && ( e . methodname . indexOf ( "componentDid" ) == 0 || e . methodname . indexOf ( "componentWill" ) == 0 ) ) {
e . node = BDFDB . ReactUtils . findDOMNode ( e . instance ) ;
if ( e . node ) return plugin [ ` process ${ type } ` ] ( e ) ;
else BDFDB . TimeUtils . timeout ( _ => {
e . node = BDFDB . ReactUtils . findDOMNode ( e . instance ) ;
if ( e . node ) return plugin [ ` process ${ type } ` ] ( e ) ;
} ) ;
}
else if ( e . returnvalue || e . patchtypes . includes ( "before" ) ) return plugin [ ` process ${ type } ` ] ( e ) ;
}
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . patchObserverData = { observer : null , data : { } } ;
2020-09-19 21:32:19 +02:00
InternalBDFDB . patchPlugin = function ( plugin ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ObjectUtils . is ( plugin . patchedModules ) ) return ;
BDFDB . PatchUtils . unpatch ( plugin ) ;
let patchedModules = { } ;
for ( let patchType in plugin . patchedModules ) for ( let type in plugin . patchedModules [ patchType ] ) {
if ( ! patchedModules [ type ] ) patchedModules [ type ] = { } ;
patchedModules [ type ] [ patchType ] = plugin . patchedModules [ patchType ] [ type ] ;
}
for ( let type in patchedModules ) {
let pluginData = { plugin : plugin , patchTypes : patchedModules [ type ] } ;
let unmappedType = type . split ( " _ _ " ) [ 1 ] || type ;
let config = {
classNames : [ InternalData . ModuleUtilsConfig . Finder [ unmappedType ] && InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . class ] . flat ( 10 ) . filter ( n => DiscordClasses [ n ] ) ,
stringFind : InternalData . ModuleUtilsConfig . Finder [ unmappedType ] && InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . strings ,
propertyFind : InternalData . ModuleUtilsConfig . Finder [ unmappedType ] && InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . props ,
specialFilter : InternalData . ModuleUtilsConfig . Finder [ unmappedType ] && InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . special && InternalBDFDB . createFilter ( InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . special ) ,
memoComponent : InternalData . ModuleUtilsConfig . MemoComponent . includes ( unmappedType ) ,
2020-11-16 16:26:22 +01:00
subRender : InternalData . ModuleUtilsConfig . SubRender . includes ( unmappedType ) ,
2020-09-19 21:32:19 +02:00
forceObserve : InternalData . ModuleUtilsConfig . ForceObserve . includes ( unmappedType ) ,
nonRender : BDFDB . ObjectUtils . toArray ( pluginData . patchTypes ) . flat ( 10 ) . filter ( n => n && ! InternalData . ModuleUtilsConfig . InstanceFunctions . includes ( n ) ) . length > 0 ,
2021-02-04 21:24:35 +01:00
exported : InternalData . ModuleUtilsConfig . Finder [ unmappedType ] && InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . exported || false ,
2020-09-19 21:32:19 +02:00
mapped : InternalData . ModuleUtilsConfig . PatchMap [ type ]
} ;
2020-09-25 21:34:18 +02:00
config . ignoreCheck = ! ! ( config . codeFind || config . propertyFind || config . specialFilter || config . nonRender || config . memoComponent ) ;
2020-09-19 21:32:19 +02:00
config . nonPrototype = InternalData . ModuleUtilsConfig . NonPrototype . includes ( unmappedType ) || ! ! ( config . codeFind || config . propertyFind || config . nonRender ) ;
let component = InternalData . ModuleUtilsConfig . LoadedInComponents [ type ] && BDFDB . ObjectUtils . get ( InternalComponents , InternalData . ModuleUtilsConfig . LoadedInComponents [ type ] ) ;
2021-02-04 21:24:35 +01:00
if ( component ) InternalBDFDB . patchComponent ( pluginData , config . nonRender ? ( BDFDB . ModuleUtils . find ( m => m == component , config . exported ) || { } ) . exports : component , type , config ) ;
2020-09-19 21:32:19 +02:00
else {
let mappedType = config . mapped ? config . mapped + " _ _ " + type : type ;
let name = mappedType . split ( " _ _ " ) [ 0 ] ;
if ( config . mapped ) {
for ( let patchType in plugin . patchedModules ) if ( plugin . patchedModules [ patchType ] [ type ] ) {
plugin . patchedModules [ patchType ] [ mappedType ] = plugin . patchedModules [ patchType ] [ type ] ;
delete plugin . patchedModules [ patchType ] [ type ] ;
}
}
2021-02-04 21:24:35 +01:00
let patchSpecial = ( func , argument ) => {
let module = BDFDB . ModuleUtils [ func ] ( argument , config . exported ) ;
let exports = module && ! config . exported && module . exports || module ;
exports && InternalBDFDB . patchComponent ( pluginData , config . memoComponent ? exports . default : exports , mappedType , config ) ;
} ;
2020-09-19 21:32:19 +02:00
if ( config . classNames . length ) InternalBDFDB . checkForInstance ( pluginData , mappedType , config ) ;
2021-02-04 21:24:35 +01:00
else if ( config . stringFind ) patchSpecial ( "findByString" , config . stringFind ) ;
else if ( config . propertyFind ) patchSpecial ( "findByProperties" , config . propertyFind ) ;
else if ( config . nonRender ) patchSpecial ( "findByName" , name ) ;
2021-01-28 17:47:49 +01:00
else InternalBDFDB . patchComponent ( pluginData , BDFDB . ModuleUtils . findByName ( name ) , mappedType , config ) ;
2020-09-19 21:32:19 +02:00
}
}
} ;
2021-01-28 17:47:49 +01:00
InternalBDFDB . patchComponent = function ( pluginDataObjs , instance , type , config ) {
2020-09-19 21:32:19 +02:00
pluginDataObjs = [ pluginDataObjs ] . flat ( 10 ) . filter ( n => n ) ;
if ( pluginDataObjs . length && instance ) {
let name = type . split ( " _ _ " ) [ 0 ] ;
2020-11-26 09:53:49 +01:00
instance = instance [ BDFDB . ReactUtils . instanceKey ] && instance [ BDFDB . ReactUtils . instanceKey ] . type ? instance [ BDFDB . ReactUtils . instanceKey ] . type : instance ;
2020-11-19 16:51:14 +01:00
instance = config . ignoreCheck || BDFDB . ReactUtils . isCorrectInstance ( instance , name ) || InternalData . ModuleUtilsConfig . LoadedInComponents [ type ] ? instance : ( BDFDB . ReactUtils . findConstructor ( instance , name ) || BDFDB . ReactUtils . findConstructor ( instance , name , { up : true } ) ) ;
2020-09-19 21:32:19 +02:00
if ( instance ) {
2020-11-26 09:53:49 +01:00
instance = instance [ BDFDB . ReactUtils . instanceKey ] && instance [ BDFDB . ReactUtils . instanceKey ] . type ? instance [ BDFDB . ReactUtils . instanceKey ] . type : instance ;
2020-09-19 21:32:19 +02:00
let toBePatched = config . nonPrototype ? instance : instance . prototype ;
2020-11-16 10:55:23 +01:00
toBePatched = config . subRender && toBePatched ? toBePatched . type : toBePatched ;
2020-09-19 21:32:19 +02:00
for ( let pluginData of pluginDataObjs ) for ( let patchType in pluginData . patchTypes ) {
let patchMethods = { } ;
patchMethods [ patchType ] = e => {
return InternalBDFDB . initiateProcess ( pluginData . plugin , type , {
2020-11-19 16:51:14 +01:00
instance : e . thisObject && window != e . thisObject ? e . thisObject : { props : e . methodArguments [ 0 ] } ,
2020-09-19 21:32:19 +02:00
returnvalue : e . returnValue ,
methodname : e . originalMethodName ,
patchtypes : [ patchType ]
} ) ;
} ;
2020-11-16 10:55:23 +01:00
BDFDB . PatchUtils . patch ( pluginData . plugin , toBePatched , config . subRender ? "render" : pluginData . patchTypes [ patchType ] , patchMethods ) ;
2020-09-19 21:32:19 +02:00
}
}
}
} ;
InternalBDFDB . createFilter = function ( config ) {
return ins => ins && config . every ( prop => {
let value = BDFDB . ObjectUtils . get ( ins , prop . path ) ;
return value && ( ! prop . value || [ prop . value ] . flat ( 10 ) . filter ( n => typeof n == "string" ) . some ( n => value . toUpperCase ( ) . indexOf ( n . toUpperCase ( ) ) == 0 ) ) ;
} ) && ins . return . type ;
} ;
InternalBDFDB . checkEle = function ( pluginDataObjs , ele , type , config ) {
pluginDataObjs = [ pluginDataObjs ] . flat ( 10 ) . filter ( n => n ) ;
let unmappedType = type . split ( " _ _ " ) [ 1 ] || type ;
let ins = BDFDB . ReactUtils . getInstance ( ele ) ;
if ( typeof config . specialFilter == "function" ) {
let component = config . specialFilter ( ins ) ;
if ( component ) {
if ( config . nonRender ) {
let exports = ( BDFDB . ModuleUtils . find ( m => m == component , false ) || { } ) . exports ;
2021-01-28 17:47:49 +01:00
InternalBDFDB . patchComponent ( pluginDataObjs , exports && config . memoComponent ? exports . default : exports , type , config ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-28 17:47:49 +01:00
else InternalBDFDB . patchComponent ( pluginDataObjs , component , type , config ) ;
2020-09-19 21:32:19 +02:00
BDFDB . PatchUtils . forceAllUpdates ( pluginDataObjs . map ( n => n . plugin ) , type ) ;
return true ;
}
}
else if ( InternalBDFDB . isCorrectPatchInstance ( ins , type ) ) {
2021-01-28 17:47:49 +01:00
InternalBDFDB . patchComponent ( pluginDataObjs , ins , type , config ) ;
2020-09-19 21:32:19 +02:00
BDFDB . PatchUtils . forceAllUpdates ( pluginDataObjs . map ( n => n . plugin ) , type ) ;
return true ;
}
return false ;
} ;
InternalBDFDB . checkForInstance = function ( pluginData , type , config ) {
const app = document . querySelector ( BDFDB . dotCN . app ) , bdSettings = document . querySelector ( "#bd-settingspane-container .scroller" ) ;
let instanceFound = false ;
if ( ! config . forceObserve ) {
if ( app ) {
2020-11-19 16:51:14 +01:00
let appIns = BDFDB . ReactUtils . findConstructor ( app , type , { unlimited : true } ) || BDFDB . ReactUtils . findConstructor ( app , type , { unlimited : true , up : true } ) ;
2021-01-28 17:47:49 +01:00
if ( appIns && ( instanceFound = true ) ) InternalBDFDB . patchComponent ( pluginData , appIns , type , config ) ;
2020-09-19 21:32:19 +02:00
}
if ( ! instanceFound && bdSettings ) {
2020-11-19 16:51:14 +01:00
let bdSettingsIns = BDFDB . ReactUtils . findConstructor ( bdSettings , type , { unlimited : true } ) ;
2021-01-28 17:47:49 +01:00
if ( bdSettingsIns && ( instanceFound = true ) ) InternalBDFDB . patchComponent ( pluginData , bdSettingsIns , type , config ) ;
2020-09-19 21:32:19 +02:00
}
}
if ( ! instanceFound ) {
let elementFound = false , classes = config . classNames . map ( n => BDFDB . disCN [ n ] ) , selector = config . classNames . map ( n => BDFDB . dotCN [ n ] ) . join ( ", " ) ;
for ( let ele of document . querySelectorAll ( selector ) ) {
elementFound = InternalBDFDB . checkEle ( pluginData , ele , type , config ) ;
if ( elementFound ) break ;
}
if ( ! elementFound ) {
if ( ! InternalBDFDB . patchObserverData . observer ) {
2020-09-23 00:03:17 +02:00
let appMount = document . querySelector ( BDFDB . dotCN . appmount ) ;
if ( appMount ) {
2020-09-19 21:32:19 +02:00
InternalBDFDB . patchObserverData . observer = new MutationObserver ( cs => { cs . forEach ( c => { c . addedNodes . forEach ( n => {
if ( ! n || ! n . tagName ) return ;
for ( let type in InternalBDFDB . patchObserverData . data ) if ( ! InternalBDFDB . patchObserverData . data [ type ] . found ) {
let ele = null ;
if ( ( ele = BDFDB . DOMUtils . containsClass ( n , ... InternalBDFDB . patchObserverData . data [ type ] . classes ) ? n : n . querySelector ( InternalBDFDB . patchObserverData . data [ type ] . selector ) ) != null ) {
2020-09-23 00:03:17 +02:00
InternalBDFDB . patchObserverData . data [ type ] . found = InternalBDFDB . checkEle ( InternalBDFDB . patchObserverData . data [ type ] . plugins , ele , type , InternalBDFDB . patchObserverData . data [ type ] . config ) ;
2020-09-19 21:32:19 +02:00
if ( InternalBDFDB . patchObserverData . data [ type ] . found ) {
delete InternalBDFDB . patchObserverData . data [ type ] ;
if ( BDFDB . ObjectUtils . isEmpty ( InternalBDFDB . patchObserverData . data ) ) {
InternalBDFDB . patchObserverData . observer . disconnect ( ) ;
InternalBDFDB . patchObserverData . observer = null ;
}
}
}
}
} ) ; } ) ; } ) ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . patchObserverData . observer . observe ( appMount , { childList : true , subtree : true } ) ;
2020-09-19 21:32:19 +02:00
}
}
2020-11-19 16:51:14 +01:00
if ( ! InternalBDFDB . patchObserverData . data [ type ] ) InternalBDFDB . patchObserverData . data [ type ] = { selector , classes , found : false , config , plugins : [ ] } ;
2020-09-19 21:32:19 +02:00
InternalBDFDB . patchObserverData . data [ type ] . plugins . push ( pluginData ) ;
}
}
} ;
InternalBDFDB . isCorrectPatchInstance = function ( instance , name ) {
if ( ! instance ) return false ;
2020-11-26 09:53:49 +01:00
instance = instance [ BDFDB . ReactUtils . instanceKey ] && instance [ BDFDB . ReactUtils . instanceKey ] . type ? instance [ BDFDB . ReactUtils . instanceKey ] . type : instance ;
2020-11-19 16:51:14 +01:00
instance = BDFDB . ReactUtils . isCorrectInstance ( instance , name ) ? instance : ( BDFDB . ReactUtils . findConstructor ( instance , name ) || BDFDB . ReactUtils . findConstructor ( instance , name , { up : true } ) ) ;
2020-09-19 21:32:19 +02:00
return ! ! instance ;
} ;
BDFDB . PatchUtils = { } ;
BDFDB . PatchUtils . isPatched = function ( plugin , module , methodName ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! plugin || ! BDFDB . ObjectUtils . is ( module ) || ! module . BDFDB _patches || ! methodName ) return false ;
const pluginId = ( typeof plugin === "string" ? plugin : plugin . name ) . toLowerCase ( ) ;
return pluginId && module [ methodName ] && module [ methodName ] . _ _is _BDFDB _patched && module . BDFDB _patches [ methodName ] && BDFDB . ObjectUtils . toArray ( module . BDFDB _patches [ methodName ] ) . some ( patchObj => BDFDB . ObjectUtils . toArray ( patchObj ) . some ( priorityObj => Object . keys ( priorityObj ) . includes ( pluginId ) ) ) ;
} ;
BDFDB . PatchUtils . patch = function ( plugin , module , methodNames , patchMethods , config = { } ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! plugin || ! BDFDB . ObjectUtils . is ( module ) || ! methodNames || ! BDFDB . ObjectUtils . is ( patchMethods ) ) return null ;
patchMethods = BDFDB . ObjectUtils . filter ( patchMethods , type => InternalData . ModuleUtilsConfig . PatchTypes . includes ( type ) , true ) ;
if ( BDFDB . ObjectUtils . isEmpty ( patchMethods ) ) return null ;
const pluginName = typeof plugin === "string" ? plugin : plugin . name ;
const pluginId = pluginName . toLowerCase ( ) ;
const patchPriority = BDFDB . ObjectUtils . is ( plugin ) && ! isNaN ( plugin . patchPriority ) ? ( plugin . patchPriority < 0 ? 0 : ( plugin . patchPriority > 10 ? 10 : Math . round ( plugin . patchPriority ) ) ) : 5 ;
if ( ! BDFDB . ObjectUtils . is ( module . BDFDB _patches ) ) module . BDFDB _patches = { } ;
methodNames = [ methodNames ] . flat ( 10 ) . filter ( n => n ) ;
let cancel = _ => { BDFDB . PatchUtils . unpatch ( plugin , module , methodNames ) ; } ;
for ( let methodName of methodNames ) if ( module [ methodName ] == null || typeof module [ methodName ] == "function" ) {
if ( ! module . BDFDB _patches [ methodName ] || config . force && ( ! module [ methodName ] || ! module [ methodName ] . _ _is _BDFDB _patched ) ) {
if ( ! module . BDFDB _patches [ methodName ] ) {
module . BDFDB _patches [ methodName ] = { } ;
for ( let type of InternalData . ModuleUtilsConfig . PatchTypes ) module . BDFDB _patches [ methodName ] [ type ] = { } ;
}
if ( ! module [ methodName ] ) module [ methodName ] = ( _ => { } ) ;
const originalMethod = module [ methodName ] ;
module . BDFDB _patches [ methodName ] . originalMethod = originalMethod ;
module [ methodName ] = function ( ) {
let callInstead = false , stopCall = false ;
const data = {
thisObject : this ,
methodArguments : arguments ,
originalMethod : originalMethod ,
originalMethodName : methodName ,
callOriginalMethod : _ => { if ( ! stopCall ) data . returnValue = data . originalMethod . apply ( data . thisObject , data . methodArguments ) } ,
callOriginalMethodAfterwards : _ => { callInstead = true ; } ,
stopOriginalMethodCall : _ => { stopCall = true ; }
} ;
if ( module . BDFDB _patches && module . BDFDB _patches [ methodName ] ) {
for ( let priority in module . BDFDB _patches [ methodName ] . before ) for ( let id in BDFDB . ObjectUtils . sort ( module . BDFDB _patches [ methodName ] . before [ priority ] ) ) {
BDFDB . TimeUtils . suppress ( module . BDFDB _patches [ methodName ] . before [ priority ] [ id ] , ` "before" callback of ${ methodName } in ${ module . constructor ? ( module . constructor . displayName || module . constructor . name ) : "module" } ` , module . BDFDB _patches [ methodName ] . before [ priority ] [ id ] . pluginName ) ( data ) ;
}
if ( ! module . BDFDB _patches || ! module . BDFDB _patches [ methodName ] ) return methodName == "render" && data . returnValue === undefined ? null : data . returnValue ;
let hasInsteadPatches = BDFDB . ObjectUtils . toArray ( module . BDFDB _patches [ methodName ] . instead ) . some ( priorityObj => ! BDFDB . ObjectUtils . isEmpty ( priorityObj ) ) ;
if ( hasInsteadPatches ) for ( let priority in module . BDFDB _patches [ methodName ] . instead ) for ( let id in BDFDB . ObjectUtils . sort ( module . BDFDB _patches [ methodName ] . instead [ priority ] ) ) {
let tempReturn = BDFDB . TimeUtils . suppress ( module . BDFDB _patches [ methodName ] . instead [ priority ] [ id ] , ` "instead" callback of ${ methodName } in ${ module . constructor ? ( module . constructor . displayName || module . constructor . name ) : "module" } ` , module . BDFDB _patches [ methodName ] . instead [ priority ] [ id ] . pluginName ) ( data ) ;
if ( tempReturn !== undefined ) data . returnValue = tempReturn ;
}
if ( ( ! hasInsteadPatches || callInstead ) && ! stopCall ) BDFDB . TimeUtils . suppress ( data . callOriginalMethod , ` originalMethod of ${ methodName } in ${ module . constructor ? ( module . constructor . displayName || module . constructor . name ) : "module" } ` ) ( ) ;
if ( ! module . BDFDB _patches || ! module . BDFDB _patches [ methodName ] ) return methodName == "render" && data . returnValue === undefined ? null : data . returnValue ;
for ( let priority in module . BDFDB _patches [ methodName ] . after ) for ( let id in BDFDB . ObjectUtils . sort ( module . BDFDB _patches [ methodName ] . after [ priority ] ) ) {
let tempReturn = BDFDB . TimeUtils . suppress ( module . BDFDB _patches [ methodName ] . after [ priority ] [ id ] , ` "after" callback of ${ methodName } in ${ module . constructor ? ( module . constructor . displayName || module . constructor . name ) : "module" } ` , module . BDFDB _patches [ methodName ] . after [ priority ] [ id ] . pluginName ) ( data ) ;
if ( tempReturn !== undefined ) data . returnValue = tempReturn ;
}
}
else BDFDB . TimeUtils . suppress ( data . callOriginalMethod , ` originalMethod of ${ methodName } in ${ module . constructor ? module . constructor . displayName || module . constructor . name : "module" } ` ) ( ) ;
callInstead = false , stopCall = false ;
2021-01-06 11:46:34 +01:00
return ( methodName == "render" || methodName == "default" ) && data . returnValue === undefined ? null : data . returnValue ;
2020-09-19 21:32:19 +02:00
} ;
for ( let key of Object . keys ( originalMethod ) ) module [ methodName ] [ key ] = originalMethod [ key ] ;
if ( ! module [ methodName ] . _ _originalFunction ) {
let realOriginalMethod = originalMethod . _ _originalMethod || originalMethod . _ _originalFunction || originalMethod ;
if ( typeof realOriginalMethod == "function" ) {
module [ methodName ] . _ _originalFunction = realOriginalMethod ;
module [ methodName ] . toString = _ => realOriginalMethod . toString ( ) ;
}
}
module [ methodName ] . _ _is _BDFDB _patched = true ;
}
for ( let type in patchMethods ) if ( typeof patchMethods [ type ] == "function" ) {
if ( ! BDFDB . ObjectUtils . is ( module . BDFDB _patches [ methodName ] [ type ] [ patchPriority ] ) ) module . BDFDB _patches [ methodName ] [ type ] [ patchPriority ] = { } ;
module . BDFDB _patches [ methodName ] [ type ] [ patchPriority ] [ pluginId ] = ( ... args ) => {
if ( config . once || ! plugin . started ) cancel ( ) ;
return patchMethods [ type ] ( ... args ) ;
} ;
module . BDFDB _patches [ methodName ] [ type ] [ patchPriority ] [ pluginId ] . pluginName = pluginName ;
}
}
if ( BDFDB . ObjectUtils . is ( plugin ) && ! config . once && ! config . noCache ) {
if ( ! BDFDB . ArrayUtils . is ( plugin . patchCancels ) ) plugin . patchCancels = [ ] ;
plugin . patchCancels . push ( cancel ) ;
}
return cancel ;
} ;
BDFDB . PatchUtils . unpatch = function ( plugin , module , methodNames ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! module && ! methodNames ) {
if ( BDFDB . ObjectUtils . is ( plugin ) && BDFDB . ArrayUtils . is ( plugin . patchCancels ) ) while ( plugin . patchCancels . length ) ( plugin . patchCancels . pop ( ) ) ( ) ;
}
else {
if ( ! BDFDB . ObjectUtils . is ( module ) || ! module . BDFDB _patches ) return ;
const pluginId = ! plugin ? null : ( typeof plugin === "string" ? plugin : plugin . name ) . toLowerCase ( ) ;
if ( methodNames ) {
for ( let methodName of [ methodNames ] . flat ( 10 ) . filter ( n => n ) ) if ( module [ methodName ] && module . BDFDB _patches [ methodName ] ) unpatch ( methodName , pluginId ) ;
}
else for ( let patchedMethod of module . BDFDB _patches ) unpatch ( patchedMethod , pluginId ) ;
}
function unpatch ( funcName , pluginId ) {
for ( let type of InternalData . ModuleUtilsConfig . PatchTypes ) {
if ( pluginId ) for ( let priority in module . BDFDB _patches [ funcName ] [ type ] ) {
delete module . BDFDB _patches [ funcName ] [ type ] [ priority ] [ pluginId ] ;
if ( BDFDB . ObjectUtils . isEmpty ( module . BDFDB _patches [ funcName ] [ type ] [ priority ] ) ) delete module . BDFDB _patches [ funcName ] [ type ] [ priority ] ;
}
else delete module . BDFDB _patches [ funcName ] [ type ] ;
}
if ( BDFDB . ObjectUtils . isEmpty ( BDFDB . ObjectUtils . filter ( module . BDFDB _patches [ funcName ] , key => InternalData . ModuleUtilsConfig . PatchTypes . includes ( key ) && ! BDFDB . ObjectUtils . isEmpty ( module . BDFDB _patches [ funcName ] [ key ] ) , true ) ) ) {
module [ funcName ] = module . BDFDB _patches [ funcName ] . originalMethod ;
delete module . BDFDB _patches [ funcName ] ;
if ( BDFDB . ObjectUtils . isEmpty ( module . BDFDB _patches ) ) delete module . BDFDB _patches ;
}
}
} ;
BDFDB . PatchUtils . forceAllUpdates = function ( plugins , selectedTypes ) {
plugins = [ plugins ] . flat ( 10 ) . map ( n => n == BDFDB && InternalBDFDB || n ) . filter ( n => BDFDB . ObjectUtils . is ( n . patchedModules ) ) ;
if ( plugins . length ) {
const app = document . querySelector ( BDFDB . dotCN . app ) ;
const bdSettings = document . querySelector ( "#bd-settingspane-container > *" ) ;
if ( app ) {
selectedTypes = [ selectedTypes ] . flat ( 10 ) . filter ( n => n ) . map ( type => type && InternalData . ModuleUtilsConfig . PatchMap [ type ] ? InternalData . ModuleUtilsConfig . PatchMap [ type ] + " _ _ " + type : type ) ;
let updateData = { } ;
for ( let plugin of plugins ) {
updateData [ plugin . name ] = {
filteredModules : [ ] ,
specialModules : [ ] ,
specialModuleTypes : [ ] ,
patchTypes : { }
} ;
for ( let patchType in plugin . patchedModules ) for ( let type in plugin . patchedModules [ patchType ] ) {
let methodNames = [ plugin . patchedModules [ patchType ] [ type ] ] . flat ( 10 ) . filter ( n => n ) ;
if ( BDFDB . ArrayUtils . includes ( methodNames , "componentDidMount" , "componentDidUpdate" , "render" , false ) && ( ! selectedTypes . length || selectedTypes . includes ( type ) ) ) {
let unmappedType = type . split ( " _ _ " ) [ 1 ] || type ;
let selector = [ InternalData . ModuleUtilsConfig . Finder [ unmappedType ] ] . flat ( 10 ) . filter ( n => DiscordClasses [ n ] ) . map ( n => BDFDB . dotCN [ n ] ) . join ( ", " ) ;
let specialFilter = InternalData . ModuleUtilsConfig . Finder [ unmappedType ] && InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . special && InternalBDFDB . createFilter ( InternalData . ModuleUtilsConfig . Finder [ unmappedType ] . special ) ;
if ( selector && typeof specialFilter == "function" ) {
for ( let ele of document . querySelectorAll ( selector ) ) {
let constro = specialFilter ( BDFDB . ReactUtils . getInstance ( ele ) ) ;
if ( constro ) {
updateData [ plugin . name ] . specialModules . push ( [ type , constro ] ) ;
updateData [ plugin . name ] . specialModuleTypes . push ( type ) ;
break ;
}
}
}
else updateData [ plugin . name ] . filteredModules . push ( type ) ;
let name = type . split ( " _ _ " ) [ 0 ] ;
if ( ! updateData [ plugin . name ] . patchTypes [ name ] ) updateData [ plugin . name ] . patchTypes [ name ] = [ ] ;
updateData [ plugin . name ] . patchTypes [ name ] . push ( patchType ) ;
}
}
}
let updateDataArray = BDFDB . ObjectUtils . toArray ( updateData ) ;
if ( BDFDB . ArrayUtils . sum ( updateDataArray . map ( n => n . filteredModules . length + n . specialModules . length ) ) ) {
try {
let filteredModules = BDFDB . ArrayUtils . removeCopies ( updateDataArray . map ( n => n . filteredModules ) . flat ( 10 ) ) ;
let specialModules = BDFDB . ArrayUtils . removeCopies ( updateDataArray . map ( n => n . specialModules ) . flat ( 10 ) ) ;
2021-01-30 12:36:34 +01:00
const appInsDown = BDFDB . ReactUtils . findOwner ( app , { name : filteredModules , type : specialModules , all : true , unlimited : true , group : true } ) ;
const appInsUp = BDFDB . ReactUtils . findOwner ( app , { name : filteredModules , type : specialModules , all : true , unlimited : true , group : true , up : true } ) ;
2020-09-19 21:32:19 +02:00
for ( let type in appInsDown ) {
2020-11-19 16:51:14 +01:00
let filteredPlugins = plugins . filter ( n => updateData [ n . name ] . filteredModules . includes ( type ) || updateData [ n . name ] . specialModuleTypes . includes ( type ) ) . map ( n => ( { plugin : n , patchTypes : updateData [ n . name ] . patchTypes } ) ) ;
2020-09-19 21:32:19 +02:00
for ( let ins of appInsDown [ type ] ) InternalBDFDB . forceInitiateProcess ( filteredPlugins , ins , type ) ;
}
for ( let type in appInsUp ) {
2020-11-19 16:51:14 +01:00
let filteredPlugins = plugins . filter ( n => updateData [ n . name ] . filteredModules . includes ( type ) || updateData [ n . name ] . specialModuleTypes . includes ( type ) ) . map ( n => ( { plugin : n , patchTypes : updateData [ n . name ] . patchTypes } ) ) ;
2020-09-19 21:32:19 +02:00
for ( let ins of appInsUp [ type ] ) InternalBDFDB . forceInitiateProcess ( filteredPlugins , ins , type ) ;
}
if ( bdSettings ) {
2020-11-19 16:51:14 +01:00
const bdSettingsIns = BDFDB . ReactUtils . findOwner ( bdSettings , { name : filteredModules , type : specialModules , all : true , unlimited : true } ) ;
2020-09-19 21:32:19 +02:00
if ( bdSettingsIns . length ) {
2020-11-19 16:51:14 +01:00
const bdSettingsWrap = BDFDB . ReactUtils . findOwner ( BDFDB . ReactUtils . getInstance ( document . querySelector ( "#bd-settingspane-container > *" ) ) , { props : "onChange" , up : true } ) ;
2020-09-19 21:32:19 +02:00
if ( bdSettingsWrap && bdSettingsWrap . props && typeof bdSettingsWrap . props . onChange == "function" ) bdSettingsWrap . props . onChange ( bdSettingsWrap . props . type ) ;
}
}
}
catch ( err ) { BDFDB . LogUtils . error ( "Could not force update components! " + err , plugins . map ( n => n . name ) . join ( ", " ) ) ; }
}
}
}
} ;
BDFDB . DiscordConstants = BDFDB . ModuleUtils . findByProperties ( "Permissions" , "ActivityTypes" ) ;
for ( let name in InternalData . DiscordObjects ) {
if ( InternalData . DiscordObjects [ name ] . props ) DiscordObjects [ name ] = BDFDB . ModuleUtils . findByPrototypes ( InternalData . DiscordObjects [ name ] . props ) ;
else if ( InternalData . DiscordObjects [ name ] . protos ) DiscordObjects [ name ] = BDFDB . ModuleUtils . find ( m => m . prototype && InternalData . DiscordObjects [ name ] . protos . every ( proto => m . prototype [ proto ] && ( ! InternalData . DiscordObjects [ name ] . array || Array . isArray ( m . prototype [ proto ] ) ) ) ) ;
}
BDFDB . DiscordObjects = Object . assign ( { } , DiscordObjects ) ;
for ( let name of InternalData . LibraryRequires ) {
try { LibraryRequires [ name ] = require ( name ) ; } catch ( err ) { }
}
BDFDB . LibraryRequires = Object . assign ( { } , LibraryRequires ) ;
for ( let name in InternalData . LibraryModules ) {
if ( InternalData . LibraryModules [ name ] . props ) {
if ( InternalData . LibraryModules [ name ] . nonProps ) LibraryModules [ name ] = BDFDB . ModuleUtils . find ( m => InternalData . LibraryModules [ name ] . props . every ( prop => typeof m [ prop ] == "function" ) && InternalData . LibraryModules [ name ] . nonProps . every ( prop => typeof m [ prop ] != "function" ) ) ;
else LibraryModules [ name ] = BDFDB . ModuleUtils . findByProperties ( InternalData . LibraryModules [ name ] . props ) ;
}
}
if ( LibraryModules . KeyCodeUtils ) LibraryModules . KeyCodeUtils . getString = function ( keyArray ) {
return LibraryModules . KeyCodeUtils . toString ( [ keyArray ] . flat ( 10 ) . filter ( n => n ) . map ( keycode => [ BDFDB . DiscordConstants . KeyboardDeviceTypes . KEYBOARD _KEY , keycode , BDFDB . DiscordConstants . KeyboardEnvs . BROWSER ] ) , true ) ;
} ;
BDFDB . LibraryModules = Object . assign ( { } , LibraryModules ) ;
LibraryModules . React = BDFDB . ModuleUtils . findByProperties ( "createElement" , "cloneElement" ) ;
LibraryModules . ReactDOM = BDFDB . ModuleUtils . findByProperties ( "render" , "findDOMNode" ) ;
BDFDB . ReactUtils = Object . assign ( { } , LibraryModules . React , LibraryModules . ReactDOM ) ;
BDFDB . ReactUtils . childrenToArray = function ( parent ) {
if ( parent && parent . props && parent . props . children && ! BDFDB . ArrayUtils . is ( parent . props . children ) ) {
var child = parent . props . children ;
parent . props . children = [ ] ;
parent . props . children . push ( child ) ;
}
return parent . props . children ;
}
BDFDB . ReactUtils . createElement = function ( component , props = { } , errorWrap = false ) {
if ( component && component . defaultProps ) for ( let key in component . defaultProps ) if ( props [ key ] == null ) props [ key ] = component . defaultProps [ key ] ;
try {
let child = LibraryModules . React . createElement ( component || "div" , props ) || null ;
if ( errorWrap ) return LibraryModules . React . createElement ( InternalComponents . ErrorBoundary , { } , child ) || null ;
else return child ;
}
catch ( err ) { BDFDB . LogUtils . error ( "Could not create react element! " + err ) ; }
return null ;
} ;
BDFDB . ReactUtils . objectToReact = function ( obj ) {
if ( ! obj ) return null ;
else if ( typeof obj == "string" ) return obj ;
else if ( BDFDB . ObjectUtils . is ( obj ) ) return BDFDB . ReactUtils . createElement ( obj . type || obj . props && obj . props . href && "a" || "div" , ! obj . props ? { } : Object . assign ( { } , obj . props , {
children : obj . props . children ? BDFDB . ReactUtils . objectToReact ( obj . props . children ) : null
} ) ) ;
else if ( BDFDB . ArrayUtils . is ( obj ) ) return obj . map ( n => BDFDB . ReactUtils . objectToReact ( n ) ) ;
else return null ;
} ;
2020-11-12 15:40:12 +01:00
BDFDB . ReactUtils . markdownParse = function ( str ) {
if ( ! BDFDB . ReactUtils . markdownParse . parser || ! BDFDB . ReactUtils . markdownParse . render ) {
BDFDB . ReactUtils . markdownParse . parser = LibraryModules . SimpleMarkdownParser . parserFor ( LibraryModules . SimpleMarkdownParser . defaultRules ) ;
BDFDB . ReactUtils . markdownParse . render = LibraryModules . SimpleMarkdownParser . reactFor ( LibraryModules . SimpleMarkdownParser . ruleOutput ( LibraryModules . SimpleMarkdownParser . defaultRules , "react" ) ) ;
}
return BDFDB . ReactUtils . markdownParse . render ( BDFDB . ReactUtils . markdownParse . parser ( str , { inline : true } ) ) ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . elementToReact = function ( node , ref ) {
if ( BDFDB . ReactUtils . isValidElement ( node ) ) return node ;
else if ( ! Node . prototype . isPrototypeOf ( node ) ) return null ;
else if ( node . nodeType == Node . TEXT _NODE ) return node . nodeValue ;
let attributes = { } , importantStyles = [ ] ;
if ( typeof ref == "function" ) attributes . ref = ref ;
for ( let attr of node . attributes ) attributes [ attr . name ] = attr . value ;
if ( node . attributes . style ) attributes . style = BDFDB . ObjectUtils . filter ( node . style , n => node . style [ n ] && isNaN ( parseInt ( n ) ) , true ) ;
attributes . children = [ ] ;
if ( node . style && node . style . cssText ) for ( let propStr of node . style . cssText . split ( ";" ) ) if ( propStr . endsWith ( "!important" ) ) {
let key = propStr . split ( ":" ) [ 0 ] ;
let camelprop = key . replace ( /-([a-z]?)/g , ( m , g ) => g . toUpperCase ( ) ) ;
if ( attributes . style [ camelprop ] != null ) importantStyles . push ( key ) ;
}
for ( let child of node . childNodes ) attributes . children . push ( BDFDB . ReactUtils . elementToReact ( child ) ) ;
attributes . className = BDFDB . DOMUtils . formatClassName ( attributes . className , attributes . class ) ;
delete attributes . class ;
let reactEle = BDFDB . ReactUtils . createElement ( node . tagName , attributes ) ;
BDFDB . ReactUtils . forceStyle ( reactEle , importantStyles ) ;
return reactEle ;
} ;
BDFDB . ReactUtils . forceStyle = function ( reactEle , styles ) {
if ( ! BDFDB . ReactUtils . isValidElement ( reactEle ) || ! BDFDB . ObjectUtils . is ( reactEle . props . style ) || ! BDFDB . ArrayUtils . is ( styles ) || ! styles . length ) return null ;
let ref = reactEle . ref ;
reactEle . ref = instance => {
if ( typeof ref == "function" ) ref ( instance ) ;
let node = BDFDB . ReactUtils . findDOMNode ( instance ) ;
if ( Node . prototype . isPrototypeOf ( node ) ) for ( let key of styles ) {
let propValue = reactEle . props . style [ key . replace ( /-([a-z]?)/g , ( m , g ) => g . toUpperCase ( ) ) ] ;
if ( propValue != null ) node . style . setProperty ( key , propValue , "important" ) ;
}
} ;
return reactEle ;
} ;
BDFDB . ReactUtils . findChild = function ( nodeOrInstance , config ) {
if ( ! nodeOrInstance || ! BDFDB . ObjectUtils . is ( config ) || ! config . name && ! config . key && ! config . props && ! config . filter ) return config . all ? [ ] : null ;
let instance = Node . prototype . isPrototypeOf ( nodeOrInstance ) ? BDFDB . ReactUtils . getInstance ( nodeOrInstance ) : nodeOrInstance ;
if ( ! BDFDB . ObjectUtils . is ( instance ) && ! BDFDB . ArrayUtils . is ( instance ) ) return null ;
config . name = config . name && [ config . name ] . flat ( ) . filter ( n => n ) ;
config . key = config . key && [ config . key ] . flat ( ) . filter ( n => n ) ;
config . props = config . props && [ config . props ] . flat ( ) . filter ( n => n ) ;
config . filter = typeof config . filter == "function" && config . filter ;
let depth = - 1 ;
let start = performance . now ( ) ;
let maxDepth = config . unlimited ? 999999999 : ( config . depth === undefined ? 30 : config . depth ) ;
let maxTime = config . unlimited ? 999999999 : ( config . time === undefined ? 150 : config . time ) ;
let foundChildren = [ ] ;
let singleChild = getChild ( instance ) ;
if ( config . all ) {
for ( let i in foundChildren ) delete foundChildren [ i ] . BDFDBreactSearch ;
return foundChildren ;
}
else return singleChild ;
function getChild ( children ) {
let result = null ;
if ( ! children || depth >= maxDepth || performance . now ( ) - start >= maxTime ) return result ;
if ( ! BDFDB . ArrayUtils . is ( children ) ) {
if ( check ( children ) ) {
if ( config . all === undefined || ! config . all ) result = children ;
else if ( config . all ) {
if ( ! children . BDFDBreactSearch ) {
children . BDFDBreactSearch = true ;
foundChildren . push ( children ) ;
}
}
}
else if ( children . props && children . props . children ) {
depth ++ ;
result = getChild ( children . props . children ) ;
depth -- ;
}
}
else {
for ( let child of children ) if ( child ) {
if ( BDFDB . ArrayUtils . is ( child ) ) result = getChild ( child ) ;
else if ( check ( child ) ) {
if ( config . all === undefined || ! config . all ) result = child ;
else if ( config . all ) {
if ( ! child . BDFDBreactSearch ) {
child . BDFDBreactSearch = true ;
foundChildren . push ( child ) ;
}
}
}
else if ( child . props && child . props . children ) {
depth ++ ;
result = getChild ( child . props . children ) ;
depth -- ;
}
if ( result ) break ;
}
}
return result ;
}
function check ( instance ) {
if ( ! instance ) return false ;
let props = instance . stateNode ? instance . stateNode . props : instance . props ;
return instance . type && config . name && config . name . some ( name => BDFDB . ReactUtils . isCorrectInstance ( instance , name ) ) || config . key && config . key . some ( key => instance . key == key ) || props && config . props && config . props [ config . someProps ? "some" : "every" ] ( prop => BDFDB . ArrayUtils . is ( prop ) ? ( BDFDB . ArrayUtils . is ( prop [ 1 ] ) ? prop [ 1 ] . some ( checkValue => propCheck ( props , prop [ 0 ] , checkValue ) ) : propCheck ( props , prop [ 0 ] , prop [ 1 ] ) ) : props [ prop ] !== undefined ) || config . filter && config . filter ( instance ) ;
}
function propCheck ( props , key , value ) {
return key != null && props [ key ] != null && value != null && ( key == "className" ? ( " " + props [ key ] + " " ) . indexOf ( " " + value + " " ) > - 1 : BDFDB . equals ( props [ key ] , value ) ) ;
}
} ;
BDFDB . ReactUtils . setChild = function ( parent , stringOrChild ) {
if ( ! BDFDB . ReactUtils . isValidElement ( parent ) || ( ! BDFDB . ReactUtils . isValidElement ( stringOrChild ) && typeof stringOrChild != "string" && ! BDFDB . ArrayUtils . is ( stringOrChild ) ) ) return ;
let set = false ;
checkParent ( parent ) ;
function checkParent ( child ) {
if ( set ) return ;
if ( ! BDFDB . ArrayUtils . is ( child ) ) checkChild ( child ) ;
else for ( let subChild of child ) checkChild ( subChild ) ;
}
function checkChild ( child ) {
if ( ! BDFDB . ReactUtils . isValidElement ( child ) ) return ;
if ( BDFDB . ReactUtils . isValidElement ( child . props . children ) ) checkParent ( child . props . children ) ;
else if ( BDFDB . ArrayUtils . is ( child . props . children ) ) {
if ( child . props . children . every ( c => ! c || typeof c == "string" ) ) {
set = true ;
child . props . children = [ stringOrChild ] . flat ( 10 ) ;
}
else checkParent ( child . props . children ) ;
}
else {
set = true ;
child . props . children = stringOrChild ;
}
}
} ;
BDFDB . ReactUtils . findConstructor = function ( nodeOrInstance , types , config = { } ) {
if ( ! BDFDB . ObjectUtils . is ( config ) ) return null ;
if ( ! nodeOrInstance || ! types ) return config . all ? ( config . group ? { } : [ ] ) : null ;
let instance = Node . prototype . isPrototypeOf ( nodeOrInstance ) ? BDFDB . ReactUtils . getInstance ( nodeOrInstance ) : nodeOrInstance ;
if ( ! BDFDB . ObjectUtils . is ( instance ) ) return config . all ? ( config . group ? { } : [ ] ) : null ;
types = types && [ types ] . flat ( 10 ) . filter ( n => typeof n == "string" ) ;
if ( ! types . length ) return config . all ? ( config . group ? { } : [ ] ) : null ; ;
let depth = - 1 ;
let start = performance . now ( ) ;
let maxDepth = config . unlimited ? 999999999 : ( config . depth === undefined ? 30 : config . depth ) ;
let maxTime = config . unlimited ? 999999999 : ( config . time === undefined ? 150 : config . time ) ;
2020-11-26 09:53:49 +01:00
let whitelist = config . up ? {
return : true ,
sibling : true ,
default : true
} : {
child : true ,
sibling : true ,
default : true
} ;
whitelist [ BDFDB . ReactUtils . instanceKey ] = true ;
2020-09-19 21:32:19 +02:00
let foundConstructors = config . group ? { } : [ ] ;
let singleConstructor = getConstructor ( instance ) ;
if ( config . all ) {
for ( let i in foundConstructors ) {
if ( config . group ) for ( let j in foundConstructors [ i ] ) delete foundConstructors [ i ] [ j ] . BDFDBreactSearch ;
else delete foundConstructors [ i ] . BDFDBreactSearch ;
}
return foundConstructors ;
}
else return singleConstructor ;
function getConstructor ( instance ) {
depth ++ ;
let result = undefined ;
if ( instance && ! Node . prototype . isPrototypeOf ( instance ) && ! BDFDB . ReactUtils . getInstance ( instance ) && depth < maxDepth && performance . now ( ) - start < maxTime ) {
if ( instance . type && types . some ( name => BDFDB . ReactUtils . isCorrectInstance ( instance , name . split ( " _ _ " ) [ 0 ] ) ) ) {
if ( config . all === undefined || ! config . all ) result = instance . type ;
else if ( config . all ) {
if ( ! instance . type . BDFDBreactSearch ) {
instance . type . BDFDBreactSearch = true ;
if ( config . group ) {
if ( instance . type && ( instance . type . render && instance . type . render . displayName || instance . type . displayName || instance . type . name ) ) {
let group = config . name . find ( name => ( instance . type . render && instance . type . render . displayName || instance . type . displayName || instance . type . name || instance . type ) == name . split ( " _ _ " ) [ 0 ] ) || "Default" ;
if ( ! BDFDB . ArrayUtils . is ( foundConstructors [ group ] ) ) foundConstructors [ group ] = [ ] ;
foundConstructors [ group ] . push ( instance . stateNode ) ;
}
}
else foundConstructors . push ( instance . type ) ;
}
}
}
if ( result === undefined ) {
let keys = Object . getOwnPropertyNames ( instance ) ;
for ( let i = 0 ; result === undefined && i < keys . length ; i ++ ) {
let key = keys [ i ] ;
2021-02-09 13:05:30 +01:00
if ( key && whitelist [ key ] && ( typeof instance [ key ] === "object" || typeof instance [ key ] == "function" ) ) result = getConstructor ( instance [ key ] ) ;
2020-09-19 21:32:19 +02:00
}
}
}
depth -- ;
return result ;
}
} ;
BDFDB . ReactUtils . findDOMNode = function ( instance ) {
if ( Node . prototype . isPrototypeOf ( instance ) ) return instance ;
if ( ! instance || ! instance . updater || typeof instance . updater . isMounted !== "function" || ! instance . updater . isMounted ( instance ) ) return null ;
let node = LibraryModules . ReactDOM . findDOMNode ( instance ) || BDFDB . ObjectUtils . get ( instance , "child.stateNode" ) ;
return Node . prototype . isPrototypeOf ( node ) ? node : null ;
} ;
BDFDB . ReactUtils . findOwner = function ( nodeOrInstance , config ) {
if ( ! BDFDB . ObjectUtils . is ( config ) ) return null ;
2020-10-14 21:21:08 +02:00
if ( ! nodeOrInstance || ! config . name && ! config . type && ! config . key && ! config . props && ! config . filter ) return config . all ? ( config . group ? { } : [ ] ) : null ;
2020-09-19 21:32:19 +02:00
let instance = Node . prototype . isPrototypeOf ( nodeOrInstance ) ? BDFDB . ReactUtils . getInstance ( nodeOrInstance ) : nodeOrInstance ;
if ( ! BDFDB . ObjectUtils . is ( instance ) ) return config . all ? ( config . group ? { } : [ ] ) : null ;
config . name = config . name && [ config . name ] . flat ( ) . filter ( n => n ) ;
config . type = config . type && [ config . type ] . flat ( ) . filter ( n => n ) ;
config . key = config . key && [ config . key ] . flat ( ) . filter ( n => n ) ;
config . props = config . props && [ config . props ] . flat ( ) . filter ( n => n ) ;
2020-10-14 21:21:08 +02:00
config . filter = typeof config . filter == "function" && config . filter ;
2020-09-19 21:32:19 +02:00
let depth = - 1 ;
let start = performance . now ( ) ;
let maxDepth = config . unlimited ? 999999999 : ( config . depth === undefined ? 30 : config . depth ) ;
let maxTime = config . unlimited ? 999999999 : ( config . time === undefined ? 150 : config . time ) ;
2020-11-26 09:53:49 +01:00
let whitelist = config . up ? {
return : true ,
sibling : true ,
default : true
} : {
child : true ,
sibling : true ,
default : true
} ;
whitelist [ BDFDB . ReactUtils . instanceKey ] = true ;
2020-09-19 21:32:19 +02:00
let foundInstances = config . group ? { } : [ ] ;
let singleInstance = getOwner ( instance ) ;
if ( config . all ) {
for ( let i in foundInstances ) {
if ( config . group ) for ( let j in foundInstances [ i ] ) delete foundInstances [ i ] [ j ] . BDFDBreactSearch ;
else delete foundInstances [ i ] . BDFDBreactSearch ;
}
return foundInstances ;
}
else return singleInstance ;
function getOwner ( instance ) {
depth ++ ;
let result = undefined ;
if ( instance && ! Node . prototype . isPrototypeOf ( instance ) && ! BDFDB . ReactUtils . getInstance ( instance ) && depth < maxDepth && performance . now ( ) - start < maxTime ) {
let props = instance . stateNode ? instance . stateNode . props : instance . props ;
2020-10-14 21:21:08 +02:00
if ( instance . stateNode && ! Node . prototype . isPrototypeOf ( instance . stateNode ) && ( instance . type && config . name && config . name . some ( name => BDFDB . ReactUtils . isCorrectInstance ( instance , name . split ( " _ _ " ) [ 0 ] ) ) || instance . type && config . type && config . type . some ( type => BDFDB . ArrayUtils . is ( type ) ? instance . type === type [ 1 ] : instance . type === type ) || instance . key && config . key && config . key . some ( key => instance . key == key ) || props && config . props && config . props . every ( prop => BDFDB . ArrayUtils . is ( prop ) ? ( BDFDB . ArrayUtils . is ( prop [ 1 ] ) ? prop [ 1 ] . some ( checkValue => BDFDB . equals ( props [ prop [ 0 ] ] , checkValue ) ) : BDFDB . equals ( props [ prop [ 0 ] ] , prop [ 1 ] ) ) : props [ prop ] !== undefined ) ) || config . filter && config . filter ( instance ) ) {
2020-09-19 21:32:19 +02:00
if ( config . all === undefined || ! config . all ) result = instance . stateNode ;
else if ( config . all ) {
if ( ! instance . stateNode . BDFDBreactSearch ) {
instance . stateNode . BDFDBreactSearch = true ;
if ( config . group ) {
if ( config . name && instance . type && ( instance . type . render && instance . type . render . displayName || instance . type . displayName || instance . type . name || instance . type ) ) {
let group = config . name . find ( name => ( instance . type . render && instance . type . render . displayName || instance . type . displayName || instance . type . name || instance . type ) == name . split ( " _ _ " ) [ 0 ] ) || "Default" ;
if ( ! BDFDB . ArrayUtils . is ( foundInstances [ group ] ) ) foundInstances [ group ] = [ ] ;
foundInstances [ group ] . push ( instance . stateNode ) ;
}
else if ( config . type && instance . type ) {
let group = [ config . type . find ( t => BDFDB . ArrayUtils . is ( t ) && instance . type === t [ 1 ] ) ] . flat ( 10 ) [ 0 ] || "Default" ;
if ( ! BDFDB . ArrayUtils . is ( foundInstances [ group ] ) ) foundInstances [ group ] = [ ] ;
foundInstances [ group ] . push ( instance . stateNode ) ;
}
}
else foundInstances . push ( instance . stateNode ) ;
}
}
}
if ( result === undefined ) {
let keys = Object . getOwnPropertyNames ( instance ) ;
for ( let i = 0 ; result === undefined && i < keys . length ; i ++ ) {
let key = keys [ i ] ;
2021-02-09 13:05:30 +01:00
if ( key && whitelist [ key ] && ( typeof instance [ key ] === "object" || typeof instance [ key ] == "function" ) ) result = getOwner ( instance [ key ] ) ;
2020-09-19 21:32:19 +02:00
}
}
}
depth -- ;
return result ;
}
} ;
BDFDB . ReactUtils . findParent = function ( nodeOrInstance , config ) {
if ( ! nodeOrInstance || ! BDFDB . ObjectUtils . is ( config ) || ! config . name && ! config . key && ! config . props && ! config . filter ) return [ null , - 1 ] ;
let instance = Node . prototype . isPrototypeOf ( nodeOrInstance ) ? BDFDB . ReactUtils . getInstance ( nodeOrInstance ) : nodeOrInstance ;
2020-10-30 16:31:52 +01:00
if ( ! BDFDB . ObjectUtils . is ( instance ) && ! BDFDB . ArrayUtils . is ( instance ) || instance . props && typeof instance . props . children == "function" ) return [ null , - 1 ] ;
2020-09-19 21:32:19 +02:00
config . name = config . name && [ config . name ] . flat ( ) . filter ( n => n ) ;
config . key = config . key && [ config . key ] . flat ( ) . filter ( n => n ) ;
config . props = config . props && [ config . props ] . flat ( ) . filter ( n => n ) ;
config . filter = typeof config . filter == "function" && config . filter ;
let parent = firstArray = instance ;
while ( ! BDFDB . ArrayUtils . is ( firstArray ) && firstArray . props && firstArray . props . children ) firstArray = firstArray . props . children ;
if ( ! BDFDB . ArrayUtils . is ( firstArray ) ) {
if ( parent && parent . props ) {
parent . props . children = [ parent . props . children ] ;
firstArray = parent . props . children ;
}
else firstArray = [ ] ;
}
return getParent ( instance ) ;
function getParent ( children ) {
let result = [ firstArray , - 1 ] ;
if ( ! children ) return result ;
if ( ! BDFDB . ArrayUtils . is ( children ) ) {
if ( check ( children ) ) result = found ( children ) ;
else if ( children . props && children . props . children ) {
parent = children ;
result = getParent ( children . props . children ) ;
}
}
else {
for ( let i = 0 ; result [ 1 ] == - 1 && i < children . length ; i ++ ) if ( children [ i ] ) {
if ( BDFDB . ArrayUtils . is ( children [ i ] ) ) {
parent = children ;
result = getParent ( children [ i ] ) ;
}
else if ( check ( children [ i ] ) ) {
parent = children ;
result = found ( children [ i ] ) ;
}
else if ( children [ i ] . props && children [ i ] . props . children ) {
parent = children [ i ] ;
result = getParent ( children [ i ] . props . children ) ;
}
}
}
return result ;
}
function found ( child ) {
if ( BDFDB . ArrayUtils . is ( parent ) ) return [ parent , parent . indexOf ( child ) ] ;
else {
parent . props . children = [ ] ;
parent . props . children . push ( child ) ;
return [ parent . props . children , 0 ] ;
}
}
function check ( instance ) {
if ( ! instance ) return false ;
let props = instance . stateNode ? instance . stateNode . props : instance . props ;
return instance . type && config . name && config . name . some ( name => BDFDB . ReactUtils . isCorrectInstance ( instance , name ) ) || config . key && config . key . some ( key => instance . key == key ) || props && config . props && config . props [ config . someProps ? "some" : "every" ] ( prop => BDFDB . ArrayUtils . is ( prop ) ? ( BDFDB . ArrayUtils . is ( prop [ 1 ] ) ? prop [ 1 ] . some ( checkValue => propCheck ( props , prop [ 0 ] , checkValue ) ) : propCheck ( props , prop [ 0 ] , prop [ 1 ] ) ) : props [ prop ] !== undefined ) || config . filter && config . filter ( instance ) ;
}
function propCheck ( props , key , value ) {
return key != null && props [ key ] != null && value != null && ( key == "className" ? ( " " + props [ key ] + " " ) . indexOf ( " " + value + " " ) > - 1 : BDFDB . equals ( props [ key ] , value ) ) ;
}
} ;
BDFDB . ReactUtils . findProps = function ( nodeOrInstance , config ) {
if ( ! BDFDB . ObjectUtils . is ( config ) ) return null ;
if ( ! nodeOrInstance || ! config . name && ! config . key ) return null ;
let instance = Node . prototype . isPrototypeOf ( nodeOrInstance ) ? BDFDB . ReactUtils . getInstance ( nodeOrInstance ) : nodeOrInstance ;
if ( ! BDFDB . ObjectUtils . is ( instance ) ) return null ;
config . name = config . name && [ config . name ] . flat ( ) . filter ( n => n ) ;
config . key = config . key && [ config . key ] . flat ( ) . filter ( n => n ) ;
let depth = - 1 ;
let start = performance . now ( ) ;
let maxDepth = config . unlimited ? 999999999 : ( config . depth === undefined ? 30 : config . depth ) ;
let maxTime = config . unlimited ? 999999999 : ( config . time === undefined ? 150 : config . time ) ;
2020-11-26 09:53:49 +01:00
let whitelist = config . up ? {
return : true ,
sibling : true ,
default : true
} : {
child : true ,
sibling : true ,
default : true
} ;
whitelist [ BDFDB . ReactUtils . instanceKey ] = true ;
2020-09-19 21:32:19 +02:00
return findProps ( instance ) ;
function findProps ( instance ) {
depth ++ ;
let result = undefined ;
if ( instance && ! Node . prototype . isPrototypeOf ( instance ) && ! BDFDB . ReactUtils . getInstance ( instance ) && depth < maxDepth && performance . now ( ) - start < maxTime ) {
if ( instance . memoizedProps && ( instance . type && config . name && config . name . some ( name => BDFDB . ReactUtils . isCorrectInstance ( instance , name . split ( " _ _ " ) [ 0 ] ) ) || config . key && config . key . some ( key => instance . key == key ) ) ) result = instance . memoizedProps ;
if ( result === undefined ) {
let keys = Object . getOwnPropertyNames ( instance ) ;
for ( let i = 0 ; result === undefined && i < keys . length ; i ++ ) {
let key = keys [ i ] ;
2021-02-09 13:05:30 +01:00
if ( key && whitelist [ key ] && ( typeof instance [ key ] === "object" || typeof instance [ key ] == "function" ) ) result = findProps ( instance [ key ] ) ;
2020-09-19 21:32:19 +02:00
}
}
}
depth -- ;
return result ;
}
} ;
BDFDB . ReactUtils . findValue = function ( nodeOrInstance , searchKey , config = { } ) {
if ( ! BDFDB . ObjectUtils . is ( config ) ) return null ;
if ( ! nodeOrInstance || typeof searchKey != "string" ) return config . all ? [ ] : null ;
let instance = Node . prototype . isPrototypeOf ( nodeOrInstance ) ? BDFDB . ReactUtils . getInstance ( nodeOrInstance ) : nodeOrInstance ;
if ( ! BDFDB . ObjectUtils . is ( instance ) ) return config . all ? [ ] : null ;
2020-11-26 09:53:49 +01:00
instance = instance [ BDFDB . ReactUtils . instanceKey ] || instance ;
2020-09-19 21:32:19 +02:00
let depth = - 1 ;
let start = performance . now ( ) ;
let maxDepth = config . unlimited ? 999999999 : ( config . depth === undefined ? 30 : config . depth ) ;
let maxTime = config . unlimited ? 999999999 : ( config . time === undefined ? 150 : config . time ) ;
let whitelist = {
props : true ,
state : true ,
stateNode : true ,
updater : true ,
prototype : true ,
type : true ,
children : config . up ? false : true ,
memoizedProps : true ,
memoizedState : true ,
child : config . up ? false : true ,
return : config . up ? true : false ,
sibling : config . up ? false : true
} ;
let blacklist = {
contextSection : true
} ;
if ( BDFDB . ObjectUtils . is ( config . whitelist ) ) Object . assign ( whitelist , config . whiteList ) ;
if ( BDFDB . ObjectUtils . is ( config . blacklist ) ) Object . assign ( blacklist , config . blacklist ) ;
let foundKeys = [ ] ;
let singleKey = getKey ( instance ) ;
if ( config . all ) return foundKeys ;
else return singleKey ;
function getKey ( instance ) {
depth ++ ;
let result = undefined ;
if ( instance && ! Node . prototype . isPrototypeOf ( instance ) && ! BDFDB . ReactUtils . getInstance ( instance ) && depth < maxDepth && performance . now ( ) - start < maxTime ) {
let keys = Object . getOwnPropertyNames ( instance ) ;
for ( let i = 0 ; result === undefined && i < keys . length ; i ++ ) {
let key = keys [ i ] ;
if ( key && ! blacklist [ key ] ) {
let value = instance [ key ] ;
if ( searchKey === key && ( config . value === undefined || BDFDB . equals ( config . value , value ) ) ) {
if ( config . all === undefined || ! config . all ) result = value ;
else if ( config . all ) {
if ( config . noCopies === undefined || ! config . noCopies ) foundKeys . push ( value ) ;
else if ( config . noCopies ) {
let copy = false ;
for ( let foundKey of foundKeys ) if ( BDFDB . equals ( value , foundKey ) ) {
copy = true ;
break ;
}
if ( ! copy ) foundKeys . push ( value ) ;
}
}
}
2021-02-09 13:05:30 +01:00
else if ( ( typeof value === "object" || typeof value == "function" ) && ( whitelist [ key ] || key [ 0 ] == "." || ! isNaN ( key [ 0 ] ) ) ) result = getKey ( value ) ;
2020-09-19 21:32:19 +02:00
}
}
}
depth -- ;
return result ;
}
} ;
BDFDB . ReactUtils . forceUpdate = function ( ... instances ) {
for ( let ins of instances . flat ( 10 ) . filter ( n => n ) ) if ( ins . updater && typeof ins . updater . isMounted == "function" && ins . updater . isMounted ( ins ) ) ins . forceUpdate ( ) ;
} ;
BDFDB . ReactUtils . getInstance = function ( node ) {
if ( ! BDFDB . ObjectUtils . is ( node ) ) return null ;
2020-11-28 19:47:01 +01:00
return node [ Object . keys ( node ) . find ( key => key . startsWith ( "__reactInternalInstance" ) || key . startsWith ( "__reactFiber" ) ) ] ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . ReactUtils . isCorrectInstance = function ( instance , name ) {
return instance && ( ( instance . type && ( instance . type . render && instance . type . render . displayName === name || instance . type . displayName === name || instance . type . name === name || instance . type === name ) ) || instance . render && ( instance . render . displayName === name || instance . render . name === name ) || instance . displayName == name || instance . name === name ) ;
} ;
BDFDB . ReactUtils . render = function ( component , node ) {
if ( ! BDFDB . ReactUtils . isValidElement ( component ) || ! Node . prototype . isPrototypeOf ( node ) ) return ;
try {
LibraryModules . ReactDOM . render ( component , node ) ;
let observer = new MutationObserver ( changes => changes . forEach ( change => {
let nodes = Array . from ( change . removedNodes ) ;
if ( nodes . indexOf ( node ) > - 1 || nodes . some ( n => n . contains ( node ) ) ) {
observer . disconnect ( ) ;
BDFDB . ReactUtils . unmountComponentAtNode ( node ) ;
}
} ) ) ;
2020-11-19 16:51:14 +01:00
observer . observe ( document . body , { subtree : true , childList : true } ) ;
2020-09-19 21:32:19 +02:00
}
catch ( err ) { BDFDB . LogUtils . error ( "Could not render react element! " + err ) ; }
} ;
BDFDB . MessageUtils = { } ;
BDFDB . MessageUtils . rerenderAll = function ( instant ) {
2021-01-30 12:36:34 +01:00
BDFDB . TimeUtils . clear ( BDFDB . MessageUtils . rerenderAll . timeout ) ;
BDFDB . MessageUtils . rerenderAll . timeout = BDFDB . TimeUtils . timeout ( _ => {
2021-02-04 20:12:57 +01:00
let channel = LibraryModules . ChannelStore . getChannel ( LibraryModules . LastChannelStore . getChannelId ( ) ) ;
2020-09-19 21:32:19 +02:00
if ( channel ) {
if ( BDFDB . DMUtils . isDMChannel ( channel ) ) BDFDB . DMUtils . markAsRead ( channel ) ;
else BDFDB . ChannelUtils . markAsRead ( channel ) ;
}
2020-11-19 16:51:14 +01:00
let LayerProviderIns = BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . messageswrapper ) , { name : "LayerProvider" , unlimited : true , up : true } ) ;
2020-11-26 09:53:49 +01:00
let LayerProviderPrototype = BDFDB . ObjectUtils . get ( LayerProviderIns , ` ${ BDFDB . ReactUtils . instanceKey } .type.prototype ` ) ;
2020-09-19 21:32:19 +02:00
if ( LayerProviderIns && LayerProviderPrototype ) {
2021-01-30 12:36:34 +01:00
BDFDB . PatchUtils . patch ( { name : "BDFDB MessageUtils" } , LayerProviderPrototype , "render" , { after : e => {
e . returnValue . props . children = typeof e . returnValue . props . children == "function" ? ( _ => { return null ; } ) : [ ] ;
BDFDB . ReactUtils . forceUpdate ( LayerProviderIns ) ;
2020-09-19 21:32:19 +02:00
} } , { once : true } ) ;
BDFDB . ReactUtils . forceUpdate ( LayerProviderIns ) ;
}
} , instant ? 0 : 1000 ) ;
} ;
2020-10-06 12:40:59 +02:00
BDFDB . MessageUtils . openMenu = function ( message , e = mousePosition , slim = false ) {
2020-10-06 12:09:36 +02:00
if ( ! message ) return ;
let channel = LibraryModules . ChannelStore . getChannel ( message . channel _id ) ;
if ( channel ) LibraryModules . ContextMenuUtils . openContextMenu ( e , function ( e ) {
2020-11-19 16:51:14 +01:00
return BDFDB . ReactUtils . createElement ( ( BDFDB . ModuleUtils . findByName ( slim ? "MessageSearchResultContextMenu" : "MessageContextMenu" , false ) || { exports : { } } ) . exports . default , Object . assign ( { } , e , {
2020-10-06 12:09:36 +02:00
message : message ,
channel : channel
} ) ) ;
} ) ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . UserUtils = { } ;
BDFDB . UserUtils . is = function ( user ) {
return user && user instanceof BDFDB . DiscordObjects . User ;
} ;
var myDataUser = LibraryModules . CurrentUserStore && LibraryModules . CurrentUserStore . getCurrentUser ( ) ;
BDFDB . UserUtils . me = new Proxy ( myDataUser || { } , {
get : function ( list , item ) {
return ( myDataUser = LibraryModules . CurrentUserStore . getCurrentUser ( ) ) && myDataUser [ item ] ;
}
} ) ;
BDFDB . UserUtils . getStatus = function ( id = BDFDB . UserUtils . me . id ) {
id = typeof id == "number" ? id . toFixed ( ) : id ;
2020-09-23 19:55:13 +02:00
let activity = BDFDB . UserUtils . getActivity ( id ) ;
2020-09-19 21:32:19 +02:00
return activity && activity . type == BDFDB . DiscordConstants . ActivityTypes . STREAMING ? "streaming" : LibraryModules . StatusMetaUtils . getStatus ( id ) ;
} ;
2020-12-16 16:35:56 +01:00
BDFDB . UserUtils . getStatusColor = function ( status , useColor ) {
2020-09-19 21:32:19 +02:00
status = typeof status == "string" ? status . toLowerCase ( ) : null ;
switch ( status ) {
case "online" : return BDFDB . DiscordConstants . Colors . STATUS _GREEN ;
case "idle" : return BDFDB . DiscordConstants . Colors . STATUS _YELLOW ;
case "dnd" : return BDFDB . DiscordConstants . Colors . STATUS _RED ;
2020-12-16 16:35:56 +01:00
case "playing" : return useColor ? BDFDB . DiscordConstants . Colors . BRAND : "var(--bdfdb-blurple)" ;
2020-09-19 21:32:19 +02:00
case "listening" : return BDFDB . DiscordConstants . Colors . SPOTIFY ;
case "streaming" : return BDFDB . DiscordConstants . Colors . TWITCH ;
default : return BDFDB . DiscordConstants . Colors . STATUS _GREY ;
}
} ;
2020-09-23 19:55:13 +02:00
BDFDB . UserUtils . getActivity = function ( id = BDFDB . UserUtils . me . id ) {
2020-09-19 21:32:19 +02:00
for ( let activity of LibraryModules . StatusMetaUtils . getActivities ( id ) ) if ( activity . type != BDFDB . DiscordConstants . ActivityTypes . CUSTOM _STATUS ) return activity ;
return null ;
} ;
2021-01-15 20:30:31 +01:00
BDFDB . UserUtils . getCustomStatus = function ( id = BDFDB . UserUtils . me . id ) {
for ( let activity of LibraryModules . StatusMetaUtils . getActivities ( id ) ) if ( activity . type == BDFDB . DiscordConstants . ActivityTypes . CUSTOM _STATUS ) return activity ;
return null ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . UserUtils . getAvatar = function ( id = BDFDB . UserUtils . me . id ) {
2021-02-04 20:12:57 +01:00
let user = LibraryModules . UserStore . getUser ( id ) ;
2020-09-19 21:32:19 +02:00
if ( ! user ) return window . location . origin + "/assets/322c936a8c8be1b803cd94861bdfa868.png" ;
else return ( ( user . avatar ? "" : window . location . origin ) + LibraryModules . IconUtils . getUserAvatarURL ( user ) ) . split ( "?" ) [ 0 ] ;
} ;
BDFDB . UserUtils . can = function ( permission , id = BDFDB . UserUtils . me . id , channelId = LibraryModules . LastChannelStore . getChannelId ( ) ) {
if ( ! BDFDB . DiscordConstants . Permissions [ permission ] ) BDFDB . LogUtils . warn ( permission + " not found in Permissions" ) ;
else {
let channel = LibraryModules . ChannelStore . getChannel ( channelId ) ;
if ( channel ) return LibraryModules . PermissionRoleUtils . can ( BDFDB . DiscordConstants . Permissions [ permission ] , id , channel ) ;
}
return false ;
} ;
2021-02-04 20:12:57 +01:00
BDFDB . UserUtils . openMenu = function ( user , guildId , e = mousePosition ) {
if ( user && guildId ) LibraryModules . ContextMenuUtils . openContextMenu ( e , function ( e ) {
2020-11-19 16:51:14 +01:00
return BDFDB . ReactUtils . createElement ( ( BDFDB . ModuleUtils . findByName ( "GuildChannelUserContextMenu" , false ) || { exports : { } } ) . exports . default , Object . assign ( { } , e , {
2020-09-19 21:32:19 +02:00
user : user ,
guildId : guildId
} ) ) ;
} ) ;
} ;
BDFDB . GuildUtils = { } ;
BDFDB . GuildUtils . is = function ( guild ) {
if ( ! BDFDB . ObjectUtils . is ( guild ) ) return false ;
let keys = Object . keys ( guild ) ;
return guild instanceof BDFDB . DiscordObjects . Guild || Object . keys ( new BDFDB . DiscordObjects . Guild ( { } ) ) . every ( key => keys . indexOf ( key ) > - 1 ) ;
} ;
BDFDB . GuildUtils . getIcon = function ( id ) {
2021-02-04 20:12:57 +01:00
let guild = LibraryModules . GuildStore . getGuild ( id ) ;
if ( ! guild || ! guild . icon ) return "" ;
2020-09-19 21:32:19 +02:00
return LibraryModules . IconUtils . getGuildIconURL ( guild ) . split ( "?" ) [ 0 ] ;
} ;
BDFDB . GuildUtils . getBanner = function ( id ) {
2021-02-04 20:12:57 +01:00
let guild = LibraryModules . GuildStore . getGuild ( id ) ;
if ( ! guild || ! guild . banner ) return "" ;
2020-09-19 21:32:19 +02:00
return LibraryModules . IconUtils . getGuildBannerURL ( guild ) . split ( "?" ) [ 0 ] ;
} ;
BDFDB . GuildUtils . getFolder = function ( id ) {
2021-02-04 20:12:57 +01:00
return LibraryModules . FolderStore . guildFolders . filter ( n => n . folderId ) . find ( n => n . guildIds . includes ( id ) ) ;
2020-09-19 21:32:19 +02:00
} ;
2021-02-04 20:12:57 +01:00
BDFDB . GuildUtils . openMenu = function ( guild , e = mousePosition ) {
2020-09-19 21:32:19 +02:00
if ( guild ) LibraryModules . ContextMenuUtils . openContextMenu ( e , function ( e ) {
2020-11-19 16:51:14 +01:00
return BDFDB . ReactUtils . createElement ( ( BDFDB . ModuleUtils . findByName ( "GuildContextMenu" , false ) || { exports : { } } ) . exports . default , Object . assign ( { } , e , {
2020-09-19 21:32:19 +02:00
guild : guild
} ) ) ;
} ) ;
} ;
2021-02-04 20:12:57 +01:00
BDFDB . GuildUtils . markAsRead = function ( guildIds ) {
2021-02-05 13:33:05 +01:00
let channels = [ guildIds ] . flat ( 10 ) . filter ( id => id && typeof id == "string" && LibraryModules . GuildStore . getGuild ( id ) ) . map ( id => BDFDB . ObjectUtils . toArray ( LibraryModules . GuildChannelStore . getChannels ( id ) ) . flat ( 10 ) . filter ( n => BDFDB . ObjectUtils . is ( n ) ) . map ( n => n . channel && n . channel . id ) ) . flat ( ) . filter ( n => n ) ;
2021-02-04 20:12:57 +01:00
if ( channels . length ) BDFDB . ChannelUtils . markAsRead ( channels ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . GuildUtils . rerenderAll = function ( instant ) {
2021-01-30 12:36:34 +01:00
BDFDB . TimeUtils . clear ( BDFDB . GuildUtils . rerenderAll . timeout ) ;
BDFDB . GuildUtils . rerenderAll . timeout = BDFDB . TimeUtils . timeout ( _ => {
2020-11-19 16:51:14 +01:00
let GuildsIns = BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . app ) , { name : "Guilds" , unlimited : true } ) ;
2020-11-26 09:53:49 +01:00
let GuildsPrototype = BDFDB . ObjectUtils . get ( GuildsIns , ` ${ BDFDB . ReactUtils . instanceKey } .type.prototype ` ) ;
2020-09-19 21:32:19 +02:00
if ( GuildsIns && GuildsPrototype ) {
2020-10-30 16:10:32 +01:00
let injectPlaceholder = returnValue => {
let [ children , index ] = BDFDB . ReactUtils . findParent ( returnValue , { name : "ConnectedUnreadDMs" } ) ;
if ( index > - 1 ) children . splice ( index + 1 , 0 , BDFDB . ReactUtils . createElement ( "div" , { } ) ) ;
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . forceUpdate ( GuildsIns ) ;
2020-10-30 16:10:32 +01:00
} ;
2021-01-30 12:36:34 +01:00
BDFDB . PatchUtils . patch ( { name : "BDFDB GuildUtils" } , GuildsPrototype , "render" , { after : e => {
2020-10-30 16:10:32 +01:00
if ( typeof e . returnValue . props . children == "function" ) {
let childrenRender = e . returnValue . props . children ;
e . returnValue . props . children = ( ... args ) => {
let children = childrenRender ( ... args ) ;
injectPlaceholder ( children ) ;
return children ;
} ;
}
else injectPlaceholder ( e . returnValue ) ;
2020-09-19 21:32:19 +02:00
} } , { once : true } ) ;
BDFDB . ReactUtils . forceUpdate ( GuildsIns ) ;
}
} , instant ? 0 : 1000 ) ;
} ;
BDFDB . FolderUtils = { } ;
BDFDB . FolderUtils . getId = function ( div ) {
if ( ! Node . prototype . isPrototypeOf ( div ) || ! BDFDB . ReactUtils . getInstance ( div ) ) return ;
div = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . guildfolderwrapper , div ) ;
if ( ! div ) return ;
2020-11-19 16:51:14 +01:00
return BDFDB . ReactUtils . findValue ( div , "folderId" , { up : true } ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . FolderUtils . getDefaultName = function ( folderId ) {
2021-02-04 20:12:57 +01:00
let folder = LibraryModules . FolderStore . getGuildFolderById ( folderId ) ;
2020-09-19 21:32:19 +02:00
if ( ! folder ) return "" ;
let rest = 2 * BDFDB . DiscordConstants . MAX _GUILD _FOLDER _NAME _LENGTH ;
2021-02-04 20:12:57 +01:00
let names = [ ] , allNames = folder . guildIds . map ( guildId => ( LibraryModules . GuildStore . getGuild ( guildId ) || { } ) . name ) . filter ( n => n ) ;
2020-09-19 21:32:19 +02:00
for ( let name of allNames ) if ( name . length < rest || names . length === 0 ) {
names . push ( name ) ;
rest -= name . length ;
}
return names . join ( ", " ) + ( names . length < allNames . length ? ", ..." : "" ) ;
} ;
BDFDB . ChannelUtils = { } ;
BDFDB . ChannelUtils . is = function ( channel ) {
if ( ! BDFDB . ObjectUtils . is ( channel ) ) return false ;
let keys = Object . keys ( channel ) ;
return channel instanceof BDFDB . DiscordObjects . Channel || Object . keys ( new BDFDB . DiscordObjects . Channel ( { } ) ) . every ( key => keys . indexOf ( key ) > - 1 ) ;
} ;
BDFDB . ChannelUtils . isTextChannel = function ( channelOrId ) {
let channel = typeof channelOrId == "string" ? LibraryModules . ChannelStore . getChannel ( channelOrId ) : channelOrId ;
return BDFDB . ObjectUtils . is ( channel ) && ( channel . type == BDFDB . DiscordConstants . ChannelTypes . GUILD _TEXT || channel . type == BDFDB . DiscordConstants . ChannelTypes . GUILD _STORE || channel . type == BDFDB . DiscordConstants . ChannelTypes . GUILD _ANNOUNCEMENT ) ;
} ;
2021-02-04 20:12:57 +01:00
BDFDB . ChannelUtils . markAsRead = function ( channelIds ) {
let unreadChannels = [ channelIds ] . flat ( 10 ) . filter ( id => id && typeof id == "string" && BDFDB . ChannelUtils . isTextChannel ( id ) && ( LibraryModules . UnreadChannelUtils . hasUnread ( id ) || LibraryModules . UnreadChannelUtils . getMentionCount ( id ) > 0 ) ) . map ( id => ( {
2021-02-04 18:22:04 +01:00
channelId : id ,
messageId : LibraryModules . UnreadChannelUtils . lastMessageId ( id )
} ) ) ;
2020-09-19 21:32:19 +02:00
if ( unreadChannels . length ) LibraryModules . AckUtils . bulkAck ( unreadChannels ) ;
} ;
2020-10-30 15:42:08 +01:00
BDFDB . ChannelUtils . rerenderAll = function ( instant ) {
2021-01-30 12:36:34 +01:00
BDFDB . TimeUtils . clear ( BDFDB . ChannelUtils . rerenderAll . timeout ) ;
BDFDB . ChannelUtils . rerenderAll . timeout = BDFDB . TimeUtils . timeout ( _ => {
2020-11-19 16:51:14 +01:00
let ChannelsIns = BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . guildchannels ) , { name : "Channels" , unlimited : true } ) ;
2020-11-26 09:53:49 +01:00
let ChannelsPrototype = BDFDB . ObjectUtils . get ( ChannelsIns , ` ${ BDFDB . ReactUtils . instanceKey } .type.prototype ` ) ;
2020-10-30 15:42:08 +01:00
if ( ChannelsIns && ChannelsPrototype ) {
2021-01-30 12:36:34 +01:00
BDFDB . PatchUtils . patch ( { name : "BDFDB ChannelUtils" } , ChannelsPrototype , "render" , { after : e => {
2020-10-30 15:54:55 +01:00
e . returnValue . props . children = typeof e . returnValue . props . children == "function" ? ( _ => { return null ; } ) : [ ] ;
2020-10-30 15:42:08 +01:00
BDFDB . ReactUtils . forceUpdate ( ChannelsIns ) ;
} } , { once : true } ) ;
BDFDB . ReactUtils . forceUpdate ( ChannelsIns ) ;
}
} , instant ? 0 : 1000 ) ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . DMUtils = { } ;
2021-02-04 20:12:57 +01:00
BDFDB . DMUtils . isDMChannel = function ( id ) {
let channel = LibraryModules . ChannelStore . getChannel ( id ) ;
return BDFDB . ObjectUtils . is ( channel ) && ( channel . isDM ( ) || channel . isGroupDM ( ) ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DMUtils . getIcon = function ( id ) {
2021-02-04 20:12:57 +01:00
let channel = LibraryModules . ChannelStore . getChannel ( id ) ;
if ( ! channel ) return "" ;
if ( ! channel . icon ) return channel . isDM ( ) ? BDFDB . UserUtils . getAvatar ( channel . recipients [ 0 ] ) : ( channel . isGroupDM ( ) ? window . location . origin + LibraryModules . IconUtils . getChannelIconURL ( channel ) . split ( "?" ) [ 0 ] : null ) ;
2020-09-19 21:32:19 +02:00
return LibraryModules . IconUtils . getChannelIconURL ( channel ) . split ( "?" ) [ 0 ] ;
} ;
2021-02-04 20:12:57 +01:00
BDFDB . DMUtils . openMenu = function ( channel , e = mousePosition ) {
2020-09-19 21:32:19 +02:00
if ( channel ) {
2021-02-04 20:12:57 +01:00
if ( channel . isGroupDM ( ) ) LibraryModules . ContextMenuUtils . openContextMenu ( e , function ( e ) {
2020-11-19 16:51:14 +01:00
return BDFDB . ReactUtils . createElement ( ( BDFDB . ModuleUtils . findByName ( "GroupDMContextMenu" , false ) || { exports : { } } ) . exports . default , Object . assign ( { } , e , {
2020-09-19 21:32:19 +02:00
channel : channel ,
selected : channel . id == LibraryModules . LastChannelStore . getChannelId ( )
} ) ) ;
} ) ;
else LibraryModules . ContextMenuUtils . openContextMenu ( e , function ( e ) {
2020-11-19 16:51:14 +01:00
return BDFDB . ReactUtils . createElement ( ( BDFDB . ModuleUtils . findByName ( "DMUserContextMenu" , false ) || { exports : { } } ) . exports . default , Object . assign ( { } , e , {
2020-09-19 21:32:19 +02:00
user : LibraryModules . UserStore . getUser ( channel . recipients [ 0 ] ) ,
channel : channel ,
selected : channel . id == LibraryModules . LastChannelStore . getChannelId ( )
} ) ) ;
} ) ;
}
} ;
2021-02-04 20:12:57 +01:00
BDFDB . DMUtils . markAsRead = function ( dmIds ) {
let unreadDMs = [ dmIds ] . flat ( 10 ) . filter ( id => id && typeof id == "string" && BDFDB . DMUtils . isDMChannel ( id ) && ( LibraryModules . UnreadChannelUtils . hasUnread ( id ) || LibraryModules . UnreadChannelUtils . getMentionCount ( id ) > 0 ) ) ;
if ( unreadDMs . length ) for ( let i in unreadDMs ) BDFDB . TimeUtils . timeout ( _ => LibraryModules . AckUtils . ack ( unreadDMs [ i ] ) , i * 1000 ) ;
2020-09-19 21:32:19 +02:00
} ;
InternalBDFDB . writeConfig = function ( path , config ) {
try { LibraryRequires . fs . writeFileSync ( path , JSON . stringify ( config , null , " " ) ) ; }
catch ( err ) { }
} ;
InternalBDFDB . readConfig = function ( path ) {
try { return JSON . parse ( LibraryRequires . fs . readFileSync ( path ) ) ; }
catch ( err ) { return { } ; }
} ;
BDFDB . DataUtils = { } ;
BDFDB . DataUtils . save = function ( data , plugin , key , id ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
let pluginName = typeof plugin === "string" ? plugin : plugin . name ;
2020-09-29 09:10:42 +02:00
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName ;
let configPath = LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , fileName + ".config.json" ) ;
2020-09-19 21:32:19 +02:00
let config = Cache . data [ pluginName ] !== undefined ? Cache . data [ pluginName ] : ( InternalBDFDB . readConfig ( configPath ) || { } ) ;
if ( key === undefined ) config = BDFDB . ObjectUtils . is ( data ) ? BDFDB . ObjectUtils . sort ( data ) : data ;
else {
if ( id === undefined ) config [ key ] = BDFDB . ObjectUtils . is ( data ) ? BDFDB . ObjectUtils . sort ( data ) : data ;
else {
if ( ! BDFDB . ObjectUtils . is ( config [ key ] ) ) config [ key ] = { } ;
config [ key ] [ id ] = BDFDB . ObjectUtils . is ( data ) ? BDFDB . ObjectUtils . sort ( data ) : data ;
}
}
let configIsObject = BDFDB . ObjectUtils . is ( config ) ;
if ( key !== undefined && configIsObject && BDFDB . ObjectUtils . is ( config [ key ] ) && BDFDB . ObjectUtils . isEmpty ( config [ key ] ) ) delete config [ key ] ;
if ( BDFDB . ObjectUtils . isEmpty ( config ) ) {
delete Cache . data [ pluginName ] ;
if ( LibraryRequires . fs . existsSync ( configPath ) ) LibraryRequires . fs . unlinkSync ( configPath ) ;
}
else {
if ( configIsObject ) config = BDFDB . ObjectUtils . sort ( config ) ;
Cache . data [ pluginName ] = configIsObject ? BDFDB . ObjectUtils . deepAssign ( { } , config ) : config ;
InternalBDFDB . writeConfig ( configPath , config ) ;
}
} ;
BDFDB . DataUtils . load = function ( plugin , key , id ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
let pluginName = typeof plugin === "string" ? plugin : plugin . name ;
2020-09-29 09:10:42 +02:00
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName ;
let configPath = LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , fileName + ".config.json" ) ;
2020-09-19 21:32:19 +02:00
let config = Cache . data [ pluginName ] !== undefined ? Cache . data [ pluginName ] : ( InternalBDFDB . readConfig ( configPath ) || { } ) ;
let configIsObject = BDFDB . ObjectUtils . is ( config ) ;
Cache . data [ pluginName ] = configIsObject ? BDFDB . ObjectUtils . deepAssign ( { } , config ) : config ;
if ( key === undefined ) return config ;
else {
2021-01-10 11:41:01 +01:00
let keyData = configIsObject ? ( BDFDB . ObjectUtils . is ( config [ key ] ) || config [ key ] === undefined ? BDFDB . ObjectUtils . deepAssign ( { } , config [ key ] ) : config [ key ] ) : null ;
if ( id === undefined ) return keyData ;
else return ! BDFDB . ObjectUtils . is ( keyData ) || keyData [ id ] === undefined ? null : keyData [ id ] ;
2020-09-19 21:32:19 +02:00
}
} ;
BDFDB . DataUtils . remove = function ( plugin , key , id ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
let pluginName = typeof plugin === "string" ? plugin : plugin . name ;
2020-09-29 09:10:42 +02:00
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName ;
let configPath = LibraryRequires . path . join ( BDFDB . BDUtils . getPluginsFolder ( ) , fileName + ".config.json" ) ;
2020-09-19 21:32:19 +02:00
let config = Cache . data [ pluginName ] !== undefined ? Cache . data [ pluginName ] : ( InternalBDFDB . readConfig ( configPath ) || { } ) ;
let configIsObject = BDFDB . ObjectUtils . is ( config ) ;
if ( key === undefined || ! configIsObject ) config = { } ;
else {
if ( id === undefined ) delete config [ key ] ;
else if ( BDFDB . ObjectUtils . is ( config [ key ] ) ) delete config [ key ] [ id ] ;
}
if ( BDFDB . ObjectUtils . is ( config [ key ] ) && BDFDB . ObjectUtils . isEmpty ( config [ key ] ) ) delete config [ key ] ;
if ( BDFDB . ObjectUtils . isEmpty ( config ) ) {
delete Cache . data [ pluginName ] ;
if ( LibraryRequires . fs . existsSync ( configPath ) ) LibraryRequires . fs . unlinkSync ( configPath ) ;
}
else {
if ( configIsObject ) config = BDFDB . ObjectUtils . sort ( config ) ;
Cache . data [ pluginName ] = configIsObject ? BDFDB . ObjectUtils . deepAssign ( { } , config ) : config ;
InternalBDFDB . writeConfig ( configPath , config ) ;
}
} ;
BDFDB . DataUtils . get = function ( plugin , key , id ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
plugin = typeof plugin == "string" ? BDFDB . BDUtils . getPlugin ( plugin ) : plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) ) return id === undefined ? { } : null ;
let defaults = plugin . defaults ;
if ( ! BDFDB . ObjectUtils . is ( defaults ) || ! defaults [ key ] ) return id === undefined ? { } : null ;
let oldC = BDFDB . DataUtils . load ( plugin , key ) , newC = { } , update = false ;
for ( let k in defaults [ key ] ) {
let isObj = BDFDB . ObjectUtils . is ( defaults [ key ] [ k ] . value ) ;
if ( oldC [ k ] == null || isObj && ( ! BDFDB . ObjectUtils . is ( oldC [ k ] ) || Object . keys ( defaults [ key ] [ k ] . value ) . some ( n => defaults [ key ] [ k ] . value [ n ] != null && ! BDFDB . sameProto ( defaults [ key ] [ k ] . value [ n ] , oldC [ k ] [ n ] ) ) ) ) {
newC [ k ] = isObj ? BDFDB . ObjectUtils . deepAssign ( { } , defaults [ key ] [ k ] . value ) : defaults [ key ] [ k ] . value ;
update = true ;
}
else newC [ k ] = oldC [ k ] ;
}
if ( update ) BDFDB . DataUtils . save ( newC , plugin , key ) ;
if ( id === undefined ) return newC ;
else return newC [ id ] === undefined ? null : newC [ id ] ;
} ;
BDFDB . ColorUtils = { } ;
BDFDB . ColorUtils . convert = function ( color , conv , type ) {
if ( BDFDB . ObjectUtils . is ( color ) ) {
var newColor = { } ;
for ( let pos in color ) newColor [ pos ] = BDFDB . ColorUtils . convert ( color [ pos ] , conv , type ) ;
return newColor ;
}
else {
conv = conv === undefined || ! conv ? conv = "RGBCOMP" : conv . toUpperCase ( ) ;
type = type === undefined || ! type || ! [ "RGB" , "RGBA" , "RGBCOMP" , "HSL" , "HSLA" , "HSLCOMP" , "HEX" , "HEXA" , "INT" ] . includes ( type . toUpperCase ( ) ) ? BDFDB . ColorUtils . getType ( color ) : type . toUpperCase ( ) ;
if ( conv == "RGBCOMP" ) {
switch ( type ) {
case "RGBCOMP" :
if ( color . length == 3 ) return processRGB ( color ) ;
else if ( color . length == 4 ) {
let a = processA ( color . pop ( ) ) ;
return processRGB ( color ) . concat ( a ) ;
}
break ;
case "RGB" :
return processRGB ( color . replace ( /\s/g , "" ) . slice ( 4 , - 1 ) . split ( "," ) ) ;
case "RGBA" :
let comp = color . replace ( /\s/g , "" ) . slice ( 5 , - 1 ) . split ( "," ) ;
let a = processA ( comp . pop ( ) ) ;
return processRGB ( comp ) . concat ( a ) ;
case "HSLCOMP" :
if ( color . length == 3 ) return BDFDB . ColorUtils . convert ( ` hsl( ${ processHSL ( color ) . join ( "," ) } ) ` , "RGBCOMP" ) ;
else if ( color . length == 4 ) {
let a = processA ( color . pop ( ) ) ;
return BDFDB . ColorUtils . convert ( ` hsl( ${ processHSL ( color ) . join ( "," ) } ) ` , "RGBCOMP" ) . concat ( a ) ;
}
break ;
case "HSL" :
var hslcomp = processHSL ( color . replace ( /\s/g , "" ) . slice ( 4 , - 1 ) . split ( "," ) ) ;
var r , g , b , m , c , x , p , q ;
var h = hslcomp [ 0 ] / 360 , l = parseInt ( hslcomp [ 1 ] ) / 100 , s = parseInt ( hslcomp [ 2 ] ) / 100 ; m = Math . floor ( h * 6 ) ; c = h * 6 - m ; x = s * ( 1 - l ) ; p = s * ( 1 - c * l ) ; q = s * ( 1 - ( 1 - c ) * l ) ;
switch ( m % 6 ) {
case 0 : r = s , g = q , b = x ; break ;
case 1 : r = p , g = s , b = x ; break ;
case 2 : r = x , g = s , b = q ; break ;
case 3 : r = x , g = p , b = s ; break ;
case 4 : r = q , g = x , b = s ; break ;
case 5 : r = s , g = x , b = p ; break ;
}
return [ Math . round ( r * 255 ) , Math . round ( g * 255 ) , Math . round ( b * 255 ) ] ;
case "HSLA" :
var hslcomp = color . replace ( /\s/g , "" ) . slice ( 5 , - 1 ) . split ( "," ) ;
return BDFDB . ColorUtils . convert ( ` hsl( ${ hslcomp . slice ( 0 , 3 ) . join ( "," ) } ) ` , "RGBCOMP" ) . concat ( processA ( hslcomp . pop ( ) ) ) ;
case "HEX" :
var hex = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$|^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i . exec ( color ) ;
return [ parseInt ( hex [ 1 ] + hex [ 1 ] || hex [ 4 ] , 16 ) . toString ( ) , parseInt ( hex [ 2 ] + hex [ 2 ] || hex [ 5 ] , 16 ) . toString ( ) , parseInt ( hex [ 3 ] + hex [ 3 ] || hex [ 6 ] , 16 ) . toString ( ) ] ;
case "HEXA" :
var hex = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$|^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i . exec ( color ) ;
return [ parseInt ( hex [ 1 ] + hex [ 1 ] || hex [ 5 ] , 16 ) . toString ( ) , parseInt ( hex [ 2 ] + hex [ 2 ] || hex [ 6 ] , 16 ) . toString ( ) , parseInt ( hex [ 3 ] + hex [ 3 ] || hex [ 7 ] , 16 ) . toString ( ) , Math . floor ( BDFDB . NumberUtils . mapRange ( [ 0 , 255 ] , [ 0 , 100 ] , parseInt ( hex [ 4 ] + hex [ 4 ] || hex [ 8 ] , 16 ) . toString ( ) ) ) / 100 ] ;
case "INT" :
color = processINT ( color ) ;
return [ ( color >> 16 & 255 ) . toString ( ) , ( color >> 8 & 255 ) . toString ( ) , ( color & 255 ) . toString ( ) ] ;
default :
return null ;
}
}
else {
if ( conv && type && conv . indexOf ( "HSL" ) == 0 && type . indexOf ( "HSL" ) == 0 ) {
if ( type == "HSLCOMP" ) {
switch ( conv ) {
case "HSLCOMP" :
if ( color . length == 3 ) return processHSL ( color ) ;
else if ( color . length == 4 ) {
var a = processA ( color . pop ( ) ) ;
return processHSL ( color ) . concat ( a ) ;
}
break ;
case "HSL" :
return ` hsl( ${ processHSL ( color . slice ( 0 , 3 ) ) . join ( "," ) } ) ` ;
case "HSLA" :
color = color . slice ( 0 , 4 ) ;
var a = color . length == 4 ? processA ( color . pop ( ) ) : 1 ;
return ` hsla( ${ processHSL ( color ) . concat ( a ) . join ( "," ) } ) ` ;
}
}
else return BDFDB . ColorUtils . convert ( color . replace ( /\s/g , "" ) . slice ( color . toLowerCase ( ) . indexOf ( "hsla" ) == 0 ? 5 : 4 , - 1 ) . split ( "," ) , conv , "HSLCOMP" ) ;
}
else {
let rgbcomp = type == "RGBCOMP" ? color : BDFDB . ColorUtils . convert ( color , "RGBCOMP" , type ) ;
if ( rgbcomp ) switch ( conv ) {
case "RGB" :
return ` rgb( ${ processRGB ( rgbcomp . slice ( 0 , 3 ) ) . join ( "," ) } ) ` ;
case "RGBA" :
rgbcomp = rgbcomp . slice ( 0 , 4 ) ;
var a = rgbcomp . length == 4 ? processA ( rgbcomp . pop ( ) ) : 1 ;
return ` rgba( ${ processRGB ( rgbcomp ) . concat ( a ) . join ( "," ) } ) ` ;
case "HSLCOMP" :
var a = rgbcomp . length == 4 ? processA ( rgbcomp . pop ( ) ) : null ;
var hslcomp = processHSL ( BDFDB . ColorUtils . convert ( rgbcomp , "HSL" ) . replace ( /\s/g , "" ) . split ( "," ) ) ;
return a != null ? hslcomp . concat ( a ) : hslcomp ;
case "HSL" :
var r = processC ( rgbcomp [ 0 ] ) , g = processC ( rgbcomp [ 1 ] ) , b = processC ( rgbcomp [ 2 ] ) ;
var max = Math . max ( r , g , b ) , min = Math . min ( r , g , b ) , dif = max - min , h , l = max === 0 ? 0 : dif / max , s = max / 255 ;
switch ( max ) {
case min : h = 0 ; break ;
case r : h = g - b + dif * ( g < b ? 6 : 0 ) ; h /= 6 * dif ; break ;
case g : h = b - r + dif * 2 ; h /= 6 * dif ; break ;
case b : h = r - g + dif * 4 ; h /= 6 * dif ; break ;
}
return ` hsl( ${ processHSL ( [ Math . round ( h * 360 ) , l * 100 , s * 100 ] ) . join ( "," ) } ) ` ;
case "HSLA" :
var a = rgbcomp . length == 4 ? processA ( rgbcomp . pop ( ) ) : 1 ;
return ` hsla( ${ BDFDB . ColorUtils . convert ( rgbcomp , "HSL" ) . slice ( 4 , - 1 ) . split ( "," ) . concat ( a ) . join ( "," ) } ) ` ;
case "HEX" :
return ( "#" + ( 0x1000000 + ( rgbcomp [ 2 ] | rgbcomp [ 1 ] << 8 | rgbcomp [ 0 ] << 16 ) ) . toString ( 16 ) . slice ( 1 ) ) . toUpperCase ( ) ;
case "HEXA" :
return ( "#" + ( 0x1000000 + ( rgbcomp [ 2 ] | rgbcomp [ 1 ] << 8 | rgbcomp [ 0 ] << 16 ) ) . toString ( 16 ) . slice ( 1 ) + ( 0x100 + Math . round ( BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , [ 0 , 255 ] , processA ( rgbcomp [ 3 ] ) * 100 ) ) ) . toString ( 16 ) . slice ( 1 ) ) . toUpperCase ( ) ;
case "INT" :
return processINT ( rgbcomp [ 2 ] | rgbcomp [ 1 ] << 8 | rgbcomp [ 0 ] << 16 ) ;
default :
return null ;
}
}
}
}
return null ;
function processC ( c ) { if ( c == null ) { return 255 ; } else { c = parseInt ( c . toString ( ) . replace ( /[^0-9\-]/g , "" ) ) ; return isNaN ( c ) || c > 255 ? 255 : c < 0 ? 0 : c ; } } ;
function processRGB ( comp ) { return comp . map ( c => { return processC ( c ) ; } ) ; } ;
function processA ( a ) { if ( a == null ) { return 1 ; } else { a = a . toString ( ) ; a = ( a . indexOf ( "%" ) > - 1 ? 0.01 : 1 ) * parseFloat ( a . replace ( /[^0-9\.\-]/g , "" ) ) ; return isNaN ( a ) || a > 1 ? 1 : a < 0 ? 0 : a ; } } ;
function processSL ( sl ) { if ( sl == null ) { return "100%" ; } else { sl = parseFloat ( sl . toString ( ) . replace ( /[^0-9\.\-]/g , "" ) ) ; return ( isNaN ( sl ) || sl > 100 ? 100 : sl < 0 ? 0 : sl ) + "%" ; } } ;
function processHSL ( comp ) { let h = parseFloat ( comp . shift ( ) . toString ( ) . replace ( /[^0-9\.\-]/g , "" ) ) ; h = isNaN ( h ) || h > 360 ? 360 : h < 0 ? 0 : h ; return [ h ] . concat ( comp . map ( sl => { return processSL ( sl ) ; } ) ) ; } ;
function processINT ( c ) { if ( c == null ) { return 16777215 ; } else { c = parseInt ( c . toString ( ) . replace ( /[^0-9]/g , "" ) ) ; return isNaN ( c ) || c > 16777215 ? 16777215 : c < 0 ? 0 : c ; } } ;
} ;
BDFDB . ColorUtils . setAlpha = function ( color , a , conv ) {
if ( BDFDB . ObjectUtils . is ( color ) ) {
2021-01-02 12:51:18 +01:00
let newcolor = { } ;
2020-09-19 21:32:19 +02:00
for ( let pos in color ) newcolor [ pos ] = BDFDB . ColorUtils . setAlpha ( color [ pos ] , a , conv ) ;
return newcolor ;
}
else {
2021-01-02 12:51:18 +01:00
let comp = BDFDB . ColorUtils . convert ( color , "RGBCOMP" ) ;
2020-09-19 21:32:19 +02:00
if ( comp ) {
a = a . toString ( ) ;
a = ( a . indexOf ( "%" ) > - 1 ? 0.01 : 1 ) * parseFloat ( a . replace ( /[^0-9\.\-]/g , "" ) ) ;
a = isNaN ( a ) || a > 1 ? 1 : a < 0 ? 0 : a ;
comp [ 3 ] = a ;
conv = ( conv || BDFDB . ColorUtils . getType ( color ) ) . toUpperCase ( ) ;
conv = conv == "RGB" || conv == "HSL" || conv == "HEX" ? conv + "A" : conv ;
return BDFDB . ColorUtils . convert ( comp , conv ) ;
}
}
return null ;
} ;
BDFDB . ColorUtils . getAlpha = function ( color ) {
2021-01-02 12:51:18 +01:00
let comp = BDFDB . ColorUtils . convert ( color , "RGBCOMP" ) ;
2020-09-19 21:32:19 +02:00
if ( comp ) {
if ( comp . length == 3 ) return 1 ;
else if ( comp . length == 4 ) {
let a = comp [ 3 ] . toString ( ) ;
a = ( a . indexOf ( "%" ) > - 1 ? 0.01 : 1 ) * parseFloat ( a . replace ( /[^0-9\.\-]/g , "" ) ) ;
return isNaN ( a ) || a > 1 ? 1 : a < 0 ? 0 : a ;
}
}
return null ;
} ;
BDFDB . ColorUtils . change = function ( color , value , conv ) {
value = parseFloat ( value ) ;
if ( color != null && typeof value == "number" && ! isNaN ( value ) ) {
if ( BDFDB . ObjectUtils . is ( color ) ) {
2021-01-02 12:51:18 +01:00
let newColor = { } ;
for ( let pos in color ) newColor [ pos ] = BDFDB . ColorUtils . change ( color [ pos ] , value , conv ) ;
return newColor ;
2020-09-19 21:32:19 +02:00
}
else {
2021-01-02 12:51:18 +01:00
let comp = BDFDB . ColorUtils . convert ( color , "RGBCOMP" ) ;
2020-09-19 21:32:19 +02:00
if ( comp ) {
if ( parseInt ( value ) !== value ) {
value = value . toString ( ) ;
value = ( value . indexOf ( "%" ) > - 1 ? 0.01 : 1 ) * parseFloat ( value . replace ( /[^0-9\.\-]/g , "" ) ) ;
value = isNaN ( value ) ? 0 : value ;
return BDFDB . ColorUtils . convert ( [ Math . round ( comp [ 0 ] * ( 1 + value ) ) , Math . round ( comp [ 1 ] * ( 1 + value ) ) , Math . round ( comp [ 2 ] * ( 1 + value ) ) ] , conv || BDFDB . ColorUtils . getType ( color ) ) ;
}
else return BDFDB . ColorUtils . convert ( [ Math . round ( comp [ 0 ] + value ) , Math . round ( comp [ 1 ] + value ) , Math . round ( comp [ 2 ] + value ) ] , conv || BDFDB . ColorUtils . getType ( color ) ) ;
}
}
}
return null ;
} ;
BDFDB . ColorUtils . invert = function ( color , conv ) {
if ( BDFDB . ObjectUtils . is ( color ) ) {
2021-01-02 12:51:18 +01:00
let newColor = { } ;
for ( let pos in color ) newColor [ pos ] = BDFDB . ColorUtils . invert ( color [ pos ] , conv ) ;
return newColor ;
2020-09-19 21:32:19 +02:00
}
else {
2021-01-02 12:51:18 +01:00
let comp = BDFDB . ColorUtils . convert ( color , "RGBCOMP" ) ;
2020-09-19 21:32:19 +02:00
if ( comp ) return BDFDB . ColorUtils . convert ( [ 255 - comp [ 0 ] , 255 - comp [ 1 ] , 255 - comp [ 2 ] ] , conv || BDFDB . ColorUtils . getType ( color ) ) ;
}
return null ;
} ;
BDFDB . ColorUtils . compare = function ( color1 , color2 ) {
if ( color1 && color2 ) {
color1 = BDFDB . ColorUtils . convert ( color1 , "RGBA" ) ;
color2 = BDFDB . ColorUtils . convert ( color2 , "RGBA" ) ;
if ( color1 && color2 ) return BDFDB . equals ( color1 , color2 ) ;
}
return null ;
} ;
BDFDB . ColorUtils . isBright = function ( color , compare = 160 ) {
color = BDFDB . ColorUtils . convert ( color , "RGBCOMP" ) ;
if ( ! color ) return false ;
return parseInt ( compare ) < Math . sqrt ( 0.299 * color [ 0 ] * * 2 + 0.587 * color [ 1 ] * * 2 + 0.144 * color [ 2 ] * * 2 ) ;
} ;
BDFDB . ColorUtils . getType = function ( color ) {
if ( color != null ) {
if ( typeof color === "object" && ( color . length == 3 || color . length == 4 ) ) {
if ( isRGB ( color ) ) return "RGBCOMP" ;
else if ( isHSL ( color ) ) return "HSLCOMP" ;
}
else if ( typeof color === "string" ) {
if ( /^#[a-f\d]{3}$|^#[a-f\d]{6}$/i . test ( color ) ) return "HEX" ;
else if ( /^#[a-f\d]{4}$|^#[a-f\d]{8}$/i . test ( color ) ) return "HEXA" ;
else {
color = color . toUpperCase ( ) ;
2021-01-02 12:51:18 +01:00
let comp = color . replace ( /[^0-9\.\-\,\%]/g , "" ) . split ( "," ) ;
2020-09-19 21:32:19 +02:00
if ( color . indexOf ( "RGB(" ) == 0 && comp . length == 3 && isRGB ( comp ) ) return "RGB" ;
else if ( color . indexOf ( "RGBA(" ) == 0 && comp . length == 4 && isRGB ( comp ) ) return "RGBA" ;
else if ( color . indexOf ( "HSL(" ) == 0 && comp . length == 3 && isHSL ( comp ) ) return "HSL" ;
else if ( color . indexOf ( "HSLA(" ) == 0 && comp . length == 4 && isHSL ( comp ) ) return "HSLA" ;
}
}
else if ( typeof color === "number" && parseInt ( color ) == color && color > - 1 && color < 16777216 ) return "INT" ;
}
return null ;
function isRGB ( comp ) { return comp . slice ( 0 , 3 ) . every ( rgb => rgb . toString ( ) . indexOf ( "%" ) == - 1 && parseFloat ( rgb ) == parseInt ( rgb ) ) ; } ;
function isHSL ( comp ) { return comp . slice ( 1 , 3 ) . every ( hsl => hsl . toString ( ) . indexOf ( "%" ) == hsl . length - 1 ) ; } ;
} ;
2020-10-23 19:07:35 +02:00
BDFDB . ColorUtils . createGradient = function ( colorObj , direction = "to right" ) {
let gradientString = "linear-gradient(" + direction ;
for ( let pos of Object . keys ( colorObj ) . sort ( ) ) {
let color = BDFDB . ColorUtils . convert ( colorObj [ pos ] , "RGBA" ) ;
gradientString += color ? ` , ${ color } ${ pos * 100 } % ` : ''
2020-09-19 21:32:19 +02:00
}
2020-10-23 19:07:35 +02:00
return gradientString += ")" ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DOMUtils = { } ;
BDFDB . DOMUtils . getSelection = function ( ) {
let selection = document . getSelection ( ) ;
return selection && selection . anchorNode ? selection . getRangeAt ( 0 ) . toString ( ) : "" ;
} ;
BDFDB . DOMUtils . addClass = function ( eles , ... classes ) {
if ( ! eles || ! classes ) return ;
for ( let ele of [ eles ] . map ( n => NodeList . prototype . isPrototypeOf ( n ) ? Array . from ( n ) : n ) . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) add ( ele ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) for ( let e of ele ) add ( e ) ;
else if ( typeof ele == "string" ) for ( let e of ele . split ( "," ) ) if ( e && ( e = e . trim ( ) ) ) for ( let n of document . querySelectorAll ( e ) ) add ( n ) ;
}
function add ( node ) {
if ( node && node . classList ) for ( let cla of classes ) for ( let cl of [ cla ] . flat ( 10 ) . filter ( n => n ) ) if ( typeof cl == "string" ) for ( let c of cl . split ( " " ) ) if ( c ) node . classList . add ( c ) ;
}
} ;
BDFDB . DOMUtils . removeClass = function ( eles , ... classes ) {
if ( ! eles || ! classes ) return ;
for ( let ele of [ eles ] . map ( n => NodeList . prototype . isPrototypeOf ( n ) ? Array . from ( n ) : n ) . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) remove ( ele ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) for ( let e of ele ) remove ( e ) ;
else if ( typeof ele == "string" ) for ( let e of ele . split ( "," ) ) if ( e && ( e = e . trim ( ) ) ) for ( let n of document . querySelectorAll ( e ) ) remove ( n ) ;
}
function remove ( node ) {
if ( node && node . classList ) for ( let cla of classes ) for ( let cl of [ cla ] . flat ( 10 ) . filter ( n => n ) ) if ( typeof cl == "string" ) for ( let c of cl . split ( " " ) ) if ( c ) node . classList . remove ( c ) ;
}
} ;
BDFDB . DOMUtils . toggleClass = function ( eles , ... classes ) {
if ( ! eles || ! classes ) return ;
var force = classes . pop ( ) ;
if ( typeof force != "boolean" ) {
classes . push ( force ) ;
force = undefined ;
}
if ( ! classes . length ) return ;
for ( let ele of [ eles ] . map ( n => NodeList . prototype . isPrototypeOf ( n ) ? Array . from ( n ) : n ) . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) toggle ( ele ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) for ( let e of ele ) toggle ( e ) ;
else if ( typeof ele == "string" ) for ( let e of ele . split ( "," ) ) if ( e && ( e = e . trim ( ) ) ) for ( let n of document . querySelectorAll ( e ) ) toggle ( n ) ;
}
function toggle ( node ) {
if ( node && node . classList ) for ( let cla of classes ) for ( let cl of [ cla ] . flat ( 10 ) . filter ( n => n ) ) if ( typeof cl == "string" ) for ( let c of cl . split ( " " ) ) if ( c ) node . classList . toggle ( c , force ) ;
}
} ;
BDFDB . DOMUtils . containsClass = function ( eles , ... classes ) {
if ( ! eles || ! classes ) return ;
let all = classes . pop ( ) ;
if ( typeof all != "boolean" ) {
classes . push ( all ) ;
all = true ;
}
if ( ! classes . length ) return ;
let contained = undefined ;
for ( let ele of [ eles ] . map ( n => NodeList . prototype . isPrototypeOf ( n ) ? Array . from ( n ) : n ) . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) contains ( ele ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) for ( let e of ele ) contains ( e ) ;
else if ( typeof ele == "string" ) for ( let c of ele . split ( "," ) ) if ( c && ( c = c . trim ( ) ) ) for ( let n of document . querySelectorAll ( c ) ) contains ( n ) ;
}
return contained ;
function contains ( node ) {
if ( node && node . classList ) for ( let cla of classes ) if ( typeof cla == "string" ) for ( let c of cla . split ( " " ) ) if ( c ) {
if ( contained === undefined ) contained = all ;
if ( all && ! node . classList . contains ( c ) ) contained = false ;
if ( ! all && node . classList . contains ( c ) ) contained = true ;
}
}
} ;
BDFDB . DOMUtils . replaceClass = function ( eles , oldclass , newclass ) {
if ( ! eles || typeof oldclass != "string" || typeof newclass != "string" ) return ;
for ( let ele of [ eles ] . map ( n => NodeList . prototype . isPrototypeOf ( n ) ? Array . from ( n ) : n ) . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) replace ( ele ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) for ( let e of ele ) replace ( e ) ;
else if ( typeof ele == "string" ) for ( let e of ele . split ( "," ) ) if ( e && ( e = e . trim ( ) ) ) for ( let n of document . querySelectorAll ( e ) ) replace ( n ) ;
}
function replace ( node ) {
if ( node && node . tagName && node . className ) node . className = node . className . replace ( new RegExp ( oldclass , "g" ) , newclass ) . trim ( ) ;
}
} ;
BDFDB . DOMUtils . formatClassName = function ( ... classes ) {
return BDFDB . ArrayUtils . removeCopies ( classes . flat ( 10 ) . filter ( n => n ) . join ( " " ) . split ( " " ) ) . join ( " " ) . trim ( ) ;
} ;
BDFDB . DOMUtils . removeClassFromDOM = function ( ... classes ) {
for ( let c of classes . flat ( 10 ) . filter ( n => n ) ) if ( typeof c == "string" ) for ( let a of c . split ( "," ) ) if ( a && ( a = a . replace ( /\.|\s/g , "" ) ) ) BDFDB . DOMUtils . removeClass ( document . querySelectorAll ( "." + a ) , a ) ;
} ;
BDFDB . DOMUtils . show = function ( ... eles ) {
BDFDB . DOMUtils . toggle ( ... eles , true ) ;
} ;
BDFDB . DOMUtils . hide = function ( ... eles ) {
BDFDB . DOMUtils . toggle ( ... eles , false ) ;
} ;
BDFDB . DOMUtils . toggle = function ( ... eles ) {
if ( ! eles ) return ;
let force = eles . pop ( ) ;
if ( typeof force != "boolean" ) {
eles . push ( force ) ;
force = undefined ;
}
if ( ! eles . length ) return ;
for ( let ele of eles . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) toggle ( ele ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) for ( let node of ele ) toggle ( node ) ;
else if ( typeof ele == "string" ) for ( let c of ele . split ( "," ) ) if ( c && ( c = c . trim ( ) ) ) for ( let node of document . querySelectorAll ( c ) ) toggle ( node ) ;
}
function toggle ( node ) {
if ( ! node || ! Node . prototype . isPrototypeOf ( node ) ) return ;
2021-02-03 11:27:30 +01:00
let hide = force === undefined ? ! BDFDB . DOMUtils . isHidden ( node ) : ! force ;
if ( hide ) {
2020-09-19 21:32:19 +02:00
let display = node . style . getPropertyValue ( "display" ) ;
if ( display && display != "none" ) node . BDFDBhideDisplayState = {
display : display ,
important : ( ` ${ node . style . cssText } ` . split ( ` display: ${ display } ` ) [ 1 ] || "" ) . trim ( ) . indexOf ( "!important" ) == 0
} ;
node . style . setProperty ( "display" , "none" , "important" ) ;
}
else {
if ( node . BDFDBhideDisplayState ) {
node . style . setProperty ( "display" , node . BDFDBhideDisplayState . display , node . BDFDBhideDisplayState . important ? "important" : "" ) ;
delete node . BDFDBhideDisplayState ;
}
else node . style . removeProperty ( "display" ) ;
}
}
} ;
BDFDB . DOMUtils . isHidden = function ( node ) {
if ( Node . prototype . isPrototypeOf ( node ) && node . nodeType != Node . TEXT _NODE ) return getComputedStyle ( node , null ) . getPropertyValue ( "display" ) == "none" ;
} ;
BDFDB . DOMUtils . remove = function ( ... eles ) {
for ( let ele of eles . flat ( 10 ) . filter ( n => n ) ) {
if ( Node . prototype . isPrototypeOf ( ele ) ) ele . remove ( ) ;
else if ( NodeList . prototype . isPrototypeOf ( ele ) ) {
let nodes = Array . from ( ele ) ;
while ( nodes . length ) nodes . shift ( ) . remove ( ) ;
}
else if ( typeof ele == "string" ) for ( let c of ele . split ( "," ) ) if ( c && ( c = c . trim ( ) ) ) {
let nodes = Array . from ( document . querySelectorAll ( c ) ) ;
while ( nodes . length ) nodes . shift ( ) . remove ( ) ;
}
}
} ;
BDFDB . DOMUtils . create = function ( html ) {
if ( typeof html != "string" || ! html . trim ( ) ) return null ;
let template = document . createElement ( "template" ) ;
try { template . innerHTML = html . replace ( /(?<!pre)>[\t\r\n]+<(?!pre)/g , "><" ) ; }
catch ( err ) { template . innerHTML = html . replace ( />[\t\r\n]+<(?!pre)/g , "><" ) ; }
2020-11-11 11:25:04 +01:00
if ( template . content . childNodes . length == 1 ) return template . content . firstElementChild || template . content . firstChild ;
2020-09-19 21:32:19 +02:00
else {
let wrapper = document . createElement ( "span" ) ;
let nodes = Array . from ( template . content . childNodes ) ;
while ( nodes . length ) wrapper . appendChild ( nodes . shift ( ) ) ;
return wrapper ;
}
} ;
BDFDB . DOMUtils . getParent = function ( listOrSelector , node ) {
let parent = null ;
if ( Node . prototype . isPrototypeOf ( node ) && listOrSelector ) {
let list = NodeList . prototype . isPrototypeOf ( listOrSelector ) ? listOrSelector : typeof listOrSelector == "string" ? document . querySelectorAll ( listOrSelector ) : null ;
if ( list ) for ( let listNode of list ) if ( listNode . contains ( node ) ) {
parent = listNode ;
break ;
}
}
return parent ;
} ;
BDFDB . DOMUtils . setText = function ( node , stringOrNode ) {
if ( ! node || ! Node . prototype . isPrototypeOf ( node ) ) return ;
let textnode = node . nodeType == Node . TEXT _NODE ? node : null ;
if ( ! textnode ) for ( let child of node . childNodes ) if ( child . nodeType == Node . TEXT _NODE || BDFDB . DOMUtils . containsClass ( child , "BDFDB-textnode" ) ) {
textnode = child ;
break ;
}
if ( textnode ) {
if ( Node . prototype . isPrototypeOf ( stringOrNode ) && stringOrNode . nodeType != Node . TEXT _NODE ) {
BDFDB . DOMUtils . addClass ( stringOrNode , "BDFDB-textnode" ) ;
node . replaceChild ( stringOrNode , textnode ) ;
}
else if ( Node . prototype . isPrototypeOf ( textnode ) && textnode . nodeType != Node . TEXT _NODE ) node . replaceChild ( document . createTextNode ( stringOrNode ) , textnode ) ;
else textnode . textContent = stringOrNode ;
}
else node . appendChild ( Node . prototype . isPrototypeOf ( stringOrNode ) ? stringOrNode : document . createTextNode ( stringOrNode ) ) ;
} ;
BDFDB . DOMUtils . getText = function ( node ) {
if ( ! node || ! Node . prototype . isPrototypeOf ( node ) ) return ;
for ( let child of node . childNodes ) if ( child . nodeType == Node . TEXT _NODE ) return child . textContent ;
} ;
BDFDB . DOMUtils . getRects = function ( node ) {
let rects = { } ;
if ( Node . prototype . isPrototypeOf ( node ) && node . nodeType != Node . TEXT _NODE ) {
let hideNode = node ;
while ( hideNode ) {
let hidden = BDFDB . DOMUtils . isHidden ( hideNode ) ;
if ( hidden ) {
BDFDB . DOMUtils . toggle ( hideNode , true ) ;
hideNode . BDFDBgetRectsHidden = true ;
}
hideNode = hideNode . parentElement ;
}
rects = node . getBoundingClientRect ( ) ;
hideNode = node ;
while ( hideNode ) {
if ( hideNode . BDFDBgetRectsHidden ) {
BDFDB . DOMUtils . toggle ( hideNode , false ) ;
delete hideNode . BDFDBgetRectsHidden ;
}
hideNode = hideNode . parentElement ;
}
}
return rects ;
} ;
BDFDB . DOMUtils . getHeight = function ( node ) {
if ( Node . prototype . isPrototypeOf ( node ) && node . nodeType != Node . TEXT _NODE ) {
let rects = BDFDB . DOMUtils . getRects ( node ) ;
let style = getComputedStyle ( node ) ;
return rects . height + parseInt ( style . marginTop ) + parseInt ( style . marginBottom ) ;
}
return 0 ;
} ;
BDFDB . DOMUtils . getInnerHeight = function ( node ) {
if ( Node . prototype . isPrototypeOf ( node ) && node . nodeType != Node . TEXT _NODE ) {
let rects = BDFDB . DOMUtils . getRects ( node ) ;
let style = getComputedStyle ( node ) ;
return rects . height - parseInt ( style . paddingTop ) - parseInt ( style . paddingBottom ) ;
}
return 0 ;
} ;
BDFDB . DOMUtils . getWidth = function ( node ) {
if ( Node . prototype . isPrototypeOf ( node ) && node . nodeType != Node . TEXT _NODE ) {
let rects = BDFDB . DOMUtils . getRects ( node ) ;
let style = getComputedStyle ( node ) ;
return rects . width + parseInt ( style . marginLeft ) + parseInt ( style . marginRight ) ;
}
return 0 ;
} ;
BDFDB . DOMUtils . getInnerWidth = function ( node ) {
if ( Node . prototype . isPrototypeOf ( node ) && node . nodeType != Node . TEXT _NODE ) {
let rects = BDFDB . DOMUtils . getRects ( node ) ;
let style = getComputedStyle ( node ) ;
return rects . width - parseInt ( style . paddingLeft ) - parseInt ( style . paddingRight ) ;
}
return 0 ;
} ;
BDFDB . DOMUtils . appendWebScript = function ( url , container ) {
if ( typeof url != "string" ) return ;
if ( ! container && ! document . head . querySelector ( "bd-head bd-scripts" ) ) document . head . appendChild ( BDFDB . DOMUtils . create ( ` <bd-head><bd-scripts></bd-scripts></bd-head> ` ) ) ;
container = container || document . head . querySelector ( "bd-head bd-scripts" ) || document . head ;
container = Node . prototype . isPrototypeOf ( container ) ? container : document . head ;
BDFDB . DOMUtils . removeWebScript ( url , container ) ;
let script = document . createElement ( "script" ) ;
script . src = url ;
container . appendChild ( script ) ;
} ;
BDFDB . DOMUtils . removeWebScript = function ( url , container ) {
if ( typeof url != "string" ) return ;
container = container || document . head . querySelector ( "bd-head bd-scripts" ) || document . head ;
container = Node . prototype . isPrototypeOf ( container ) ? container : document . head ;
BDFDB . DOMUtils . remove ( container . querySelectorAll ( ` script[src=" ${ url } "] ` ) ) ;
} ;
BDFDB . DOMUtils . appendWebStyle = function ( url , container ) {
if ( typeof url != "string" ) return ;
if ( ! container && ! document . head . querySelector ( "bd-head bd-styles" ) ) document . head . appendChild ( BDFDB . DOMUtils . create ( ` <bd-head><bd-styles></bd-styles></bd-head> ` ) ) ;
container = container || document . head . querySelector ( "bd-head bd-styles" ) || document . head ;
container = Node . prototype . isPrototypeOf ( container ) ? container : document . head ;
BDFDB . DOMUtils . removeWebStyle ( url , container ) ;
2021-02-17 13:13:48 +01:00
container . appendChild ( BDFDB . DOMUtils . create ( ` <link type="text/css" rel="stylesheet" href=" ${ url } "></link> ` ) ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DOMUtils . removeWebStyle = function ( url , container ) {
if ( typeof url != "string" ) return ;
container = container || document . head . querySelector ( "bd-head bd-styles" ) || document . head ;
container = Node . prototype . isPrototypeOf ( container ) ? container : document . head ;
BDFDB . DOMUtils . remove ( container . querySelectorAll ( ` link[href=" ${ url } "] ` ) ) ;
} ;
BDFDB . DOMUtils . appendLocalStyle = function ( id , css , container ) {
if ( typeof id != "string" || typeof css != "string" ) return ;
if ( ! container && ! document . head . querySelector ( "bd-head bd-styles" ) ) document . head . appendChild ( BDFDB . DOMUtils . create ( ` <bd-head><bd-styles></bd-styles></bd-head> ` ) ) ;
container = container || document . head . querySelector ( "bd-head bd-styles" ) || document . head ;
container = Node . prototype . isPrototypeOf ( container ) ? container : document . head ;
BDFDB . DOMUtils . removeLocalStyle ( id , container ) ;
container . appendChild ( BDFDB . DOMUtils . create ( ` <style id=" ${ id } CSS"> ${ css . replace ( /\t|\r|\n/g , "" ) } </style> ` ) ) ;
} ;
BDFDB . DOMUtils . removeLocalStyle = function ( id , container ) {
if ( typeof id != "string" ) return ;
container = container || document . head . querySelector ( "bd-head bd-styles" ) || document . head ;
container = Node . prototype . isPrototypeOf ( container ) ? container : document . head ;
BDFDB . DOMUtils . remove ( container . querySelectorAll ( ` style[id=" ${ id } CSS"] ` ) ) ;
} ;
BDFDB . ModalUtils = { } ;
BDFDB . ModalUtils . open = function ( plugin , config ) {
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ObjectUtils . is ( config ) ) return ;
2021-01-29 22:18:18 +01:00
let modalInstance , modalProps , cancels = [ ] , closeModal = _ => {
2020-09-19 21:32:19 +02:00
if ( BDFDB . ObjectUtils . is ( modalProps ) && typeof modalProps . onClose == "function" ) modalProps . onClose ( ) ;
} ;
2021-01-29 22:18:18 +01:00
2020-12-22 07:54:16 +01:00
let titleChildren = [ ] , headerChildren = [ ] , contentChildren = [ ] , footerChildren = [ ] ;
2021-01-29 22:18:18 +01:00
if ( typeof config . text == "string" ) contentChildren . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextElement , {
children : config . text
} ) ) ;
2020-09-19 21:32:19 +02:00
if ( config . children ) {
2021-01-29 22:18:18 +01:00
let tabBarItems = [ ] , tabIns = { } ;
2020-09-19 21:32:19 +02:00
for ( let child of [ config . children ] . flat ( 10 ) . filter ( n => n ) ) if ( LibraryModules . React . isValidElement ( child ) ) {
if ( child . type == InternalComponents . LibraryComponents . ModalComponents . ModalTabContent ) {
if ( ! tabBarItems . length ) child . props . open = true ;
else delete child . props . open ;
2021-01-29 22:18:18 +01:00
let ref = typeof child . ref == "function" ? child . ref : ( _ => { } ) ;
child . ref = instance => {
ref ( instance ) ;
if ( instance ) tabIns [ child . props . tab ] = instance ;
} ;
2020-11-19 16:51:14 +01:00
tabBarItems . push ( { value : child . props . tab } ) ;
2020-09-19 21:32:19 +02:00
}
contentChildren . push ( child ) ;
}
if ( tabBarItems . length ) headerChildren . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . disCN . tabbarcontainer ,
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TabBar , {
className : BDFDB . disCN . tabbar ,
itemClassName : BDFDB . disCN . tabbaritem ,
type : InternalComponents . LibraryComponents . TabBar . Types . TOP ,
items : tabBarItems ,
2021-01-29 22:18:18 +01:00
onItemSelect : value => {
for ( let key in tabIns ) {
if ( key == value ) tabIns [ key ] . props . open = true ;
else delete tabIns [ key ] . props . open ;
2020-09-19 21:32:19 +02:00
}
2021-01-29 22:18:18 +01:00
BDFDB . ReactUtils . forceUpdate ( BDFDB . ObjectUtils . toArray ( tabIns ) ) ;
2020-09-19 21:32:19 +02:00
}
} ) ,
config . tabBarChildren
] . flat ( 10 ) . filter ( n => n )
} ) ) ;
}
2021-01-29 22:18:18 +01:00
2020-09-19 21:32:19 +02:00
if ( BDFDB . ArrayUtils . is ( config . buttons ) ) for ( let button of config . buttons ) {
let contents = typeof button . contents == "string" && button . contents ;
if ( contents ) {
let color = typeof button . color == "string" && InternalComponents . LibraryComponents . Button . Colors [ button . color . toUpperCase ( ) ] ;
let look = typeof button . look == "string" && InternalComponents . LibraryComponents . Button . Looks [ button . look . toUpperCase ( ) ] ;
let click = typeof button . click == "function" ? button . click : ( typeof button . onClick == "function" ? button . onClick : _ => { } ) ;
if ( button . cancel ) cancels . push ( click ) ;
footerChildren . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Button , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , button , {
look : look || ( color ? InternalComponents . LibraryComponents . Button . Looks . FILLED : InternalComponents . LibraryComponents . Button . Looks . LINK ) ,
color : color || InternalComponents . LibraryComponents . Button . Colors . PRIMARY ,
onClick : _ => {
if ( button . close ) closeModal ( ) ;
2021-01-29 22:18:18 +01:00
if ( ! ( button . close && button . cancel ) ) click ( modalInstance ) ;
2020-09-19 21:32:19 +02:00
} ,
children : contents
} ) , "click" , "close" , "cancel" , "contents" ) ) ) ;
}
}
2021-01-29 22:18:18 +01:00
2020-09-19 21:32:19 +02:00
contentChildren = contentChildren . concat ( config . contentChildren ) . filter ( n => n && ( typeof n == "string" || BDFDB . ReactUtils . isValidElement ( n ) ) ) ;
2020-12-21 21:27:22 +01:00
titleChildren = titleChildren . concat ( config . titleChildren ) . filter ( n => n && ( typeof n == "string" || BDFDB . ReactUtils . isValidElement ( n ) ) ) ;
2020-09-19 21:32:19 +02:00
headerChildren = headerChildren . concat ( config . headerChildren ) . filter ( n => n && ( typeof n == "string" || BDFDB . ReactUtils . isValidElement ( n ) ) ) ;
footerChildren = footerChildren . concat ( config . footerChildren ) . filter ( n => n && ( typeof n == "string" || BDFDB . ReactUtils . isValidElement ( n ) ) ) ;
2021-01-29 22:18:18 +01:00
2020-09-19 21:32:19 +02:00
if ( contentChildren . length ) {
if ( typeof config . onClose != "function" ) config . onClose = _ => { } ;
if ( typeof config . onOpen != "function" ) config . onOpen = _ => { } ;
let name = plugin . name || ( typeof plugin . getName == "function" ? plugin . getName ( ) : null ) ;
name = typeof name == "string" ? name : null ;
let oldTransitionState = 0 ;
LibraryModules . ModalUtils . openModal ( props => {
modalProps = props ;
return BDFDB . ReactUtils . createElement ( class BDFDB _Modal extends LibraryModules . React . Component {
2020-11-22 18:46:33 +01:00
render ( ) {
2020-09-19 21:32:19 +02:00
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ModalComponents . ModalRoot , {
className : BDFDB . DOMUtils . formatClassName ( name && ` ${ name } -modal ` , BDFDB . disCN . modalwrapper , config . className ) ,
size : typeof config . size == "string" && InternalComponents . LibraryComponents . ModalComponents . ModalSize [ config . size . toUpperCase ( ) ] || InternalComponents . LibraryComponents . ModalComponents . ModalSize . SMALL ,
transitionState : props . transitionState ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ModalComponents . ModalHeader , {
className : BDFDB . DOMUtils . formatClassName ( config . headerClassName , config . shade && BDFDB . disCN . modalheadershade , headerChildren . length && BDFDB . disCN . modalheaderhassibling ) ,
separator : config . headerSeparator || false ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormTitle , {
tag : InternalComponents . LibraryComponents . FormComponents . FormTitle . Tags . H4 ,
children : config . header
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextElement , {
size : InternalComponents . LibraryComponents . TextElement . Sizes . SIZE _12 ,
2021-01-23 18:50:24 +01:00
children : typeof config . subHeader == "string" || BDFDB . ReactUtils . isValidElement ( config . subHeader ) ? config . subHeader : ( name || "" )
2020-09-19 21:32:19 +02:00
} )
]
} ) ,
2020-12-21 21:27:22 +01:00
titleChildren ,
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ModalComponents . ModalCloseButton , {
onClick : closeModal
} )
2020-12-21 21:27:22 +01:00
] . flat ( 10 ) . filter ( n => n )
2020-09-19 21:32:19 +02:00
} ) ,
headerChildren . length ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
grow : 0 ,
shrink : 0 ,
children : headerChildren
} ) : null ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ModalComponents . ModalContent , {
className : config . contentClassName ,
scroller : config . scroller ,
direction : config . direction ,
content : config . content ,
children : contentChildren
} ) ,
footerChildren . length ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ModalComponents . ModalFooter , {
className : config . footerClassName ,
2020-10-08 17:35:36 +02:00
direction : config . footerDirection ,
2020-09-19 21:32:19 +02:00
children : footerChildren
} ) : null
]
} ) ;
}
2020-11-22 18:46:33 +01:00
componentDidMount ( ) {
2020-09-19 21:32:19 +02:00
modalInstance = this ;
2021-01-29 22:18:18 +01:00
if ( props . transitionState == 1 && props . transitionState > oldTransitionState ) config . onOpen ( modalInstance ) ;
2020-09-19 21:32:19 +02:00
oldTransitionState = props . transitionState ;
}
2020-11-22 18:46:33 +01:00
componentWillUnmount ( ) {
2021-01-29 22:18:18 +01:00
if ( props . transitionState == 3 ) {
for ( let cancel of cancels ) cancel ( modalInstance ) ;
config . onClose ( modalInstance ) ;
2020-09-19 21:32:19 +02:00
}
}
} , props , true ) ;
} , {
onCloseRequest : closeModal
} ) ;
}
} ;
BDFDB . ModalUtils . confirm = function ( plugin , text , callback ) {
if ( ! BDFDB . ObjectUtils . is ( plugin ) || typeof text != "string" ) return ;
2021-01-23 18:50:24 +01:00
BDFDB . ModalUtils . open ( plugin , {
text : text ,
header : BDFDB . LanguageUtils . LibraryStrings . confirm ,
className : BDFDB . disCN . modalconfirmmodal ,
scroller : false ,
buttons : [
{ contents : BDFDB . LanguageUtils . LanguageStrings . OKAY , close : true , color : "RED" , onClick : callback } ,
{ contents : BDFDB . LanguageUtils . LanguageStrings . CANCEL , close : true }
]
} ) ;
2020-09-19 21:32:19 +02:00
} ;
const RealMenuItems = BDFDB . ModuleUtils . findByProperties ( "MenuItem" , "MenuGroup" ) ;
BDFDB . ContextMenuUtils = { } ;
BDFDB . ContextMenuUtils . open = function ( plugin , e , children ) {
LibraryModules . ContextMenuUtils . openContextMenu ( e , function ( e ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Menu , {
navId : "bdfdb-context" ,
2021-02-04 20:12:57 +01:00
onClose : LibraryModules . ContextMenuUtils . closeContextMenu ,
2020-09-19 21:32:19 +02:00
children : children
} , true ) ;
} ) ;
} ;
BDFDB . ContextMenuUtils . close = function ( nodeOrInstance ) {
if ( ! BDFDB . ObjectUtils . is ( nodeOrInstance ) ) return ;
2020-11-19 16:51:14 +01:00
let instance = BDFDB . ReactUtils . findOwner ( nodeOrInstance , { props : "closeContextMenu" , up : true } ) ;
2020-09-19 21:32:19 +02:00
if ( BDFDB . ObjectUtils . is ( instance ) && instance . props && typeof instance . props . closeContextMenu == "function" ) instance . props . closeContextMenu ( ) ;
2021-02-04 20:12:57 +01:00
else LibraryModules . ContextMenuUtils . closeContextMenu ( ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . ContextMenuUtils . createItem = function ( component , props = { } ) {
if ( ! component ) return null ;
else {
2021-01-08 22:51:58 +01:00
if ( props . render || props . persisting || BDFDB . ObjectUtils . is ( props . popoutProps ) || ( typeof props . color == "string" && ! DiscordClasses [ ` menu ${ props . color . toLowerCase ( ) } ` ] ) ) component = InternalComponents . MenuItem ;
2020-09-19 21:32:19 +02:00
if ( BDFDB . ObjectUtils . toArray ( RealMenuItems ) . some ( c => c == component ) ) return BDFDB . ReactUtils . createElement ( component , props ) ;
else return BDFDB . ReactUtils . createElement ( RealMenuItems . MenuItem , {
id : props . id ,
disabled : props . disabled ,
2021-01-08 22:51:58 +01:00
customItem : true ,
2020-09-19 21:32:19 +02:00
render : menuItemProps => {
if ( ! props . state ) props . state = BDFDB . ObjectUtils . extract ( props , "checked" , "value" ) ;
return BDFDB . ReactUtils . createElement ( InternalComponents . CustomMenuItemWrapper , {
disabled : props . disabled ,
childProps : Object . assign ( { } , props , menuItemProps , { color : props . color } ) ,
children : component
} , true ) ;
}
} ) ;
}
} ;
BDFDB . ContextMenuUtils . createItemId = function ( ... strings ) {
return strings . map ( s => typeof s == "number" ? s . toString ( ) : s ) . filter ( s => typeof s == "string" ) . map ( s => s . toLowerCase ( ) . replace ( /\s/ , "-" ) ) . join ( "-" ) ;
} ;
BDFDB . ContextMenuUtils . findItem = function ( returnvalue , config ) {
if ( ! returnvalue || ! BDFDB . ObjectUtils . is ( config ) || ! config . label && ! config . id ) return [ null , - 1 ] ;
config . label = config . label && [ config . label ] . flat ( ) . filter ( n => n ) ;
config . id = config . id && [ config . id ] . flat ( ) . filter ( n => n ) ;
let contextMenu = BDFDB . ReactUtils . findChild ( returnvalue , { props : "navId" } ) ;
if ( contextMenu ) {
for ( let i in contextMenu . props . children ) {
if ( contextMenu . props . children [ i ] && contextMenu . props . children [ i ] . type == RealMenuItems . MenuGroup ) {
if ( BDFDB . ArrayUtils . is ( contextMenu . props . children [ i ] . props . children ) ) {
for ( let j in contextMenu . props . children [ i ] . props . children ) if ( check ( contextMenu . props . children [ i ] . props . children [ j ] ) ) {
if ( config . group ) return [ contextMenu . props . children , parseInt ( i ) ] ;
else return [ contextMenu . props . children [ i ] . props . children , parseInt ( j ) ] ;
}
}
else if ( contextMenu . props . children [ i ] && contextMenu . props . children [ i ] . props ) {
if ( check ( contextMenu . props . children [ i ] . props . children ) ) {
if ( config . group ) return [ contextMenu . props . children , parseInt ( i ) ] ;
else {
contextMenu . props . children [ i ] . props . children = [ contextMenu . props . children [ i ] . props . children ] ;
return [ contextMenu . props . children [ i ] . props . children , 0 ] ;
}
}
else if ( contextMenu . props . children [ i ] . props . children && contextMenu . props . children [ i ] . props . children . props && BDFDB . ArrayUtils . is ( contextMenu . props . children [ i ] . props . children . props . children ) ) {
for ( let j in contextMenu . props . children [ i ] . props . children . props . children ) if ( check ( contextMenu . props . children [ i ] . props . children . props . children [ j ] ) ) {
if ( config . group ) return [ contextMenu . props . children , parseInt ( i ) ] ;
else return [ contextMenu . props . children [ i ] . props . children . props . children , parseInt ( j ) ] ;
}
}
}
}
else if ( check ( contextMenu . props . children [ i ] ) ) return [ contextMenu . props . children , parseInt ( i ) ] ;
}
return [ contextMenu . props . children , - 1 ] ;
}
return [ null , - 1 ] ;
function check ( child ) {
if ( ! child ) return false ;
let props = child . stateNode ? child . stateNode . props : child . props ;
if ( ! props ) return false ;
return config . id && config . id . some ( key => props . id == key ) || config . label && config . label . some ( key => props . label == key ) ;
}
} ;
BDFDB . StringUtils = { } ;
BDFDB . StringUtils . htmlEscape = function ( string ) {
let ele = document . createElement ( "div" ) ;
ele . innerText = string ;
return ele . innerHTML ;
} ;
BDFDB . StringUtils . regEscape = function ( string ) {
return typeof string == "string" && string . replace ( /([\-\/\\\^\$\*\+\?\.\(\)\|\[\]\{\}])/g , "\\$1" ) ;
} ;
BDFDB . StringUtils . insertNRST = function ( string ) {
return typeof string == "string" && string . replace ( /\\r/g , "\r" ) . replace ( /\\n/g , "\n" ) . replace ( /\\t/g , "\t" ) . replace ( /\\s/g , " " ) ;
} ;
BDFDB . StringUtils . highlight = function ( string , searchstring , prefix = ` <span class=" ${ BDFDB . disCN . highlight } "> ` , suffix = ` </span> ` ) {
if ( typeof string != "string" || ! searchstring || searchstring . length < 1 ) return string ;
let offset = 0 , original = string ;
BDFDB . ArrayUtils . getAllIndexes ( string . toUpperCase ( ) , searchstring . toUpperCase ( ) ) . forEach ( index => {
let d1 = offset * ( prefix . length + suffix . length ) ;
index = index + d1 ;
let d2 = index + searchstring . length ;
let d3 = [ - 1 ] . concat ( BDFDB . ArrayUtils . getAllIndexes ( string . substring ( 0 , index ) , "<" ) ) ;
let d4 = [ - 1 ] . concat ( BDFDB . ArrayUtils . getAllIndexes ( string . substring ( 0 , index ) , ">" ) ) ;
if ( d3 [ d3 . length - 1 ] > d4 [ d4 . length - 1 ] ) return ;
string = string . substring ( 0 , index ) + prefix + string . substring ( index , d2 ) + suffix + string . substring ( d2 ) ;
offset ++ ;
} ) ;
return string || original ;
} ;
2020-09-26 17:30:44 +02:00
BDFDB . StringUtils . findMatchCaseless = function ( match , string , any ) {
2020-09-26 20:11:27 +02:00
if ( typeof match != "string" || typeof string != "string" || ! match || ! string ) return "" ;
match = BDFDB . StringUtils . regEscape ( match ) ;
2020-09-26 17:30:44 +02:00
let exec = ( new RegExp ( any ? ` ([ \\ n \\ r \\ s]+ ${ match } )|(^ ${ match } ) ` : ` ([ \\ n \\ r \\ s]+ ${ match } [ \\ n \\ r \\ s]+)|([ \\ n \\ r \\ s]+ ${ match } $ )|(^ ${ match } [ \\ n \\ r \\ s]+)|(^ ${ match } $ ) ` , "i" ) ) . exec ( string ) ;
2020-09-26 17:16:07 +02:00
return exec && typeof exec [ 0 ] == "string" && exec [ 0 ] . replace ( /[\n\r\s]/g , "" ) || "" ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . StringUtils . extractSelection = function ( original , selection ) {
if ( typeof original != "string" ) return "" ;
if ( typeof selection != "string" ) return original ;
let s = [ ] , f = [ ] , wrong = 0 , canceled = false , done = false ;
for ( let i of BDFDB . ArrayUtils . getAllIndexes ( original , selection [ 0 ] ) ) if ( ! done ) {
while ( i <= original . length && ! done ) {
let subSelection = selection . slice ( s . filter ( n => n != undefined ) . length ) ;
if ( ! subSelection && s . length - 20 <= selection . length ) done = true ;
else for ( let j in subSelection ) if ( ! done && ! canceled ) {
if ( original [ i ] == subSelection [ j ] ) {
s [ i ] = subSelection [ j ] ;
f [ i ] = subSelection [ j ] ;
wrong = 0 ;
if ( i == original . length ) done = true ;
}
else {
s [ i ] = null ;
f [ i ] = original [ i ] ;
wrong ++ ;
if ( wrong > 4 ) {
s = [ ] , f = [ ] , wrong = 0 , canceled = true ;
break ;
}
}
break ;
}
canceled = false ;
i ++ ;
}
}
if ( s . filter ( n => n ) . length ) {
let reverseS = [ ] . concat ( s ) . reverse ( ) , i = 0 , j = 0 ;
for ( let k in s ) {
if ( s [ k ] == null ) i = parseInt ( k ) + 1 ;
else break ;
}
for ( let k in reverseS ) {
if ( reverseS [ k ] == null ) j = parseInt ( k ) + 1 ;
else break ;
}
return f . slice ( i , f . length - j ) . join ( "" ) ;
}
else return original ;
} ;
BDFDB . SlateUtils = { } ;
BDFDB . SlateUtils . isRichValue = function ( richValue ) {
return BDFDB . ObjectUtils . is ( richValue ) && LibraryModules . SlateUtils . deserialize ( "" ) . constructor . prototype . isPrototypeOf ( richValue ) ;
} ;
BDFDB . SlateUtils . copyRichValue = function ( string , richValue ) {
let newRichValue = LibraryModules . SlateUtils . deserialize ( string ) ;
if ( BDFDB . SlateUtils . isRichValue ( richValue ) && richValue . _map && richValue . _map . _root && BDFDB . ArrayUtils . is ( richValue . _map . _root . entries ) ) {
for ( let i in richValue . _map . _root . entries ) if ( richValue . _map . _root . entries [ i ] [ 0 ] == "selection" ) {
newRichValue . _map . _root . entries [ i ] = richValue . _map . _root . entries [ i ] ;
break ;
}
}
return newRichValue ;
} ;
BDFDB . NumberUtils = { } ;
BDFDB . NumberUtils . formatBytes = function ( bytes , sigDigits ) {
bytes = parseInt ( bytes ) ;
if ( isNaN ( bytes ) || bytes < 0 ) return "0 Bytes" ;
if ( bytes == 1 ) return "1 Byte" ;
let size = Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) ;
return parseFloat ( ( bytes / Math . pow ( 1024 , size ) ) . toFixed ( sigDigits < 1 ? 0 : sigDigits > 20 ? 20 : sigDigits || 2 ) ) + " " + [ "Bytes" , "KB" , "MB" , "GB" , "TB" , "PB" , "EB" , "ZB" , "YB" ] [ size ] ;
} ;
BDFDB . NumberUtils . mapRange = function ( from , to , value ) {
if ( parseFloat ( value ) < parseFloat ( from [ 0 ] ) ) return parseFloat ( to [ 0 ] ) ;
else if ( parseFloat ( value ) > parseFloat ( from [ 1 ] ) ) return parseFloat ( to [ 1 ] ) ;
else return parseFloat ( to [ 0 ] ) + ( parseFloat ( value ) - parseFloat ( from [ 0 ] ) ) * ( parseFloat ( to [ 1 ] ) - parseFloat ( to [ 0 ] ) ) / ( parseFloat ( from [ 1 ] ) - parseFloat ( from [ 0 ] ) ) ;
} ;
BDFDB . NumberUtils . generateId = function ( array ) {
array = BDFDB . ArrayUtils . is ( array ) ? array : [ ] ;
let id = Math . floor ( Math . random ( ) * 10000000000000000 ) ;
if ( array . includes ( id ) ) return BDFDB . NumberUtils . generateId ( array ) ;
else {
array . push ( id ) ;
return id ;
}
} ;
2020-11-02 23:15:43 +01:00
BDFDB . NumberUtils . compareVersions = function ( newV , oldV ) {
if ( ! newV || ! oldV ) return true ;
newV = newV . toString ( ) . replace ( /["'`]/g , "" ) . split ( /,|\./g ) . map ( n => parseInt ( n ) ) . filter ( n => ( n || n == 0 ) && ! isNaN ( n ) ) ;
oldV = oldV . toString ( ) . replace ( /["'`]/g , "" ) . split ( /,|\./g ) . map ( n => parseInt ( n ) ) . filter ( n => ( n || n == 0 ) && ! isNaN ( n ) ) ;
let length = Math . max ( newV . length , oldV . length ) ;
2020-09-19 21:32:19 +02:00
if ( ! length ) return true ;
2020-11-02 23:15:43 +01:00
if ( newV . length > oldV . length ) {
let tempArray = new Array ( newV . length - oldV . length ) ;
for ( let i = 0 ; i < tempArray . length ; i ++ ) tempArray [ i ] = 0 ;
oldV = tempArray . concat ( oldV ) ;
2020-09-19 21:32:19 +02:00
}
2020-11-02 23:15:43 +01:00
else if ( newV . length < oldV . length ) {
let tempArray = new Array ( oldV . length - newV . length ) ;
for ( let i = 0 ; i < tempArray . length ; i ++ ) tempArray [ i ] = 0 ;
newV = tempArray . concat ( newV ) ;
2020-09-19 21:32:19 +02:00
}
2020-11-03 12:56:51 +01:00
for ( let i = 0 ; i < length ; i ++ ) for ( let iOutdated = false , j = 0 ; j <= i ; j ++ ) {
2020-11-02 23:15:43 +01:00
if ( j == i && newV [ j ] < oldV [ j ] ) return false ;
2020-11-03 12:56:51 +01:00
if ( j < i ) iOutdated = newV [ j ] == oldV [ j ] ;
if ( ( j == 0 || iOutdated ) && j == i && newV [ j ] > oldV [ j ] ) return true ;
2020-09-19 21:32:19 +02:00
}
return false ;
} ;
2020-11-02 23:15:43 +01:00
BDFDB . NumberUtils . getVersionDifference = function ( newV , oldV ) {
if ( ! newV || ! oldV ) return false ;
newV = newV . toString ( ) . replace ( /["'`]/g , "" ) . split ( /,|\./g ) . map ( n => parseInt ( n ) ) . filter ( n => ( n || n == 0 ) && ! isNaN ( n ) ) ;
oldV = oldV . toString ( ) . replace ( /["'`]/g , "" ) . split ( /,|\./g ) . map ( n => parseInt ( n ) ) . filter ( n => ( n || n == 0 ) && ! isNaN ( n ) ) ;
let length = Math . max ( newV . length , oldV . length ) ;
2020-09-19 21:32:19 +02:00
if ( ! length ) return false ;
2020-11-02 23:15:43 +01:00
if ( newV . length > oldV . length ) {
let tempArray = new Array ( newV . length - oldV . length ) ;
for ( let i = 0 ; i < tempArray . length ; i ++ ) tempArray [ i ] = 0 ;
oldV = tempArray . concat ( oldV ) ;
2020-09-19 21:32:19 +02:00
}
2020-11-02 23:15:43 +01:00
else if ( newV . length < oldV . length ) {
let tempArray = new Array ( oldV . length - newV . length ) ;
for ( let i = 0 ; i < tempArray . length ; i ++ ) tempArray [ i ] = 0 ;
newV = tempArray . concat ( newV ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-10 11:41:01 +01:00
let oldValue = 0 , newValue = 0 ;
for ( let i in oldV . reverse ( ) ) oldValue += ( oldV [ i ] * ( 10 * * i ) ) ;
2020-11-02 23:15:43 +01:00
for ( let i in newV . reverse ( ) ) newValue += ( newV [ i ] * ( 10 * * i ) ) ;
2021-01-10 11:41:01 +01:00
return ( newValue - oldValue ) / ( 10 * * ( length - 1 ) ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DiscordUtils = { } ;
2021-01-23 19:03:55 +01:00
BDFDB . DiscordUtils . openLink = function ( url , config = { } ) {
2021-01-28 16:07:18 +01:00
if ( ( config . inBuilt || config . inBuilt === undefined && settings . useChromium ) && LibraryRequires . electron && LibraryRequires . electron . remote ) {
2020-09-19 21:32:19 +02:00
let browserWindow = new LibraryRequires . electron . remote . BrowserWindow ( {
frame : true ,
resizeable : true ,
show : true ,
darkTheme : BDFDB . DiscordUtils . getTheme ( ) == BDFDB . disCN . themedark ,
webPreferences : {
nodeIntegration : false ,
nodeIntegrationInWorker : false
}
} ) ;
browserWindow . setMenu ( null ) ;
browserWindow . loadURL ( url ) ;
2021-01-23 19:03:55 +01:00
if ( config . minimized ) browserWindow . minimize ( null ) ;
2020-09-19 21:32:19 +02:00
}
2021-01-10 11:41:01 +01:00
else window . open ( url , "_blank" ) ;
2020-09-19 21:32:19 +02:00
} ;
2021-02-03 12:02:17 +01:00
window . DiscordNative && window . DiscordNative . app && window . DiscordNative . app . getPath ( "appData" ) . then ( path => { BDFDB . DiscordUtils . getFolder . base = path ; } ) ;
2020-09-19 21:32:19 +02:00
BDFDB . DiscordUtils . getFolder = function ( ) {
2021-02-03 12:02:17 +01:00
if ( ! BDFDB . DiscordUtils . getFolder . base ) return "" ;
else if ( BDFDB . DiscordUtils . getFolder . folder ) return BDFDB . DiscordUtils . getFolder . folder ;
else {
let folder ;
try {
2021-02-03 13:00:57 +01:00
let build = BDFDB . DiscordUtils . getBuild ( ) ;
build = "discord" + ( build == "stable" ? "" : build ) ;
folder = LibraryRequires . path . resolve ( BDFDB . DiscordUtils . getFolder . base , build , BDFDB . DiscordUtils . getVersion ( ) ) ;
2021-02-03 12:02:17 +01:00
}
catch ( err ) { folder = BDFDB . DiscordUtils . getFolder . base ; }
return BDFDB . DiscordUtils . getFolder . folder = folder ;
}
2020-09-19 21:32:19 +02:00
} ;
2021-02-03 13:00:57 +01:00
BDFDB . DiscordUtils . getBuild = function ( ) {
if ( BDFDB . DiscordUtils . getBuild . build ) return BDFDB . DiscordUtils . getBuild . build ;
2020-09-19 21:32:19 +02:00
else {
2021-02-03 13:00:57 +01:00
let build ;
try { build = window . DiscordNative . app . getReleaseChannel ( ) ; }
2020-09-19 21:32:19 +02:00
catch ( err ) {
2021-02-03 12:02:17 +01:00
let version = BDFDB . DiscordUtils . getVersion ( ) ;
if ( version ) {
version = version . split ( "." ) ;
2021-02-03 13:00:57 +01:00
if ( version . length == 3 && ! isNaN ( version = parseInt ( version [ 2 ] ) ) ) build = version > 300 ? "stable" : version > 200 ? "canary" : "ptb" ;
else build = "stable" ;
2020-09-19 21:32:19 +02:00
}
2021-02-03 13:00:57 +01:00
else build = "stable" ;
2020-09-19 21:32:19 +02:00
}
2021-02-03 13:00:57 +01:00
return BDFDB . DiscordUtils . getBuild . build = build ;
2020-09-19 21:32:19 +02:00
}
} ;
BDFDB . DiscordUtils . getVersion = function ( ) {
2021-02-02 13:02:27 +01:00
if ( BDFDB . DiscordUtils . getVersion . version ) return BDFDB . DiscordUtils . getVersion . version ;
2020-09-19 21:32:19 +02:00
else {
2021-02-03 12:02:17 +01:00
let version ;
try { version = window . DiscordNative . app . getVersion ( ) ; }
catch ( err ) { version = "999.999.9999" ; }
return BDFDB . DiscordUtils . getVersion . version = version ;
2020-09-19 21:32:19 +02:00
}
} ;
BDFDB . DiscordUtils . isDevModeEnabled = function ( ) {
2020-09-30 17:50:04 +02:00
return ( LibraryModules . StoreChangeUtils . get ( "UserSettingsStore" ) || { } ) . developerMode ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DiscordUtils . getTheme = function ( ) {
2020-09-30 17:50:04 +02:00
return ( LibraryModules . StoreChangeUtils . get ( "UserSettingsStore" ) || { } ) . theme != "dark" ? BDFDB . disCN . themelight : BDFDB . disCN . themedark ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DiscordUtils . getMode = function ( ) {
2020-09-30 17:50:04 +02:00
return ( LibraryModules . StoreChangeUtils . get ( "UserSettingsStore" ) || { } ) . message _display _compact ? "compact" : "cozy" ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . DiscordUtils . getZoomFactor = function ( ) {
let aRects = BDFDB . DOMUtils . getRects ( document . querySelector ( BDFDB . dotCN . appmount ) ) ;
let widthZoom = Math . round ( 100 * window . outerWidth / aRects . width ) ;
let heightZoom = Math . round ( 100 * window . outerHeight / aRects . height ) ;
return widthZoom < heightZoom ? widthZoom : heightZoom ;
} ;
BDFDB . DiscordUtils . getFontScale = function ( ) {
return parseInt ( document . firstElementChild . style . fontSize . replace ( "%" , "" ) ) ;
} ;
BDFDB . DiscordUtils . shake = function ( ) {
2021-01-30 12:36:34 +01:00
BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . appcontainer ) , { name : "Shakeable" , unlimited : true , up : true } ) . shake ( ) ;
} ;
BDFDB . DiscordUtils . rerenderAll = function ( instant ) {
BDFDB . TimeUtils . clear ( BDFDB . DiscordUtils . rerenderAll . timeout ) ;
2021-02-02 10:49:58 +01:00
BDFDB . DiscordUtils . rerenderAll . timeout = BDFDB . TimeUtils . timeout ( _ => {
2021-01-30 12:36:34 +01:00
let ShakeableIns = BDFDB . ReactUtils . findOwner ( document . querySelector ( BDFDB . dotCN . appcontainer ) , { name : "Shakeable" , unlimited : true , up : true } ) ;
let ShakeablePrototype = BDFDB . ObjectUtils . get ( ShakeableIns , ` ${ BDFDB . ReactUtils . instanceKey } .type.prototype ` ) ;
if ( ShakeableIns && ShakeablePrototype ) {
BDFDB . PatchUtils . patch ( { name : "BDFDB DiscordUtils" } , ShakeablePrototype , "render" , { after : e => {
e . returnValue . props . children = typeof e . returnValue . props . children == "function" ? ( _ => { return null ; } ) : [ ] ;
BDFDB . ReactUtils . forceUpdate ( ShakeableIns ) ;
} } , { once : true } ) ;
BDFDB . ReactUtils . forceUpdate ( ShakeableIns ) ;
}
} , instant ? 0 : 1000 ) ;
2020-09-19 21:32:19 +02:00
} ;
BDFDB . WindowUtils = { } ;
2021-01-23 19:03:55 +01:00
BDFDB . WindowUtils . open = function ( plugin , url , config = { } ) {
2020-09-19 21:32:19 +02:00
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
2021-01-28 16:07:18 +01:00
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! url || ! LibraryRequires . electron || ! LibraryRequires . electron . remote ) return ;
2020-09-19 21:32:19 +02:00
if ( ! BDFDB . ArrayUtils . is ( plugin . browserWindows ) ) plugin . browserWindows = [ ] ;
2021-01-23 19:03:55 +01:00
config = Object . assign ( {
2020-09-19 21:32:19 +02:00
show : false ,
webPreferences : {
nodeIntegration : true ,
nodeIntegrationInWorker : true
}
2021-01-23 19:03:55 +01:00
} , config ) ;
2020-09-19 21:32:19 +02:00
let browserWindow = new LibraryRequires . electron . remote . BrowserWindow ( BDFDB . ObjectUtils . exclude ( config , "showOnReady" , "onLoad" ) ) ;
if ( ! config . show && config . showOnReady ) browserWindow . once ( "ready-to-show" , browserWindow . show ) ;
if ( config . devTools ) browserWindow . openDevTools ( ) ;
if ( typeof config . onLoad == "function" ) browserWindow . webContents . on ( "did-finish-load" , ( ... args ) => { config . onLoad ( ... args ) ; } ) ;
if ( typeof config . onClose == "function" ) browserWindow . once ( "closed" , ( ... args ) => { config . onClose ( ... args ) ; } ) ;
if ( typeof browserWindow . removeMenu == "function" ) browserWindow . removeMenu ( ) ;
else browserWindow . setMenu ( null ) ;
browserWindow . loadURL ( url ) ;
browserWindow . executeJavaScriptSafe = js => { if ( ! browserWindow . isDestroyed ( ) ) browserWindow . webContents . executeJavaScript ( ` (_ => { ${ js } })(); ` ) ; } ;
plugin . browserWindows . push ( browserWindow ) ;
return browserWindow ;
} ;
BDFDB . WindowUtils . close = function ( browserWindow ) {
if ( BDFDB . ObjectUtils . is ( browserWindow ) && ! browserWindow . isDestroyed ( ) && browserWindow . isClosable ( ) ) browserWindow . close ( ) ;
} ;
BDFDB . WindowUtils . closeAll = function ( plugin ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ArrayUtils . is ( plugin . browserWindows ) ) return ;
while ( plugin . browserWindows . length ) BDFDB . WindowUtils . close ( plugin . browserWindows . pop ( ) ) ;
} ;
BDFDB . WindowUtils . addListener = function ( plugin , actions , callback ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! actions || typeof callback != "function" ) return ;
BDFDB . WindowUtils . removeListener ( plugin , actions ) ;
for ( let action of actions . split ( " " ) ) {
action = action . split ( "." ) ;
let eventName = action . shift ( ) ;
if ( ! eventName ) return ;
let namespace = ( action . join ( "." ) || "" ) + plugin . name ;
if ( ! BDFDB . ArrayUtils . is ( plugin . ipcListeners ) ) plugin . ipcListeners = [ ] ;
plugin . ipcListeners . push ( { eventName , namespace , callback } ) ;
LibraryRequires . electron . ipcRenderer . on ( eventName , callback ) ;
}
} ;
BDFDB . WindowUtils . removeListener = function ( plugin , actions = "" ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( ! BDFDB . ObjectUtils . is ( plugin ) || ! BDFDB . ArrayUtils . is ( plugin . ipcListeners ) ) return ;
if ( actions ) {
for ( let action of actions . split ( " " ) ) {
action = action . split ( "." ) ;
let eventName = action . shift ( ) ;
let namespace = ( action . join ( "." ) || "" ) + plugin . name ;
for ( let listener of plugin . ipcListeners ) {
let removedListeners = [ ] ;
if ( listener . eventName == eventName && listener . namespace == namespace ) {
LibraryRequires . electron . ipcRenderer . off ( listener . eventName , listener . callback ) ;
removedListeners . push ( listener ) ;
}
if ( removedListeners . length ) plugin . ipcListeners = plugin . ipcListeners . filter ( listener => { return removedListeners . indexOf ( listener ) < 0 ; } ) ;
}
}
}
else {
for ( let listener of plugin . ipcListeners ) LibraryRequires . electron . ipcRenderer . off ( listener . eventName , listener . callback ) ;
plugin . ipcListeners = [ ] ;
}
} ;
const DiscordClassModules = Object . assign ( { } , InternalData . CustomClassModules ) ;
for ( let name in InternalData . DiscordClassModules ) {
if ( InternalData . DiscordClassModules [ name ] . length ) DiscordClassModules [ name ] = BDFDB . ModuleUtils . find ( m => InternalData . DiscordClassModules [ name ] . props . every ( prop => typeof m [ prop ] == "string" ) && ( InternalData . DiscordClassModules [ name ] . smaller ? Object . keys ( m ) . length < InternalData . DiscordClassModules [ name ] . length : Object . keys ( m ) . length == InternalData . DiscordClassModules [ name ] . length ) ) ;
else DiscordClassModules [ name ] = BDFDB . ModuleUtils . findByProperties ( InternalData . DiscordClassModules [ name ] . props ) ;
}
BDFDB . DiscordClassModules = Object . assign ( { } , DiscordClassModules ) ;
const DiscordClasses = Object . assign ( { } , InternalData . DiscordClasses ) ;
BDFDB . DiscordClasses = Object . assign ( { } , DiscordClasses ) ;
2020-09-23 08:08:23 +02:00
InternalBDFDB . getDiscordClass = function ( item , selector ) {
let className = fallbackClassName = DiscordClassModules . BDFDB . BDFDBundefined + "-" + InternalBDFDB . generateClassId ( ) ;
2020-09-19 21:32:19 +02:00
if ( DiscordClasses [ item ] === undefined ) {
BDFDB . LogUtils . warn ( item + " not found in DiscordClasses" ) ;
return className ;
}
else if ( ! BDFDB . ArrayUtils . is ( DiscordClasses [ item ] ) || DiscordClasses [ item ] . length != 2 ) {
BDFDB . LogUtils . warn ( item + " is not an Array of Length 2 in DiscordClasses" ) ;
return className ;
}
else if ( DiscordClassModules [ DiscordClasses [ item ] [ 0 ] ] === undefined ) {
BDFDB . LogUtils . warn ( DiscordClasses [ item ] [ 0 ] + " not found in DiscordClassModules" ) ;
return className ;
}
2020-09-20 13:29:55 +02:00
else if ( [ DiscordClasses [ item ] [ 1 ] ] . flat ( ) . every ( prop => DiscordClassModules [ DiscordClasses [ item ] [ 0 ] ] [ prop ] === undefined ) ) {
2020-09-19 21:32:19 +02:00
BDFDB . LogUtils . warn ( DiscordClasses [ item ] [ 1 ] + " not found in " + DiscordClasses [ item ] [ 0 ] + " in DiscordClassModules" ) ;
return className ;
}
else {
2020-09-20 13:29:55 +02:00
for ( let prop of [ DiscordClasses [ item ] [ 1 ] ] . flat ( ) ) {
className = DiscordClassModules [ DiscordClasses [ item ] [ 0 ] ] [ prop ] ;
if ( className ) break ;
2020-09-23 08:08:23 +02:00
else className = fallbackClassName ;
2020-09-20 13:29:55 +02:00
}
2020-09-19 21:32:19 +02:00
if ( selector ) {
className = className . split ( " " ) . filter ( n => n . indexOf ( "da-" ) != 0 ) . join ( selector ? "." : " " ) ;
2020-09-23 08:08:23 +02:00
className = className || fallbackClassName ;
2020-09-19 21:32:19 +02:00
}
2020-09-23 08:08:23 +02:00
return BDFDB . ArrayUtils . removeCopies ( className . split ( " " ) ) . join ( " " ) || fallbackClassName ;
2020-09-19 21:32:19 +02:00
}
} ;
2020-09-23 08:08:23 +02:00
const generationChars = "0123456789ABCDEFGHIJKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_" . split ( "" ) ;
InternalBDFDB . generateClassId = function ( ) {
let id = "" ;
while ( id . length < 6 ) id += generationChars [ Math . floor ( Math . random ( ) * generationChars . length ) ] ;
return id ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . disCN = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
return InternalBDFDB . getDiscordClass ( item , false ) . replace ( "#" , "" ) ;
}
} ) ;
BDFDB . disCNS = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
return InternalBDFDB . getDiscordClass ( item , false ) . replace ( "#" , "" ) + " " ;
}
} ) ;
BDFDB . disCNC = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
return InternalBDFDB . getDiscordClass ( item , false ) . replace ( "#" , "" ) + "," ;
}
} ) ;
BDFDB . dotCN = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
let className = InternalBDFDB . getDiscordClass ( item , true ) ;
return ( className . indexOf ( "#" ) == 0 ? "" : "." ) + className ;
}
} ) ;
BDFDB . dotCNS = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
let className = InternalBDFDB . getDiscordClass ( item , true ) ;
return ( className . indexOf ( "#" ) == 0 ? "" : "." ) + className + " " ;
}
} ) ;
BDFDB . dotCNC = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
let className = InternalBDFDB . getDiscordClass ( item , true ) ;
return ( className . indexOf ( "#" ) == 0 ? "" : "." ) + className + "," ;
}
} ) ;
BDFDB . notCN = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
return ` :not(. ${ InternalBDFDB . getDiscordClass ( item , true ) . split ( "." ) [ 0 ] } ) ` ;
}
} ) ;
BDFDB . notCNS = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
return ` :not(. ${ InternalBDFDB . getDiscordClass ( item , true ) . split ( "." ) [ 0 ] } ) ` ;
}
} ) ;
BDFDB . notCNC = new Proxy ( DiscordClasses , {
get : function ( list , item ) {
return ` :not(. ${ InternalBDFDB . getDiscordClass ( item , true ) . split ( "." ) [ 0 ] } ), ` ;
}
} ) ;
const LanguageStrings = LibraryModules . LanguageStore && LibraryModules . LanguageStore . _proxyContext ? Object . assign ( { } , LibraryModules . LanguageStore . _proxyContext . defaultMessages ) : { } ;
const LibraryStrings = Object . assign ( { } , InternalData . LibraryStrings ) ;
BDFDB . LanguageUtils = { } ;
BDFDB . LanguageUtils . languages = Object . assign ( { } , InternalData . Languages ) ;
BDFDB . LanguageUtils . getLanguage = function ( ) {
let lang = LibraryModules . LanguageStore . chosenLocale || "en" ;
if ( lang == "en-GB" || lang == "en-US" ) lang = "en" ;
let langIds = lang . split ( "-" ) ;
let langId = langIds [ 0 ] ;
let langId2 = langIds [ 1 ] || "" ;
lang = langId2 && langId . toUpperCase ( ) !== langId2 . toUpperCase ( ) ? langId + "-" + langId2 : langId ;
return BDFDB . LanguageUtils . languages [ lang ] || BDFDB . LanguageUtils . languages [ langId ] || BDFDB . LanguageUtils . languages [ "en" ] ;
} ;
BDFDB . LanguageUtils . LanguageStrings = new Proxy ( LanguageStrings , {
get : function ( list , item ) {
let stringObj = LibraryModules . LanguageStore . Messages [ item ] ;
if ( ! stringObj ) BDFDB . LogUtils . warn ( item + " not found in BDFDB.LanguageUtils.LanguageStrings" ) ;
else {
if ( stringObj && typeof stringObj == "object" && typeof stringObj . format == "function" ) return BDFDB . LanguageUtils . LanguageStringsFormat ( item ) ;
else return stringObj ;
}
return "" ;
}
} ) ;
BDFDB . LanguageUtils . LanguageStringsCheck = new Proxy ( LanguageStrings , {
get : function ( list , item ) {
return ! ! LibraryModules . LanguageStore . Messages [ item ] ;
}
} ) ;
let parseLanguageStringObj = obj => {
let string = "" ;
if ( typeof obj == "string" ) string += obj ;
else if ( BDFDB . ObjectUtils . is ( obj ) ) {
if ( obj . props ) string += parseLanguageStringObj ( obj . props ) ;
else if ( obj . type ) {
let text = obj . content || obj . children && obj . children [ 0 ] && obj . children [ 0 ] . toString ( ) || "" ;
if ( text ) {
if ( obj . type == "text" || obj . content ) string = parseLanguageStringObj ( text ) ;
else string += ` < ${ obj . type } > ${ parseLanguageStringObj ( text ) } </ ${ obj . type } > ` ;
}
}
}
else if ( BDFDB . ArrayUtils . is ( obj ) ) for ( let ele of obj ) string += parseLanguageStringObj ( ele ) ;
return string ;
} ;
BDFDB . LanguageUtils . LanguageStringsFormat = function ( item , ... values ) {
if ( item ) {
let stringObj = LibraryModules . LanguageStore . Messages [ item ] ;
if ( stringObj && typeof stringObj == "object" && typeof stringObj . format == "function" ) {
let i = 0 , returnvalue , formatVars = { } ;
while ( ! returnvalue && i < 10 ) {
i ++ ;
try { returnvalue = stringObj . format ( formatVars , false ) ; }
catch ( err ) {
returnvalue = null ;
let value = values . shift ( ) ;
formatVars [ err . toString ( ) . split ( "for: " ) [ 1 ] ] = value != null ? ( value === 0 ? "0" : value ) : "undefined" ;
}
}
if ( returnvalue ) return parseLanguageStringObj ( returnvalue ) ;
else {
BDFDB . LogUtils . warn ( item + " failed to format string in BDFDB.LanguageUtils.LanguageStrings" ) ;
return "" ;
}
}
else return BDFDB . LanguageUtils . LanguageStrings [ item ] ;
}
else BDFDB . LogUtils . warn ( item + " enter a valid key to format the string in BDFDB.LanguageUtils.LanguageStrings" ) ;
return "" ;
} ;
BDFDB . LanguageUtils . LibraryStrings = new Proxy ( LibraryStrings . default || { } , {
get : function ( list , item ) {
let languageId = BDFDB . LanguageUtils . getLanguage ( ) . id ;
if ( LibraryStrings [ languageId ] && LibraryStrings [ languageId ] [ item ] ) return LibraryStrings [ languageId ] [ item ] ;
else if ( LibraryStrings . default [ item ] ) return LibraryStrings . default [ item ] ;
else BDFDB . LogUtils . warn ( item + " not found in BDFDB.LanguageUtils.LibraryStrings" ) ;
return "" ;
}
} ) ;
BDFDB . LanguageUtils . LibraryStringsCheck = new Proxy ( LanguageStrings , {
get : function ( list , item ) {
return ! ! LibraryStrings . default [ item ] ;
}
} ) ;
BDFDB . LanguageUtils . LibraryStringsFormat = function ( item , ... values ) {
2020-12-24 11:46:03 +01:00
if ( item ) {
2020-09-19 21:32:19 +02:00
let languageId = BDFDB . LanguageUtils . getLanguage ( ) . id , string = null ;
if ( LibraryStrings [ languageId ] && LibraryStrings [ languageId ] [ item ] ) string = LibraryStrings [ languageId ] [ item ] ;
else if ( LibraryStrings . default [ item ] ) string = LibraryStrings . default [ item ] ;
if ( string ) {
2021-01-22 17:04:49 +01:00
for ( let i = 0 ; i < values . length ; i ++ ) if ( typeof values [ i ] == "string" || typeof values [ i ] == "number" ) string = string . replace ( new RegExp ( ` {{var ${ i } }} ` , "g" ) , values [ i ] ) ;
2020-09-19 21:32:19 +02:00
return string ;
}
else BDFDB . LogUtils . warn ( item + " not found in BDFDB.LanguageUtils.LibraryStrings" ) ;
}
2020-12-24 11:46:03 +01:00
else BDFDB . LogUtils . warn ( item + " enter a valid key to format the string in BDFDB.LanguageUtils.LibraryStrings" ) ;
2020-09-19 21:32:19 +02:00
return "" ;
} ;
BDFDB . TimeUtils . interval ( interval => {
if ( LibraryModules . LanguageStore . chosenLocale ) {
BDFDB . TimeUtils . clear ( interval ) ;
let language = BDFDB . LanguageUtils . getLanguage ( ) ;
if ( language ) BDFDB . LanguageUtils . languages . $discord = Object . assign ( { } , language , { name : ` Discord ( ${ language . name } ) ` } ) ;
}
} , 100 ) ;
const reactInitialized = LibraryModules . React && LibraryModules . React . Component ;
InternalBDFDB . setDefaultProps = function ( component , defaultProps ) {
if ( BDFDB . ObjectUtils . is ( component ) ) component . defaultProps = Object . assign ( { } , component . defaultProps , defaultProps ) ;
} ;
let openedItem ;
InternalComponents . MenuItem = reactInitialized && class BDFDB _MenuItem extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
this . state = { hovered : false } ;
}
componentWillUnmount ( ) {
if ( openedItem == this . props . id ) openedItem = null ;
}
render ( ) {
let color = ( typeof this . props . color == "string" ? this . props . color : InternalComponents . LibraryComponents . MenuItems . Colors . DEFAULT ) . toLowerCase ( ) ;
let isCustomColor = false ;
if ( color ) {
if ( DiscordClasses [ ` menu ${ color } ` ] ) color = color ;
else if ( BDFDB . ColorUtils . getType ( color ) ) {
isCustomColor = true ;
color = BDFDB . ColorUtils . convert ( color , "RGBA" ) ;
}
else color = ( InternalComponents . LibraryComponents . MenuItems . Colors . DEFAULT || "" ) . toLowerCase ( ) ;
}
let renderPopout , onClose , hasPopout = BDFDB . ObjectUtils . is ( this . props . popoutProps ) ;
if ( hasPopout ) {
renderPopout = instance => {
openedItem = this . props . id ;
return typeof this . props . popoutProps . renderPopout == "function" && this . props . popoutProps . renderPopout ( instance ) ;
} ;
onClose = instance => {
openedItem = null ;
typeof this . props . popoutProps . onClose == "function" && this . props . popoutProps . onClose ( instance ) ;
} ;
}
let focused = ! openedItem ? this . props . isFocused : openedItem == this . props . id ;
let themeDark = BDFDB . DiscordUtils . getTheme ( ) == BDFDB . disCN . themedark ;
let item = BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , Object . assign ( {
2021-01-08 22:51:58 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . menuitem , ( this . props . label || this . props . subtext ) && BDFDB . disCN . menulabelcontainer , color && ( isCustomColor ? BDFDB . disCN . menucolorcustom : BDFDB . disCN [ ` menu ${ color } ` ] ) , this . props . disabled && BDFDB . disCN . menudisabled , focused && BDFDB . disCN . menufocused ) ,
2020-09-19 21:32:19 +02:00
style : {
color : isCustomColor ? ( ( focused || this . state . hovered ) ? ( BDFDB . ColorUtils . isBright ( color ) ? "#000000" : "#ffffff" ) : color ) : ( this . state . hovered ? "#ffffff" : null ) ,
background : isCustomColor && ( focused || this . state . hovered ) && color
} ,
onClick : this . props . disabled ? null : e => {
if ( ! this . props . action ) return false ;
! this . props . persisting && ! hasPopout && this . props . onClose ( ) ;
this . props . action ( e , this ) ;
} ,
onMouseEnter : this . props . disabled ? null : e => {
2021-01-08 22:51:58 +01:00
if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ;
2020-09-19 21:32:19 +02:00
this . setState ( { hovered : true } ) ;
} ,
onMouseLeave : this . props . disabled ? null : e => {
2021-01-08 22:51:58 +01:00
if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ;
2020-09-19 21:32:19 +02:00
this . setState ( { hovered : false } ) ;
} ,
"aria-disabled" : this . props . disabled ,
children : [
2021-01-08 22:51:58 +01:00
typeof this . props . render == "function" ? this . props . render ( this ) : this . props . render ,
( this . props . label || this . props . subtext ) && BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . menulabel ,
children : [
typeof this . props . label == "function" ? this . props . label ( this ) : this . props . label ,
this . props . subtext && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . menusubtext ,
children : typeof this . props . subtext == "function" ? this . props . subtext ( this ) : this . props . subtext
} )
] . filter ( n => n )
} ) ,
this . props . hint && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . menuhintcontainer ,
children : typeof this . props . hint == "function" ? this . props . hint ( this ) : this . props . hint
} ) ,
this . props . icon && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . menuiconcontainer ,
children : BDFDB . ReactUtils . createElement ( this . props . icon , {
2021-01-08 23:52:55 +01:00
className : BDFDB . disCN . menuicon
2020-09-19 21:32:19 +02:00
} )
} ) ,
this . props . imageUrl && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . menuimagecontainer ,
children : BDFDB . ReactUtils . createElement ( "img" , {
className : BDFDB . disCN . menuimage ,
src : typeof this . props . imageUrl == "function" ? this . props . imageUrl ( this ) : this . props . imageUrl ,
alt : ""
} )
} )
] . filter ( n => n )
} , this . props . menuItemProps , { isFocused : focused } ) ) ;
return hasPopout ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PopoutContainer , Object . assign ( { } , this . props . popoutProps , {
children : item ,
renderPopout : renderPopout ,
onClose : onClose
} ) ) : item ;
}
} ;
InternalComponents . CustomMenuItemWrapper = reactInitialized && class BDFDB _CustomMenuItemWrapper extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
this . state = { hovered : false } ;
}
render ( ) {
2021-01-08 22:51:58 +01:00
let isItem = this . props . children == InternalComponents . MenuItem ;
let item = BDFDB . ReactUtils . createElement ( this . props . children , Object . assign ( { } , this . props . childProps , {
onMouseEnter : isItem ? e => {
if ( this . props . childProps && typeof this . props . childProps . onMouseEnter == "function" ) this . props . childProps . onMouseEnter ( e , this ) ;
this . setState ( { hovered : true } ) ;
} : this . props . childProps && this . props . childProps . onMouseEnter ,
onMouseLeave : isItem ? e => {
if ( this . props . childProps && typeof this . props . childProps . onMouseLeave == "function" ) this . props . childProps . onMouseLeave ( e , this ) ;
this . setState ( { hovered : false } ) ;
} : this . props . childProps && this . props . childProps . onMouseLeave ,
isFocused : this . state . hovered && ! this . props . disabled
} ) ) ;
return isItem ? item : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , {
2020-09-19 21:32:19 +02:00
onMouseEnter : e => {
this . setState ( { hovered : true } ) ;
} ,
onMouseLeave : e => {
this . setState ( { hovered : false } ) ;
} ,
2021-01-08 22:51:58 +01:00
children : item
2020-09-19 21:32:19 +02:00
} ) ;
}
} ;
InternalComponents . ErrorBoundary = reactInitialized && class BDFDB _ErrorBoundary extends LibraryModules . React . PureComponent {
constructor ( props ) {
super ( props ) ;
this . state = { hasError : false } ;
}
static getDerivedStateFromError ( error ) {
return { hasError : true } ;
}
componentDidCatch ( error , info ) {
BDFDB . LogUtils . error ( "Could not create react element! " + error ) ;
}
render ( ) {
if ( this . state . hasError ) return LibraryModules . React . createElement ( "span" , {
style : {
background : BDFDB . DiscordConstants && BDFDB . DiscordConstants . Colors && BDFDB . DiscordConstants . Colors . PRIMARY _DARK ,
borderRadius : 5 ,
color : BDFDB . DiscordConstants && BDFDB . DiscordConstants . Colors && BDFDB . DiscordConstants . Colors . STATUS _RED ,
fontSize : 12 ,
fontWeight : 600 ,
padding : 6 ,
textAlign : "center" ,
verticalAlign : "center"
} ,
children : "React Component Error"
} ) ;
return this . props . children ;
}
} ;
for ( let name in InternalData . NativeSubComponents ) {
if ( InternalData . NativeSubComponents [ name ] . name ) {
if ( InternalData . NativeSubComponents [ name ] . protos ) InternalComponents . NativeSubComponents [ name ] = BDFDB . ModuleUtils . find ( m => m && m . displayName == InternalData . NativeSubComponents [ name ] . name && m . prototype && InternalData . NativeSubComponents [ name ] . protos . every ( proto => m . prototype [ proto ] ) ) ;
else InternalComponents . NativeSubComponents [ name ] = BDFDB . ModuleUtils . findByName ( InternalData . NativeSubComponents [ name ] . name ) ;
}
else if ( InternalData . NativeSubComponents [ name ] . props ) InternalComponents . NativeSubComponents [ name ] = BDFDB . ModuleUtils . findByProperties ( InternalData . NativeSubComponents [ name ] . props ) ;
}
for ( let name in InternalData . LibraryComponents ) {
let module ;
if ( InternalData . LibraryComponents [ name ] . name ) module = BDFDB . ModuleUtils . findByName ( InternalData . LibraryComponents [ name ] . name ) ;
else if ( InternalData . LibraryComponents [ name ] . strings ) module = BDFDB . ModuleUtils . findByString ( InternalData . LibraryComponents [ name ] . strings ) ;
else if ( InternalData . LibraryComponents [ name ] . props ) module = BDFDB . ModuleUtils . findByProperties ( InternalData . LibraryComponents [ name ] . props ) ;
let child = name , parent = child . split ( " " ) , components = InternalComponents . LibraryComponents ;
if ( parent . length > 1 ) {
child = parent [ 1 ] , parent = parent [ 0 ] ;
if ( ! InternalComponents . LibraryComponents [ parent ] ) InternalComponents . LibraryComponents [ parent ] = { } ;
components = InternalComponents . LibraryComponents [ parent ] ;
}
if ( InternalData . LibraryComponents [ name ] . value ) module = ( module || { } ) [ InternalData . LibraryComponents [ name ] . value ] ;
if ( InternalData . LibraryComponents [ name ] . assign ) components [ child ] = Object . assign ( { } , module ) ;
else components [ child ] = module ;
}
InternalComponents . LibraryComponents . AddonCard = reactInitialized && class BDFDB _AddonCard extends LibraryModules . React . Component {
render ( ) {
2020-11-12 15:40:12 +01:00
if ( ! BDFDB . ObjectUtils . is ( this . props . data ) ) return null ;
2020-11-11 10:02:09 +01:00
let controls = [ ] . concat ( this . props . controls ) . flat ( 10 ) . filter ( n => n ) ;
let links = [ ] . concat ( this . props . links ) . flat ( 10 ) . filter ( n => n ) ;
let buttons = [ ] . concat ( this . props . buttons ) . flat ( 10 ) . filter ( n => n ) ;
2020-11-11 10:16:57 +01:00
let meta = [
2020-11-11 11:07:19 +01:00
! isBeta && " v" ,
2020-11-11 10:16:57 +01:00
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . _repoversion ,
2020-11-11 11:07:19 +01:00
children : isBeta ? ` v ${ this . props . data . version } ` : this . props . data . version
2020-11-11 10:16:57 +01:00
} ) ,
" by " ,
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . _repoauthor ,
children : this . props . data . author
} )
2020-11-11 11:07:19 +01:00
] . filter ( n => n ) ;
2020-11-12 15:40:12 +01:00
return BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _repoentry , this . props . className , BDFDB . disCN . _repocard , BDFDB . disCN . _reposettingsclosed , BDFDB . disCN . _repocheckboxitem ) ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _repoheader ,
style : { overflow : "visible" } ,
children : [
2020-11-12 17:11:25 +01:00
isBeta && this . props . icon ,
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . _repoheadertitle ,
children : [
BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . _reponame ,
children : this . props . data . name
} ) ,
2020-11-11 10:16:57 +01:00
isBeta ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _repometa ,
children : meta
} ) : meta
2020-09-19 21:32:19 +02:00
]
} ) ,
2020-11-11 17:08:40 +01:00
controls . length && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _repoheadercontrols ,
2020-11-11 10:02:09 +01:00
children : controls
2020-09-19 21:32:19 +02:00
} )
]
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _repodescriptionwrap ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _repodescription ,
2020-11-12 16:03:47 +01:00
children : this . props . data . description && BDFDB . ReactUtils . markdownParse ( this . props . data . description )
2020-09-19 21:32:19 +02:00
} )
} ) ,
2020-11-11 10:02:09 +01:00
( links . length || buttons . length ) && BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . _repofooter ,
children : [
2020-11-11 10:02:09 +01:00
links . length && BDFDB . ReactUtils . createElement ( "span" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . _repolinks ,
2020-11-11 10:02:09 +01:00
children : links . map ( ( data , i ) => {
if ( ! BDFDB . ObjectUtils . is ( data ) ) return ;
let link = BDFDB . ReactUtils . createElement ( "a" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _repolink , typeof data . label == "string" && BDFDB . disCN . _repolink + "-" + data . label . toLowerCase ( ) . replace ( /\s/g , "" ) ) ,
href : data . href ,
children : data . icon || data . label
} ) ;
2020-11-12 16:37:22 +01:00
if ( ! isBeta ) return [
2020-11-11 10:02:09 +01:00
i > 0 && " | " ,
link
2020-11-12 16:37:22 +01:00
] ;
else {
let button = BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . _repocontrolsbutton ,
children : link ,
onClick : e => {
if ( typeof data . onClick == "function" ) {
BDFDB . ListenerUtils . stopEvent ( e ) ;
data . onClick ( ) ;
}
2020-11-11 10:02:09 +01:00
}
2020-11-12 16:37:22 +01:00
} ) ;
return typeof data . label == "string" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
2020-11-11 10:02:09 +01:00
text : data . label ,
2020-11-12 16:37:22 +01:00
children : button
} ) : button ;
}
2020-11-11 10:02:09 +01:00
} ) . flat ( 10 ) . filter ( n => n )
2020-09-19 21:32:19 +02:00
} ) ,
2020-11-12 14:12:06 +01:00
buttons . length && BDFDB . ReactUtils . createElement ( "div" , {
2020-11-12 14:16:17 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _repofootercontrols , isBeta && BDFDB . disCN . _repocontrols ) ,
2020-11-12 14:12:06 +01:00
children : buttons
} )
2020-09-19 21:32:19 +02:00
] . flat ( 10 ) . filter ( n => n )
2020-11-11 10:02:09 +01:00
} )
] . filter ( n => n )
2020-09-19 21:32:19 +02:00
} ) ;
}
} ;
InternalComponents . LibraryComponents . BadgeAnimationContainer = reactInitialized && class BDFDB _BadgeAnimationContainer extends LibraryModules . React . Component {
componentDidMount ( ) { BDFDB . ReactUtils . forceUpdate ( this ) ; }
componentWillAppear ( e ) { if ( typeof e == "function" ) e ( ) ; }
componentWillEnter ( e ) { if ( typeof e == "function" ) e ( ) ; }
componentWillLeave ( e ) { if ( typeof e == "function" ) this . timeoutId = setTimeout ( e , 300 ) ; }
2021-01-25 15:34:43 +01:00
componentWillUnmount ( ) { BDFDB . TimeUtils . clear ( this . timeoutId ) }
2020-09-19 21:32:19 +02:00
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . div , {
className : this . props . className ,
style : this . props . animatedStyle ,
children : this . props . children
} ) ;
}
} ;
InternalComponents . LibraryComponents . Badges = Object . assign ( { } , BDFDB . ModuleUtils . findByProperties ( "IconBadge" , "NumberBadge" ) ) ;
InternalComponents . LibraryComponents . Badges . IconBadge = reactInitialized && class BDFDB _IconBadge extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . badgeiconbadge , this . props . className ) ,
style : Object . assign ( {
backgroundColor : this . props . disableColor ? null : ( this . props . color || BDFDB . DiscordConstants . Colors . STATUS _RED )
} , this . props . style ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . badgeicon ,
name : this . props . icon
} )
} ) ;
}
} ;
InternalComponents . LibraryComponents . BotTag = reactInitialized && class BDFDB _BotTag extends LibraryModules . React . Component {
handleClick ( e ) { if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ; }
handleContextMenu ( e ) { if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ; }
handleMouseEnter ( e ) { if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ; }
handleMouseLeave ( e ) { if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ; }
render ( ) {
return BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , this . props . invertColor ? BDFDB . disCN . bottaginvert : BDFDB . disCN . bottagregular , this . props . useRemSizes ? BDFDB . disCN . bottagrem : BDFDB . disCN . bottagpx ) ,
style : this . props . style ,
onClick : this . handleClick . bind ( this ) ,
onContextMenu : this . handleContextMenu . bind ( this ) ,
onMouseEnter : this . handleMouseEnter . bind ( this ) ,
onMouseLeave : this . handleMouseLeave . bind ( this ) ,
children : BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . bottagtext ,
children : this . props . tag || BDFDB . LanguageUtils . LanguageStrings . BOT _TAG _BOT
} )
} ) ;
}
} ;
InternalComponents . LibraryComponents . Button = reactInitialized && class BDFDB _Button extends LibraryModules . React . Component {
handleClick ( e ) { if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ; }
handleContextMenu ( e ) { if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ; }
handleMouseDown ( e ) { if ( typeof this . props . onMouseDown == "function" ) this . props . onMouseDown ( e , this ) ; }
handleMouseUp ( e ) { if ( typeof this . props . onMouseUp == "function" ) this . props . onMouseUp ( e , this ) ; }
handleMouseEnter ( e ) { if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ; }
handleMouseLeave ( e ) { if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ; }
render ( ) {
let processingAndListening = ( this . props . disabled || this . props . submitting ) && ( null != this . props . onMouseEnter || null != this . props . onMouseLeave ) ;
let props = BDFDB . ObjectUtils . exclude ( this . props , "look" , "color" , "hover" , "size" , "fullWidth" , "grow" , "disabled" , "submitting" , "type" , "style" , "wrapperClassName" , "className" , "innerClassName" , "onClick" , "onContextMenu" , "onMouseDown" , "onMouseUp" , "onMouseEnter" , "onMouseLeave" , "children" , "rel" ) ;
let button = BDFDB . ReactUtils . createElement ( "button" , Object . assign ( { } , ! this . props . disabled && ! this . props . submitting && props , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . button , this . props . look != null ? this . props . look : InternalComponents . LibraryComponents . Button . Looks . FILLED , this . props . color != null ? this . props . color : InternalComponents . LibraryComponents . Button . Colors . BRAND , this . props . hover , this . props . size != null ? this . props . size : InternalComponents . LibraryComponents . Button . Sizes . MEDIUM , processingAndListening && this . props . wrapperClassName , this . props . fullWidth && BDFDB . disCN . buttonfullwidth , ( this . props . grow === undefined || this . props . grow ) && BDFDB . disCN . buttongrow , this . props . hover && this . props . hover !== InternalComponents . LibraryComponents . Button . Hovers . DEFAULT && BDFDB . disCN . buttonhashover , this . props . submitting && BDFDB . disCN . buttonsubmitting ) ,
onClick : ( this . props . disabled || this . props . submitting ) ? e => { return e . preventDefault ( ) ; } : this . handleClick . bind ( this ) ,
onContextMenu : ( this . props . disabled || this . props . submitting ) ? e => { return e . preventDefault ( ) ; } : this . handleContextMenu . bind ( this ) ,
onMouseUp : ! this . props . disabled && this . handleMouseDown . bind ( this ) ,
onMouseDown : ! this . props . disabled && this . handleMouseUp . bind ( this ) ,
onMouseEnter : this . handleMouseEnter . bind ( this ) ,
onMouseLeave : this . handleMouseLeave . bind ( this ) ,
type : ! this . props . type ? "button" : this . props . type ,
disabled : this . props . disabled ,
style : this . props . style ,
rel : this . props . rel ,
children : [
this . props . submitting && ! this . props . disabled ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Spinner , {
type : InternalComponents . LibraryComponents . Spinner . Type . PULSING _ELLIPSIS ,
className : BDFDB . disCN . buttonspinner ,
itemClassName : BDFDB . disCN . buttonspinneritem
} ) : null ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . buttoncontents , this . props . innerClassName ) ,
children : this . props . children
} )
]
} ) ) ;
return ! processingAndListening ? button : BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . buttondisabledwrapper , this . props . wrapperClassName , this . props . size != null ? this . props . size : InternalComponents . LibraryComponents . Button . Sizes . MEDIUM , this . props . fullWidth && BDFDB . disCN . buttonfullwidth , ( this . props . grow === undefined || this . props . grow ) && BDFDB . disCN . buttongrow ) ,
children : [
button ,
BDFDB . ReactUtils . createElement ( "span" , {
onMouseEnter : this . handleMouseEnter . bind ( this ) ,
onMouseLeave : this . handleMouseLeave . bind ( this ) ,
className : BDFDB . disCN . buttondisabledoverlay
} )
]
} ) ;
}
} ;
InternalComponents . LibraryComponents . Card = reactInitialized && class BDFDB _Card extends LibraryModules . React . Component {
render ( ) {
2020-11-23 21:28:01 +01:00
return BDFDB . ReactUtils . createElement ( "div" , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
2020-11-24 10:53:53 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . hovercardwrapper , this . props . horizontal && BDFDB . disCN . hovercardhorizontal , this . props . backdrop && BDFDB . disCN . hovercard , this . props . className ) ,
2020-09-19 21:32:19 +02:00
onMouseEnter : e => { if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ; } ,
onMouseLeave : e => { if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ; } ,
onClick : e => { if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ; } ,
onContextMenu : e => { if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ; } ,
children : [
! this . props . noRemove ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . CardRemoveButton , {
onClick : e => {
if ( typeof this . props . onRemove == "function" ) this . props . onRemove ( e , this ) ;
BDFDB . ListenerUtils . stopEvent ( e ) ;
}
} ) : null ,
typeof this . props . children == "string" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextElement , {
className : BDFDB . disCN . hovercardinner ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextScroller , { children : this . props . children } )
} ) : this . props . children
] . flat ( 10 ) . filter ( n => n )
2020-11-24 10:53:53 +01:00
} ) , "backdrop" , "horizontal" , "noRemove" ) ) ;
2020-09-19 21:32:19 +02:00
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . Card , { backdrop : true , noRemove : false } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . ChannelTextAreaButton = reactInitialized && class BDFDB _ChannelTextAreaButton extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Button , {
look : InternalComponents . LibraryComponents . Button . Looks . BLANK ,
size : InternalComponents . LibraryComponents . Button . Sizes . NONE ,
"aria-label" : this . props . label ,
tabIndex : this . props . tabIndex ,
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . textareabuttonwrapper , this . props . isActive && BDFDB . disCN . textareabuttonactive ) ,
innerClassName : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . textareabutton , this . props . className , this . props . pulse && BDFDB . disCN . textareaattachbuttonplus ) ,
onClick : this . props . onClick ,
onContextMenu : this . props . onContextMenu ,
onMouseEnter : this . props . onMouseEnter ,
onMouseLeave : this . props . onMouseLeave ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : this . props . iconName ,
iconSVG : this . props . iconSVG ,
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . textareaicon , this . props . iconClassName , this . props . pulse && BDFDB . disCN . textareaiconpulse ) ,
nativeClass : this . props . nativeClass
} )
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . ChannelTextAreaButton , { tabIndex : 0 } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . CharCounter = reactInitialized && class BDFDB _CharCounter extends LibraryModules . React . Component {
getCounterString ( ) {
let input = this . refElement || { } , string = "" ;
if ( BDFDB . DOMUtils . containsClass ( this . refElement , BDFDB . disCN . textarea ) ) {
2020-11-19 16:51:14 +01:00
let instance = BDFDB . ReactUtils . findOwner ( input , { name : "ChannelEditorContainer" , up : true } ) ;
2020-09-19 21:32:19 +02:00
if ( instance ) string = instance . props . textValue ;
else string = input . value || input . textContent || "" ;
}
else string = input . value || input . textContent || "" ;
let start = input . selectionStart || 0 , end = input . selectionEnd || 0 , selectlength = end - start , selection = BDFDB . DOMUtils . getSelection ( ) ;
let select = ! selectlength && ! selection ? 0 : ( selectlength || selection . length ) ;
select = ! select ? 0 : ( select > string . length ? ( end || start ? string . length - ( string . length - end - start ) : string . length ) : select ) ;
let children = [
typeof this . props . renderPrefix == "function" && this . props . renderPrefix ( string . length ) ,
` ${ string . length } ${ ! this . props . max ? "" : "/" + this . props . max } ${ ! select ? "" : " (" + select + ")" } ` ,
typeof this . props . renderSuffix == "function" && this . props . renderSuffix ( string . length )
] . filter ( n => n ) ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( this ) ;
return children . length == 1 ? children [ 0 ] : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
children : children
} ) ;
}
updateCounter ( ) {
if ( ! this . refElement ) return ;
BDFDB . TimeUtils . clear ( this . updateTimeout ) ;
this . updateTimeout = BDFDB . TimeUtils . timeout ( this . forceUpdateCounter . bind ( this ) , 100 ) ;
}
forceUpdateCounter ( ) {
if ( ! this . refElement ) return ;
this . props . children = this . getCounterString ( ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
handleSelection ( ) {
if ( ! this . refElement ) return ;
2020-11-17 17:24:56 +01:00
let mouseMove = _ => {
2020-09-19 21:32:19 +02:00
BDFDB . TimeUtils . timeout ( this . forceUpdateCounter . bind ( this ) , 10 ) ;
} ;
2020-11-17 17:24:56 +01:00
let mouseUp = _ => {
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
if ( this . refElement . selectionEnd - this . refElement . selectionStart ) BDFDB . TimeUtils . timeout ( _ => {
document . addEventListener ( "click" , click ) ;
} ) ;
} ;
let click = _ => {
BDFDB . TimeUtils . timeout ( this . forceUpdateCounter . bind ( this ) , 100 ) ;
2020-11-17 17:24:56 +01:00
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
document . removeEventListener ( "click" , click ) ;
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mousemove" , mouseMove ) ;
document . addEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
}
componentDidMount ( ) {
if ( this . props . refClass ) {
let node = BDFDB . ReactUtils . findDOMNode ( this ) ;
if ( node && node . parentElement ) {
this . refElement = node . parentElement . querySelector ( this . props . refClass ) ;
if ( this . refElement ) {
if ( ! this . _updateCounter ) this . _updateCounter = _ => {
if ( ! document . contains ( node ) ) BDFDB . ListenerUtils . multiRemove ( this . refElement , "keydown click change" , this . _updateCounter ) ;
else this . updateCounter ( ) ;
} ;
if ( ! this . _handleSelection ) this . _handleSelection = _ => {
if ( ! document . contains ( node ) ) BDFDB . ListenerUtils . multiRemove ( this . refElement , "mousedown" , this . _handleSelection ) ;
else this . handleSelection ( ) ;
} ;
BDFDB . ListenerUtils . multiRemove ( this . refElement , "mousedown" , this . _handleSelection ) ;
BDFDB . ListenerUtils . multiAdd ( this . refElement , "mousedown" , this . _handleSelection ) ;
if ( this . refElement . tagName == "INPUT" || this . refElement . tagName == "TEXTAREA" ) {
BDFDB . ListenerUtils . multiRemove ( this . refElement , "keydown click change" , this . _updateCounter ) ;
BDFDB . ListenerUtils . multiAdd ( this . refElement , "keydown click change" , this . _updateCounter ) ;
}
else {
if ( ! this . _mutationObserver ) this . _mutationObserver = new MutationObserver ( changes => {
if ( ! document . contains ( node ) ) this . _mutationObserver . disconnect ( ) ;
else this . updateCounter ( ) ;
} ) ;
else this . _mutationObserver . disconnect ( ) ;
this . _mutationObserver . observe ( this . refElement , { childList : true , subtree : true } ) ;
}
this . updateCounter ( ) ;
}
else BDFDB . LogUtils . warn ( "could not find referenceElement for BDFDB_CharCounter" ) ;
}
}
else BDFDB . LogUtils . warn ( "refClass can not be undefined for BDFDB_CharCounter" ) ;
}
render ( ) {
let string = this . getCounterString ( ) ;
BDFDB . TimeUtils . timeout ( _ => { if ( string != this . getCounterString ( ) ) BDFDB . ReactUtils . forceUpdate ( this ) ; } ) ;
return BDFDB . ReactUtils . createElement ( "div" , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . charcounter , this . props . className ) ,
children : string
} ) , "parsing" , "max" , "refClass" , "renderPrefix" , "renderSuffix" ) ) ;
}
} ;
InternalComponents . LibraryComponents . Checkbox = reactInitialized && class BDFDB _Checkbox extends LibraryModules . React . Component {
2021-01-02 12:51:18 +01:00
handleClick ( e ) { if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ; }
handleContextMenu ( e ) { if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ; }
handleMouseDown ( e ) { if ( typeof this . props . onMouseDown == "function" ) this . props . onMouseDown ( e , this ) ; }
handleMouseUp ( e ) { if ( typeof this . props . onMouseUp == "function" ) this . props . onMouseUp ( e , this ) ; }
handleMouseEnter ( e ) { if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ; }
handleMouseLeave ( e ) { if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ; }
getInputMode ( ) {
return this . props . disabled ? "disabled" : this . props . readOnly ? "readonly" : "default" ;
}
getStyle ( ) {
let style = this . props . style || { } ;
if ( ! this . props . value ) return style ;
style = Object . assign ( { } , style ) ;
this . props . color = typeof this . props . getColor == "function" ? this . props . getColor ( this . props . value ) : this . props . color ;
switch ( this . props . type ) {
case InternalComponents . NativeSubComponents . Checkbox . Types . DEFAULT :
style . borderColor = this . props . color ;
break ;
case InternalComponents . NativeSubComponents . Checkbox . Types . GHOST :
let color = BDFDB . ColorUtils . setAlpha ( this . props . color , 0.15 , "RGB" ) ;
style . borderColor = color ;
style . backgroundColor = color ;
break ;
case InternalComponents . NativeSubComponents . Checkbox . Types . INVERTED :
style . backgroundColor = this . props . color ;
style . borderColor = this . props . color ;
}
return style ;
}
getColor ( ) {
return this . props . value ? ( this . props . type === InternalComponents . NativeSubComponents . Checkbox . Types . INVERTED ? BDFDB . DiscordConstants . Colors . WHITE : this . props . color ) : "transparent" ;
}
handleChange ( e ) {
this . props . value = typeof this . props . getValue == "function" ? this . props . getValue ( this . props . value , e ) : ! this . props . value ;
2020-09-19 21:32:19 +02:00
if ( typeof this . props . onChange == "function" ) this . props . onChange ( this . props . value , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
2021-01-02 12:51:18 +01:00
let label = this . props . children ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . checkboxlabel , this . props . disabled ? BDFDB . disCN . checkboxlabeldisabled : BDFDB . disCN . checkboxlabelclickable , this . props . reverse ? BDFDB . disCN . checkboxlabelreversed : BDFDB . disCN . checkboxlabelforward ) ,
style : {
lineHeight : this . props . size + "px"
} ,
children : this . props . children
} ) : null ;
return BDFDB . ReactUtils . createElement ( "label" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . disabled ? BDFDB . disCN . checkboxwrapperdisabled : BDFDB . disCN . checkboxwrapper , this . props . align , this . props . className ) ,
children : [
this . props . reverse && label ,
! this . props . displayOnly && BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FocusRingScope , {
children : BDFDB . ReactUtils . createElement ( "input" , {
className : BDFDB . disCN [ "checkboxinput" + this . getInputMode ( ) ] ,
type : "checkbox" ,
onClick : this . props . disabled || this . props . readOnly ? ( _ => { } ) : this . handleChange . bind ( this ) ,
onContextMenu : this . props . disabled || this . props . readOnly ? ( _ => { } ) : this . handleChange . bind ( this ) ,
checked : this . props . value ,
style : {
width : this . props . size ,
height : this . props . size
}
} )
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . checkbox , this . props . shape , this . props . value && BDFDB . disCN . checkboxchecked ) ,
style : Object . assign ( {
width : this . props . size ,
height : this . props . size ,
borderColor : this . props . checkboxColor
} , this . getStyle ( ) ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Checkmark , {
width : 18 ,
height : 18 ,
color : this . getColor ( ) ,
"aria-hidden" : true
} )
} ) ,
! this . props . reverse && label
] . filter ( n => n )
} ) ;
2020-09-19 21:32:19 +02:00
}
} ;
InternalComponents . LibraryComponents . Clickable = reactInitialized && class BDFDB _Clickable extends LibraryModules . React . Component {
handleClick ( e ) { if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ; }
handleContextMenu ( e ) { if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ; }
handleMouseDown ( e ) { if ( typeof this . props . onMouseDown == "function" ) this . props . onMouseDown ( e , this ) ; }
handleMouseUp ( e ) { if ( typeof this . props . onMouseUp == "function" ) this . props . onMouseUp ( e , this ) ; }
handleMouseEnter ( e ) { if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ; }
handleMouseLeave ( e ) { if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ; }
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . Clickable , Object . assign ( { } , this . props , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , ( this . props . className || "" ) . toLowerCase ( ) . indexOf ( "disabled" ) == - 1 && BDFDB . disCN . cursorpointer ) ,
onClick : this . handleClick . bind ( this ) ,
onContextMenu : this . handleContextMenu . bind ( this ) ,
onMouseUp : this . handleMouseDown . bind ( this ) ,
onMouseDown : ! this . props . disabled && this . handleMouseUp . bind ( this ) ,
onMouseEnter : this . handleMouseEnter . bind ( this ) ,
onMouseLeave : this . handleMouseLeave . bind ( this )
} ) ) ;
}
} ;
InternalComponents . LibraryComponents . CollapseContainer = reactInitialized && class BDFDB _CollapseContainer extends LibraryModules . React . Component {
render ( ) {
if ( ! BDFDB . ObjectUtils . is ( this . props . collapseStates ) ) this . props . collapseStates = { } ;
2021-01-10 11:41:01 +01:00
this . props . collapsed = this . props . collapsed && ( this . props . collapseStates [ this . props . title ] || this . props . collapseStates [ this . props . title ] === undefined ) ;
2020-09-19 21:32:19 +02:00
this . props . collapseStates [ this . props . title ] = this . props . collapsed ;
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . collapsed && BDFDB . disCN . collapsecontainercollapsed , this . props . mini ? BDFDB . disCN . collapsecontainermini : BDFDB . disCN . collapsecontainer , this . props . className ) ,
id : this . props . id ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . disCN . collapsecontainerheader ,
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
onClick : e => {
this . props . collapsed = ! this . props . collapsed ;
this . props . collapseStates [ this . props . title ] = this . props . collapsed ;
if ( typeof this . props . onClick == "function" ) this . props . onClick ( this . props . collapsed , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
} ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormTitle , {
tag : InternalComponents . LibraryComponents . FormComponents . FormTitle . Tags . H5 ,
className : BDFDB . disCN . collapsecontainertitle ,
children : this . props . title
} )
} ) ,
! this . props . collapsed ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . collapsecontainerinner ,
children : this . props . children
} ) : null
]
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . CollapseContainer , { collapsed : true , mini : true } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . ColorPicker = reactInitialized && class BDFDB _ColorPicker extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
if ( ! this . state ) this . state = { } ;
this . state . isGradient = props . gradient && props . color && BDFDB . ObjectUtils . is ( props . color ) ;
this . state . gradientBarEnabled = this . state . isGradient ;
this . state . draggingAlphaCursor = false ;
this . state . draggingGradientCursor = false ;
this . state . selectedGradientCursor = 0 ;
}
handleColorChange ( color ) {
let changed = false ;
if ( color != null ) {
changed = ! BDFDB . equals ( this . state . isGradient ? this . props . color [ this . state . selectedGradientCursor ] : this . props . color , color ) ;
if ( this . state . isGradient ) this . props . color [ this . state . selectedGradientCursor ] = color ;
else this . props . color = color ;
}
else changed = true ;
if ( changed ) {
if ( typeof this . props . onColorChange == "function" ) this . props . onColorChange ( this . props . color ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
}
componentDidMount ( ) {
this . domElementRef = { current : BDFDB . DOMUtils . getParent ( BDFDB . dotCN . itemlayer , BDFDB . ReactUtils . findDOMNode ( this ) ) } ;
2021-01-30 12:36:34 +01:00
let popoutContainerInstance = BDFDB . ReactUtils . findOwner ( this . domElementRef . current , { name : "BDFDB_PopoutContainer" , unlimited : true , up : true } ) ;
2020-09-19 21:32:19 +02:00
if ( popoutContainerInstance ) {
let mousedown = event => {
if ( ! this . domElementRef . current || ! document . contains ( this . domElementRef . current ) ) document . removeEventListener ( "mousedown" , mousedown ) ;
else if ( ! this . domElementRef . current . contains ( event . target ) ) {
2020-11-17 17:24:56 +01:00
let mouseUp = event => {
2020-09-19 21:32:19 +02:00
if ( ! this . domElementRef . current || ! document . contains ( this . domElementRef . current ) ) {
document . removeEventListener ( "mousedown" , mousedown ) ;
2020-11-17 17:24:56 +01:00
document . removeEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
}
else if ( ! this . domElementRef . current . contains ( event . target ) ) {
document . removeEventListener ( "mousedown" , mousedown ) ;
2020-11-17 17:24:56 +01:00
document . removeEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
popoutContainerInstance . handleClick ( event ) ;
}
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
}
} ;
document . addEventListener ( "mousedown" , mousedown ) ;
}
}
render ( ) {
if ( this . state . isGradient ) this . props . color = Object . assign ( { } , this . props . color ) ;
let hslFormat = this . props . alpha ? "HSLA" : "HSL" ;
let hexRegex = this . props . alpha ? /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i : /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i ;
let selectedColor = BDFDB . ColorUtils . convert ( this . state . isGradient ? this . props . color [ this . state . selectedGradientCursor ] : this . props . color , hslFormat ) || BDFDB . ColorUtils . convert ( "#000000FF" , hslFormat ) ;
let currentGradient = ( this . state . isGradient ? Object . entries ( this . props . color , hslFormat ) : [ [ 0 , selectedColor ] , [ 1 , selectedColor ] ] ) ;
let [ h , s , l ] = BDFDB . ColorUtils . convert ( selectedColor , "HSLCOMP" ) ;
let a = BDFDB . ColorUtils . getAlpha ( selectedColor ) ;
a = a == null ? 1 : a ;
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PopoutFocusLock , {
className : BDFDB . disCNS . colorpickerwrapper + BDFDB . disCN . colorpicker ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickerinner ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickersaturation ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickersaturationcolor ,
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 , cursor : "crosshair" , backgroundColor : BDFDB . ColorUtils . convert ( [ h , "100%" , "100%" ] , "RGB" ) } ,
onClick : event => {
let rects = BDFDB . DOMUtils . getRects ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickersaturationcolor , event . target ) ) ;
let newS = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0 , 100 ] , event . clientX ) + "%" ;
let newL = BDFDB . NumberUtils . mapRange ( [ rects . top , rects . top + rects . height ] , [ 100 , 0 ] , event . clientY ) + "%" ;
this . handleColorChange ( BDFDB . ColorUtils . convert ( [ h , newS , newL , a ] , hslFormat ) ) ;
} ,
onMouseDown : event => {
let rects = BDFDB . DOMUtils . getRects ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickersaturationcolor , event . target ) ) ;
2020-11-17 17:24:56 +01:00
let mouseUp = _ => {
document . removeEventListener ( "mouseup" , mouseUp ) ;
document . removeEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ;
2020-11-17 17:24:56 +01:00
let mouseMove = event2 => {
2020-09-19 21:32:19 +02:00
let newS = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0 , 100 ] , event2 . clientX ) + "%" ;
let newL = BDFDB . NumberUtils . mapRange ( [ rects . top , rects . top + rects . height ] , [ 100 , 0 ] , event2 . clientY ) + "%" ;
this . handleColorChange ( BDFDB . ColorUtils . convert ( [ h , newS , newL , a ] , hslFormat ) ) ;
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mouseup" , mouseUp ) ;
document . addEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ,
children : [
BDFDB . ReactUtils . createElement ( "style" , {
children : ` ${ BDFDB . dotCN . colorpickersaturationwhite } {background: -webkit-linear-gradient(to right, #fff, rgba(255,255,255,0));background: linear-gradient(to right, #fff, rgba(255,255,255,0));} ${ BDFDB . dotCN . colorpickersaturationblack } {background: -webkit-linear-gradient(to top, #000, rgba(0,0,0,0));background: linear-gradient(to top, #000, rgba(0,0,0,0));} `
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickersaturationwhite ,
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 } ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickersaturationblack ,
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 }
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickersaturationcursor ,
style : { position : "absolute" , cursor : "crosshair" , left : s , top : ` ${ BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , [ 100 , 0 ] , parseFloat ( l ) ) } % ` } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
style : { width : 4 , height : 4 , boxShadow : "rgb(255, 255, 255) 0px 0px 0px 1.5px, rgba(0, 0, 0, 0.3) 0px 0px 1px 1px inset, rgba(0, 0, 0, 0.4) 0px 0px 1px 2px" , borderRadius : "50%" , transform : "translate(-2px, -2px)" }
} )
} )
]
} )
]
} )
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickerhue ,
children : BDFDB . ReactUtils . createElement ( "div" , {
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickerhuehorizontal ,
style : { padding : "0px 2px" , position : "relative" , height : "100%" } ,
onClick : event => {
let rects = BDFDB . DOMUtils . getRects ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickerhuehorizontal , event . target ) ) ;
let newH = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0 , 360 ] , event . clientX ) ;
this . handleColorChange ( BDFDB . ColorUtils . convert ( [ newH , s , l , a ] , hslFormat ) ) ;
} ,
onMouseDown : event => {
let rects = BDFDB . DOMUtils . getRects ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickerhuehorizontal , event . target ) ) ;
2020-11-17 17:24:56 +01:00
let mouseUp = _ => {
document . removeEventListener ( "mouseup" , mouseUp ) ;
document . removeEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ;
2020-11-17 17:24:56 +01:00
let mouseMove = event2 => {
2020-09-19 21:32:19 +02:00
let newH = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0 , 360 ] , event2 . clientX ) ;
this . handleColorChange ( BDFDB . ColorUtils . convert ( [ newH , s , l , a ] , hslFormat ) ) ;
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mouseup" , mouseUp ) ;
document . addEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ,
children : [
BDFDB . ReactUtils . createElement ( "style" , {
children : ` ${ BDFDB . dotCN . colorpickerhuehorizontal } {background: linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);background: -webkit-linear-gradient(to right, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);} ${ BDFDB . dotCN . colorpickerhuevertical } {background: linear-gradient(to top, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);background: -webkit-linear-gradient(to top, #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);} `
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickerhuecursor ,
style : { position : "absolute" , cursor : "ew-resize" , left : ` ${ BDFDB . NumberUtils . mapRange ( [ 0 , 360 ] , [ 0 , 100 ] , h ) } % ` } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
style : { marginTop : 1 , width : 4 , borderRadius : 1 , height : 8 , boxShadow : "rgba(0, 0, 0, 0.6) 0px 0px 2px" , background : "rgb(255, 255, 255)" , transform : "translateX(-2px)" }
} )
} )
]
} )
} )
} ) ,
this . props . alpha && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickeralpha ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickeralphacheckered ,
style : { padding : "0px 2px" , position : "relative" , height : "100%" }
} )
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickeralphahorizontal ,
style : { padding : "0px 2px" , position : "relative" , height : "100%" , background : ` linear-gradient(to right, ${ BDFDB . ColorUtils . setAlpha ( [ h , s , l ] , 0 , "RGBA" ) } , ${ BDFDB . ColorUtils . setAlpha ( [ h , s , l ] , 1 , "RGBA" ) } ` } ,
onClick : event => {
let rects = BDFDB . DOMUtils . getRects ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickeralphahorizontal , event . target ) ) ;
let newA = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0 , 1 ] , event . clientX ) ;
2021-02-24 17:00:10 +01:00
this . handleColorChange ( BDFDB . ColorUtils . setAlpha ( [ h , s , l ] , newA , hslFormat ) ) ;
2020-09-19 21:32:19 +02:00
} ,
onMouseDown : event => {
let rects = BDFDB . DOMUtils . getRects ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickeralphahorizontal , event . target ) ) ;
2020-11-17 17:24:56 +01:00
let mouseUp = _ => {
document . removeEventListener ( "mouseup" , mouseUp ) ;
document . removeEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
this . state . draggingAlphaCursor = false ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
} ;
2020-11-17 17:24:56 +01:00
let mouseMove = event2 => {
2020-09-19 21:32:19 +02:00
this . state . draggingAlphaCursor = true ;
let newA = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0 , 1 ] , event2 . clientX ) ;
2021-02-24 17:00:10 +01:00
this . handleColorChange ( BDFDB . ColorUtils . setAlpha ( [ h , s , l ] , newA , hslFormat ) ) ;
2020-09-19 21:32:19 +02:00
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mouseup" , mouseUp ) ;
document . addEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickeralphacursor ,
style : { position : "absolute" , cursor : "ew-resize" , left : ` ${ a * 100 } % ` } ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
style : { marginTop : 1 , width : 4 , borderRadius : 1 , height : 8 , boxShadow : "rgba(0, 0, 0, 0.6) 0px 0px 2px" , background : "rgb(255, 255, 255)" , transform : "translateX(-2px)" }
} ) ,
this . state . draggingAlphaCursor && BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . sliderbubble ,
style : { opacity : 1 , visibility : "visible" , left : 2 } ,
children : ` ${ Math . floor ( a * 100 ) } % `
} )
] . filter ( n => n )
} )
} )
} )
]
} ) ,
this . state . gradientBarEnabled && BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickergradient ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickergradientcheckered ,
style : { padding : "0px 2px" , position : "relative" , height : "100%" }
} )
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
style : { position : "absolute" , top : 0 , right : 0 , bottom : 0 , left : 0 } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickergradienthorizontal ,
style : { padding : "0px 2px" , position : "relative" , cursor : "copy" , height : "100%" , background : BDFDB . ColorUtils . createGradient ( currentGradient . reduce ( ( colorObj , posAndColor ) => ( colorObj [ posAndColor [ 0 ] ] = posAndColor [ 1 ] , colorObj ) , { } ) ) } ,
onClick : event => {
let rects = BDFDB . DOMUtils . getRects ( event . target ) ;
let pos = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0.01 , 0.99 ] , event . clientX ) ;
if ( Object . keys ( this . props . color ) . indexOf ( pos ) == - 1 ) {
this . props . color [ pos ] = BDFDB . ColorUtils . convert ( "#000000FF" , hslFormat ) ;
this . state . selectedGradientCursor = pos ;
this . handleColorChange ( ) ;
}
} ,
children : currentGradient . map ( posAndColor => BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . colorpickergradientcursor , ( posAndColor [ 0 ] == 0 || posAndColor [ 0 ] == 1 ) && BDFDB . disCNS . colorpickergradientcursoredge , this . state . selectedGradientCursor == posAndColor [ 0 ] && BDFDB . disCN . colorpickergradientcursorselected ) ,
style : { position : "absolute" , cursor : "pointer" , left : ` ${ posAndColor [ 0 ] * 100 } % ` } ,
onMouseDown : posAndColor [ 0 ] == 0 || posAndColor [ 0 ] == 1 ? _ => { } : event => {
event = event . nativeEvent || event ;
2020-11-17 17:24:56 +01:00
let mouseMove = event2 => {
2020-09-19 21:32:19 +02:00
if ( Math . sqrt ( ( event . pageX - event2 . pageX ) * * 2 ) > 10 ) {
2020-11-17 17:24:56 +01:00
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
this . state . draggingGradientCursor = true ;
let cursor = BDFDB . DOMUtils . getParent ( BDFDB . dotCN . colorpickergradientcursor , event . target ) ;
let rects = BDFDB . DOMUtils . getRects ( cursor . parentElement ) ;
let releasing = _ => {
document . removeEventListener ( "mousemove" , dragging ) ;
document . removeEventListener ( "mouseup" , releasing ) ;
BDFDB . TimeUtils . timeout ( _ => { this . state . draggingGradientCursor = false ; } ) ;
} ;
let dragging = event3 => {
let pos = BDFDB . NumberUtils . mapRange ( [ rects . left , rects . left + rects . width ] , [ 0.01 , 0.99 ] , event3 . clientX ) ;
if ( Object . keys ( this . props . color ) . indexOf ( pos ) == - 1 ) {
delete this . props . color [ posAndColor [ 0 ] ] ;
posAndColor [ 0 ] = pos ;
this . props . color [ pos ] = posAndColor [ 1 ] ;
this . state . selectedGradientCursor = pos ;
this . handleColorChange ( ) ;
}
} ;
document . addEventListener ( "mousemove" , dragging ) ;
document . addEventListener ( "mouseup" , releasing ) ;
}
} ;
2020-11-17 17:24:56 +01:00
let mouseUp = _ => {
document . removeEventListener ( "mousemove" , mouseMove ) ;
document . removeEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mousemove" , mouseMove ) ;
document . addEventListener ( "mouseup" , mouseUp ) ;
2020-09-19 21:32:19 +02:00
} ,
onClick : event => {
BDFDB . ListenerUtils . stopEvent ( event ) ;
if ( ! this . state . draggingGradientCursor ) {
this . state . selectedGradientCursor = posAndColor [ 0 ] ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
} ,
onContextMenu : posAndColor [ 0 ] == 0 || posAndColor [ 0 ] == 1 ? _ => { } : event => {
BDFDB . ListenerUtils . stopEvent ( event ) ;
delete this . props . color [ posAndColor [ 0 ] ] ;
this . state . selectedGradientCursor = 0 ;
this . handleColorChange ( ) ;
} ,
children : BDFDB . ReactUtils . createElement ( "div" , {
style : { background : BDFDB . ColorUtils . convert ( posAndColor [ 1 ] , "RGBA" ) }
} )
} ) )
} )
} )
]
} )
] . filter ( n => n )
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextInput , {
className : BDFDB . disCNS . colorpickerhexinput + BDFDB . disCN . margintop8 ,
maxLength : this . props . alpha ? 9 : 7 ,
valuePrefix : "#" ,
value : BDFDB . ColorUtils . convert ( selectedColor , this . props . alpha ? "HEXA" : "HEX" ) ,
autoFocus : true ,
onChange : value => {
if ( hexRegex . test ( value ) ) this . handleColorChange ( value ) ;
} ,
inputChildren : this . props . gradient && BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
2020-12-24 11:46:03 +01:00
text : BDFDB . LanguageUtils . LibraryStrings . gradient ,
2020-09-19 21:32:19 +02:00
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . colorpickergradientbutton , this . state . gradientBarEnabled && BDFDB . disCN . colorpickergradientbuttonenabled ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
nativeClass : true ,
width : 28 ,
height : 28 ,
name : InternalComponents . LibraryComponents . SvgIcon . Names . GRADIENT
} ) ,
onClick : _ => {
this . state . gradientBarEnabled = ! this . state . gradientBarEnabled ;
if ( this . state . gradientBarEnabled && ! this . state . isGradient ) this . props . color = { 0 : selectedColor , 1 : selectedColor } ;
else if ( ! this . state . gradientBarEnabled && this . state . isGradient ) this . props . color = selectedColor ;
this . state . isGradient = this . props . color && BDFDB . ObjectUtils . is ( this . props . color ) ;
this . handleColorChange ( ) ;
}
} )
} )
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : "move-corners" ,
children : [ { top : 0 , left : 0 } , { top : 0 , right : 0 } , { bottom : 0 , right : 0 } , { bottom : 0 , left : 0 } ] . map ( pos => BDFDB . ReactUtils . createElement ( "div" , {
className : "move-corner" ,
onMouseDown : e => {
if ( ! this . domElementRef . current ) return ;
let rects = BDFDB . DOMUtils . getRects ( this . domElementRef . current ) ;
let left = rects . left , top = rects . top ;
let oldX = e . pageX , oldY = e . pageY ;
2020-11-17 17:24:56 +01:00
let mouseUp = _ => {
document . removeEventListener ( "mouseup" , mouseUp ) ;
document . removeEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ;
2020-11-17 17:24:56 +01:00
let mouseMove = e2 => {
2020-09-19 21:32:19 +02:00
left = left - ( oldX - e2 . pageX ) , top = top - ( oldY - e2 . pageY ) ;
oldX = e2 . pageX , oldY = e2 . pageY ;
this . domElementRef . current . style . setProperty ( "left" , ` ${ left } px ` , "important" ) ;
this . domElementRef . current . style . setProperty ( "top" , ` ${ top } px ` , "important" ) ;
} ;
2020-11-17 17:24:56 +01:00
document . addEventListener ( "mouseup" , mouseUp ) ;
document . addEventListener ( "mousemove" , mouseMove ) ;
2020-09-19 21:32:19 +02:00
} ,
style : Object . assign ( { } , pos , { width : 10 , height : 10 , cursor : "move" , position : "absolute" } )
} ) )
} )
]
} ) ;
}
} ;
InternalComponents . LibraryComponents . ColorSwatches = reactInitialized && class BDFDB _ColorSwatches extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
props . selectedColor = BDFDB . ObjectUtils . is ( props . color ) ? props . color : BDFDB . ColorUtils . convert ( props . color , "RGBA" ) ;
props . colors = ( BDFDB . ArrayUtils . is ( props . colors ) ? props . colors : [ null , 5433630 , 3066993 , 1752220 , 3447003 , 3429595 , 8789737 , 10181046 , 15277667 , 15286558 , 15158332 , 15105570 , 15844367 , 13094093 , 7372936 , 6513507 , 16777215 , 3910932 , 2067276 , 1146986 , 2123412 , 2111892 , 7148717 , 7419530 , 11342935 , 11345940 , 10038562 , 11027200 , 12745742 , 9936031 , 6121581 , 2894892 ] ) . map ( c => BDFDB . ColorUtils . convert ( c , "RGBA" ) ) ;
props . colorRows = props . colors . length ? [ props . colors . slice ( 0 , parseInt ( props . colors . length / 2 ) ) , props . colors . slice ( parseInt ( props . colors . length / 2 ) ) ] : [ ] ;
props . customColor = props . selectedColor != null ? ( props . colors . indexOf ( props . selectedColor ) > - 1 ? null : props . selectedColor ) : null ;
props . customSelected = ! ! props . customColor ;
props . pickerConfig = BDFDB . ObjectUtils . is ( props . pickerConfig ) ? props . pickerConfig : { gradient : true , alpha : true } ;
this . state = props ;
var swatches = this ;
this . ColorSwatch = class BDFDB _ColorSwatch extends LibraryModules . React . Component {
render ( ) {
let useWhite = ! BDFDB . ColorUtils . isBright ( this . props . color ) ;
let swatch = BDFDB . ReactUtils . createElement ( "button" , {
type : "button" ,
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . colorpickerswatch , this . props . isSingle && BDFDB . disCN . colorpickerswatchsingle , this . props . isDisabled && BDFDB . disCN . colorpickerswatchdisabled , this . props . isSelected && BDFDB . disCN . colorpickerswatchselected , this . props . isCustom && BDFDB . disCN . colorpickerswatchcustom , this . props . color == null && BDFDB . disCN . colorpickerswatchnocolor ) ,
number : this . props . number ,
disabled : this . props . isDisabled ,
onClick : _ => {
if ( ! this . props . isSelected ) {
2021-01-29 11:25:59 +01:00
let color = this . props . isCustom && this . props . color == null ? ( swatches . state . selectedColor || "rgba(0, 0, 0, 1)" ) : this . props . color ;
2020-09-19 21:32:19 +02:00
if ( typeof swatches . props . onColorChange == "function" ) swatches . props . onColorChange ( BDFDB . ColorUtils . convert ( color , "RGBA" ) ) ;
swatches . setState ( {
selectedColor : color ,
customColor : this . props . isCustom ? color : swatches . state . customColor ,
customSelected : this . props . isCustom
} ) ;
}
} ,
style : Object . assign ( { } , this . props . style , {
background : BDFDB . ObjectUtils . is ( this . props . color ) ? BDFDB . ColorUtils . createGradient ( this . props . color ) : BDFDB . ColorUtils . convert ( this . props . color , "RGBA" )
} ) ,
children : [
this . props . isCustom || this . props . isSingle ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . colorpickerswatchdropper ,
foreground : BDFDB . disCN . colorpickerswatchdropperfg ,
name : InternalComponents . LibraryComponents . SvgIcon . Names . DROPPER ,
width : this . props . isCustom ? 14 : 10 ,
height : this . props . isCustom ? 14 : 10 ,
color : useWhite ? BDFDB . DiscordConstants . Colors . WHITE : BDFDB . DiscordConstants . Colors . BLACK
} ) : null ,
this . props . isSelected && ! this . props . isSingle ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : InternalComponents . LibraryComponents . SvgIcon . Names . CHECKMARK ,
width : this . props . isCustom ? 32 : 16 ,
height : this . props . isCustom ? 24 : 16 ,
color : useWhite ? BDFDB . DiscordConstants . Colors . WHITE : BDFDB . DiscordConstants . Colors . BLACK
} ) : null
]
} ) ;
if ( this . props . isCustom || this . props . isSingle || this . props . color == null ) swatch = BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
text : this . props . isCustom || this . props . isSingle ? BDFDB . LanguageUtils . LanguageStrings . CUSTOM _COLOR : BDFDB . LanguageUtils . LanguageStrings . DEFAULT ,
tooltipConfig : { type : this . props . isSingle ? "top" : "bottom" } ,
children : swatch
} ) ;
if ( this . props . isCustom || this . props . isSingle ) swatch = BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PopoutContainer , {
children : swatch ,
wrap : false ,
popoutClassName : BDFDB . disCNS . colorpickerwrapper + BDFDB . disCN . colorpicker ,
animation : InternalComponents . LibraryComponents . PopoutContainer . Animation . TRANSLATE ,
position : InternalComponents . LibraryComponents . PopoutContainer . Positions . BOTTOM ,
align : InternalComponents . LibraryComponents . PopoutContainer . Align . CENTER ,
renderPopout : _ => {
2021-01-29 11:25:59 +01:00
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ColorPicker , Object . assign ( { } , props . pickerConfig , {
color : swatches . state . selectedColor ,
2020-09-19 21:32:19 +02:00
onColorChange : color => {
2021-01-29 11:25:59 +01:00
let rgba = BDFDB . ColorUtils . convert ( color , "RGBA" ) ;
if ( typeof swatches . props . onColorChange == "function" ) swatches . props . onColorChange ( rgba ) ;
if ( props . pickerConfig && typeof props . pickerConfig . onColorChange == "function" ) props . pickerConfig . onColorChange ( rgba ) ;
2020-09-19 21:32:19 +02:00
this . props . color = color ;
swatches . setState ( {
selectedColor : color ,
customColor : color ,
customSelected : true
} ) ;
}
2021-01-29 11:25:59 +01:00
} ) , true ) ;
2020-09-19 21:32:19 +02:00
}
} ) ;
2021-02-20 14:09:47 +01:00
if ( this . props . isCustom ) swatch = BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickerswatchcustomcontainer ,
children : swatch
} ) ;
2020-09-19 21:32:19 +02:00
return swatch ;
}
}
}
renderRow ( colors ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . disCN . colorpickerrow ,
wrap : InternalComponents . LibraryComponents . Flex . Wrap . WRAP ,
children : colors . map ( color => {
return BDFDB . ReactUtils . createElement ( this . ColorSwatch , {
color : color ,
isCustom : false ,
isSelected : ! this . state . customSelected && color === this . state . selectedColor ,
isDisabled : this . state . disabled
} )
} )
} ) ;
}
render ( ) {
let customSwatch = BDFDB . ReactUtils . createElement ( this . ColorSwatch , {
number : ! this . state . colors . length ? ( this . props . number != null ? this . props . number : 0 ) : null ,
color : this . state . customColor ,
isSingle : ! this . state . colors . length ,
isCustom : this . state . colors . length ,
isSelected : this . state . customSelected ,
isDisabled : this . state . disabled ,
style : { margin : 0 }
} ) ;
return ! this . state . colors . length ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . colorpickerswatchsinglewrapper ,
children : customSwatch
} ) : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
2021-02-20 14:09:47 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . colorpickerswatches , BDFDB . disCN . colorpickerswatchescontainer , this . state . disabled && BDFDB . disCN . colorpickerswatchesdisabled ) ,
2020-09-19 21:32:19 +02:00
number : this . props . number != null ? this . props . number : 0 ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
className : BDFDB . disCN . marginreset ,
shrink : 0 ,
grow : 0 ,
children : customSwatch
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
direction : InternalComponents . LibraryComponents . Flex . Direction . VERTICAL ,
className : BDFDB . disCN . flexmarginreset ,
grow : 1 ,
children : [
this . renderRow ( this . state . colorRows [ 0 ] ) ,
this . renderRow ( this . state . colorRows [ 1 ] )
]
} )
]
} ) ;
}
} ;
InternalComponents . LibraryComponents . EmojiPickerButton = reactInitialized && class BDFDB _EmojiPickerButton extends LibraryModules . React . Component {
handleEmojiChange ( emoji ) {
if ( emoji != null ) {
this . props . emoji = emoji . id ? {
id : emoji . id ,
name : emoji . name ,
animated : emoji . animated
} : {
id : null ,
name : emoji . optionallyDiverseSequence ,
animated : false
} ;
if ( typeof this . props . onSelect == "function" ) this . props . onSelect ( this . props . emoji , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
}
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PopoutContainer , {
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . EmojiButton , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . emojiinputbutton ) ,
renderButtonContents : this . props . emoji ? _ => BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Emoji , {
className : BDFDB . disCN . emoji ,
emojiId : this . props . emoji . id ,
emojiName : this . props . emoji . name
} ) : null
} ) ,
wrap : false ,
animation : InternalComponents . LibraryComponents . PopoutContainer . Animation . NONE ,
position : InternalComponents . LibraryComponents . PopoutContainer . Positions . TOP ,
align : InternalComponents . LibraryComponents . PopoutContainer . Align . LEFT ,
renderPopout : instance => {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . EmojiPicker , {
closePopout : instance . close ,
onSelectEmoji : this . handleEmojiChange . bind ( this ) ,
allowManagedEmojis : this . props . allowManagedEmojis
} ) ;
}
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . EmojiPickerButton , { allowManagedEmojis : false } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . FavButton = reactInitialized && class BDFDB _FavButton extends LibraryModules . React . Component {
handleClick ( ) {
this . props . isFavorite = ! this . props . isFavorite ;
if ( typeof this . props . onClick == "function" ) this . props . onClick ( this . props . isFavorite , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . favbuttoncontainer , this . props . className ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . FavButton , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , { onClick : this . handleClick . bind ( this ) } ) , "className" ) )
} ) ;
}
} ;
InternalComponents . LibraryComponents . FileButton = reactInitialized && class BDFDB _FileButton extends LibraryModules . React . Component {
componentDidMount ( ) {
if ( this . props . searchFolders ) {
let node = BDFDB . ReactUtils . findDOMNode ( this ) ;
if ( node && ( node = node . querySelector ( "input[type='file']" ) ) != null ) {
node . setAttribute ( "directory" , "" ) ;
node . setAttribute ( "webkitdirectory" , "" ) ;
}
}
}
render ( ) {
let filter = this . props . filter && [ this . props . filter ] . flat ( 10 ) . filter ( n => typeof n == "string" ) || [ ] ;
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Button , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
onClick : e => { e . currentTarget . querySelector ( "input" ) . click ( ) ; } ,
children : [
BDFDB . LanguageUtils . LibraryStrings . file _navigator _text ,
BDFDB . ReactUtils . createElement ( "input" , {
type : "file" ,
accept : filter . length && ( filter . join ( "/*," ) + "/*" ) ,
style : { display : "none" } ,
onChange : e => {
let file = e . currentTarget . files [ 0 ] ;
if ( this . refInput && file && ( ! filter . length || filter . some ( n => file . type . indexOf ( n ) == 0 ) ) ) {
2021-01-18 14:31:25 +01:00
this . refInput . props . value = this . props . searchFolders ? file . path . split ( file . name ) . slice ( 0 , - 1 ) . join ( file . name ) : ` ${ this . props . mode == "url" ? "url('" : "" } ${ ( this . props . useFilePath ) ? file . path : ` data: ${ file . type } ;base64, ${ BDFDB . LibraryRequires . fs . readFileSync ( file . path ) . toString ( "base64" ) } ` } ${ this . props . mode ? "')" : "" } ` ;
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . forceUpdate ( this . refInput ) ;
this . refInput . handleChange ( this . refInput . props . value ) ;
}
}
} )
]
} ) , "filter" , "mode" , "useFilePath" , "searchFolders" ) ) ;
}
} ;
InternalComponents . LibraryComponents . FormComponents . FormItem = reactInitialized && class BDFDB _FormItem extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : this . props . className ,
style : this . props . style ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
align : InternalComponents . LibraryComponents . Flex . Align . BASELINE ,
children : [
this . props . title != null || this . props . error != null ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
wrap : true ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormTitle , {
tag : this . props . tag || InternalComponents . LibraryComponents . FormComponents . FormTitle . Tags . H5 ,
disabled : this . props . disabled ,
required : this . props . required ,
error : this . props . error ,
className : this . props . titleClassName ,
children : this . props . title
} )
} ) : null
] . concat ( [ this . props . titlechildren ] . flat ( 10 ) ) . filter ( n => n )
} ) ,
] . concat ( this . props . children )
} ) ;
}
} ;
InternalComponents . LibraryComponents . GuildComponents = Object . assign ( { } , InternalComponents . LibraryComponents . GuildComponents ) ;
InternalComponents . LibraryComponents . GuildComponents . Guild = reactInitialized && class BDFDB _Guild extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
this . state = { hovered : false } ;
}
handleMouseEnter ( e ) {
if ( ! this . props . sorting ) this . setState ( { hovered : true } ) ;
if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ;
}
handleMouseLeave ( e ) {
if ( ! this . props . sorting ) this . setState ( { hovered : false } ) ;
if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ;
}
handleMouseDown ( e ) {
if ( ! this . props . unavailable && this . props . guild && this . props . selectedChannelId ) LibraryModules . DirectMessageUtils . preload ( this . props . guild . id , this . props . selectedChannelId ) ;
if ( e . button == 0 && typeof this . props . onMouseDown == "function" ) this . props . onMouseDown ( e , this ) ;
}
handleMouseUp ( e ) {
if ( e . button == 0 && typeof this . props . onMouseUp == "function" ) this . props . onMouseUp ( e , this ) ;
}
handleClick ( e ) {
if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ;
}
handleContextMenu ( e ) {
if ( this . props . menu ) BDFDB . GuildUtils . openMenu ( this . props . guild , e ) ;
if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ;
}
setRef ( e ) {
if ( typeof this . props . setRef == "function" ) this . props . setRef ( this . props . guild . id , e )
}
componentDidMount ( ) {
let node = BDFDB . ReactUtils . findDOMNode ( this ) ;
if ( node ) for ( let child of node . querySelectorAll ( "a" ) ) child . setAttribute ( "draggable" , false ) ;
}
render ( ) {
if ( ! this . props . guild ) return null ;
let currentVoiceChannel = LibraryModules . ChannelStore . getChannel ( LibraryModules . CurrentVoiceUtils . getChannelId ( ) ) ;
let hasVideo = currentVoiceChannel && LibraryModules . VoiceUtils . hasVideo ( currentVoiceChannel ) ;
this . props . guildId = this . props . guild . id ;
this . props . selectedChannelId = LibraryModules . LastChannelStore . getChannelId ( this . props . guild . id ) ;
this . props . selected = this . props . state ? LibraryModules . LastGuildStore . getGuildId ( ) == this . props . guild . id : false ;
this . props . unread = this . props . state ? LibraryModules . UnreadGuildUtils . hasUnread ( this . props . guild . id ) : false ;
this . props . badge = this . props . state ? LibraryModules . UnreadGuildUtils . getMentionCount ( this . props . guild . id ) : 0 ;
this . props . audio = this . props . state ? currentVoiceChannel && currentVoiceChannel . guild _id == this . props . guild . id && ! hasVideo : false ;
this . props . video = this . props . state ? currentVoiceChannel && currentVoiceChannel . guild _id == this . props . guild . id && hasVideo : false ;
this . props . screenshare = this . props . state ? ! ! LibraryModules . StreamUtils . getAllApplicationStreams ( ) . filter ( stream => stream . guildId == this . props . guild . id ) [ 0 ] : false ;
2021-02-05 23:24:38 +01:00
this . props . participating = this . props . state ? LibraryModules . CurrentVoiceUtils . getGuildId ( ) == this . props . guild . id : false ;
2020-09-19 21:32:19 +02:00
this . props . animatable = this . props . state ? LibraryModules . IconUtils . hasAnimatedGuildIcon ( this . props . guild ) : false ;
this . props . unavailable = this . props . state ? LibraryModules . GuildUnavailableStore . unavailableGuilds . includes ( this . props . guild . id ) : false ;
let isDraggedGuild = this . props . draggingGuildId === this . props . guild . id ;
let guild = isDraggedGuild ? BDFDB . ReactUtils . createElement ( "div" , {
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . Items . DragPlaceholder , { } )
} ) : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . guildcontainer ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . BlobMask , {
selected : this . state . isDropHovering || this . props . selected || this . state . hovered ,
2021-02-05 23:24:38 +01:00
upperBadge : this . props . unavailable ? InternalComponents . LibraryComponents . GuildComponents . Items . renderUnavailableBadge ( ) : InternalComponents . LibraryComponents . GuildComponents . Items . renderIconBadge ( BDFDB . ObjectUtils . extract ( this . props , "audio" , "video" , "screenshare" , "participating" ) ) ,
2020-09-19 21:32:19 +02:00
lowerBadge : this . props . badge > 0 ? InternalComponents . LibraryComponents . GuildComponents . Items . renderMentionBadge ( this . props . badge ) : null ,
lowerBadgeWidth : InternalComponents . LibraryComponents . Badges . getBadgeWidthForValue ( this . props . badge ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . NavItem , {
to : {
pathname : BDFDB . DiscordConstants . Routes . CHANNEL ( this . props . guild . id , this . props . selectedChannelId ) ,
state : {
analyticsSource : {
page : BDFDB . DiscordConstants . AnalyticsPages . GUILD _CHANNEL ,
section : BDFDB . DiscordConstants . AnalyticsSections . CHANNEL _LIST ,
object : BDFDB . DiscordConstants . AnalyticsObjects . CHANNEL
}
}
} ,
name : this . props . guild . name ,
onMouseEnter : this . handleMouseEnter . bind ( this ) ,
onMouseLeave : this . handleMouseLeave . bind ( this ) ,
onMouseDown : this . handleMouseDown . bind ( this ) ,
onMouseUp : this . handleMouseUp . bind ( this ) ,
onClick : this . handleClick . bind ( this ) ,
onContextMenu : this . handleContextMenu . bind ( this ) ,
icon : this . props . guild . getIconURL ( this . state . hovered && this . props . animatable ? "gif" : "png" ) ,
selected : this . props . selected || this . state . hovered
} )
} )
} ) ;
if ( this . props . draggable && typeof this . props . connectDragSource == "function" ) guild = this . props . connectDragSource ( guild ) ;
let children = [
this . props . list || this . props . pill ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . Pill , {
hovered : ! isDraggedGuild && this . state . hovered ,
selected : ! isDraggedGuild && this . props . selected ,
unread : ! isDraggedGuild && this . props . unread ,
className : BDFDB . disCN . guildpill
} ) : null ,
! this . props . tooltip ? guild : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
tooltipConfig : Object . assign ( { type : "right" } , this . props . tooltipConfig , { guild : this . props . list && this . props . guild } ) ,
children : guild
} )
] . filter ( n => n ) ;
return this . props . list ? BDFDB . ReactUtils . createElement ( "div" , {
ref : null != this . props . setRef ? this . props . setRef : null ,
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . guildouter , BDFDB . disCN . _bdguild , this . props . unread && BDFDB . disCN . _bdguildunread , this . props . selected && BDFDB . disCN . _bdguildselected , this . props . unread && BDFDB . disCN . _bdguildunread , this . props . audio && BDFDB . disCN . _bdguildaudio , this . props . video && BDFDB . disCN . _bdguildvideo ) ,
children : BDFDB . ReactUtils . createElement ( BDFDB . ReactUtils . Fragment , {
children : children
} )
} ) : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . guild , this . props . className ) ,
children : children
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . GuildComponents . Guild , { menu : true , tooltip : true , list : false , state : false , draggable : false , sorting : false } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . GuildSummaryItem = reactInitialized && class BDFDB _GuildSummaryItem extends LibraryModules . React . Component {
defaultRenderGuild ( guild , isLast ) {
if ( ! guild ) return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . guildsummaryemptyguild
} ) ;
let icon = BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . Icon , {
className : BDFDB . disCN . guildsummaryicon ,
guild : guild ,
showTooltip : this . props . showTooltip ,
tooltipPosition : "top" ,
size : InternalComponents . LibraryComponents . GuildComponents . Icon . Sizes . SMALLER
} ) ;
return this . props . switchOnClick ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , {
className : BDFDB . disCN . guildsummaryclickableicon ,
onClick : _ => { LibraryModules . SelectChannelUtils . selectChannel ( guild . id , LibraryModules . LastChannelStore . getChannelId ( guild . id ) ) ; } ,
key : guild . id ,
tabIndex : - 1 ,
children : icon
} ) : icon ;
}
renderGuilds ( ) {
let elements = [ ] ;
let renderGuild = typeof this . props . renderGuild != "function" ? this . defaultRenderGuild : this . props . renderGuild ;
let loaded = 0 , max = this . props . guilds . length === this . props . max ? this . props . guilds . length : this . props . max - 1 ;
while ( loaded < max && loaded < this . props . guilds . length ) {
let isLast = loaded === this . props . guilds . length - 1 ;
let guild = renderGuild . apply ( this , [ this . props . guilds [ loaded ] , isLast ] ) ;
elements . push ( BDFDB . ReactUtils . createElement ( "div" , {
className : isLast ? BDFDB . disCN . guildsummaryiconcontainer : BDFDB . disCN . guildsummaryiconcontainermasked ,
children : guild
} ) ) ;
loaded ++ ;
}
if ( loaded < this . props . guilds . length ) {
let rest = Math . min ( this . props . guilds . length - loaded , 99 ) ;
elements . push ( BDFDB . ReactUtils . createElement ( LibraryModules . React . Fragment , {
key : "more-guilds" ,
children : this . props . renderMoreGuilds ( "+" + rest , rest , this . props . guilds . slice ( loaded ) , this . props )
} ) ) ;
}
return elements ;
}
renderIcon ( ) {
return this . props . renderIcon ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : InternalComponents . LibraryComponents . SvgIcon . Names . WHATISTHIS ,
className : BDFDB . disCN . guildsummarysvgicon
} ) : null ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . guildsummarycontainer ) ,
ref : this . props . _ref ,
children : [
this . renderIcon . apply ( this ) ,
this . renderGuilds . apply ( this )
] . flat ( 10 ) . filter ( n => n )
} ) ;
}
}
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . GuildSummaryItem , { max : 10 , renderMoreGuilds : ( count , amount , restGuilds , props ) => {
2020-09-19 21:32:19 +02:00
let icon = BDFDB . ReactUtils . createElement ( "div" , { className : BDFDB . disCN . guildsummarymoreguilds , children : count } ) ;
return props . showTooltip ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
text : restGuilds . map ( guild => guild . name ) . join ( ", " ) ,
children : icon
} ) : icon ;
2020-11-19 16:51:14 +01:00
} , renderIcon : false } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . KeybindRecorder = reactInitialized && class BDFDB _KeybindRecorder extends LibraryModules . React . Component {
handleChange ( arrays ) {
2021-02-04 20:12:57 +01:00
if ( typeof this . props . onChange == "function" ) this . props . onChange ( arrays . map ( platformkey => LibraryModules . KeyEvents . codes [ LibraryModules . KeyCodeUtils . codeToKey ( platformkey ) ] || platformkey [ 1 ] ) , this ) ;
2020-09-19 21:32:19 +02:00
}
handleReset ( ) {
this . props . defaultValue = [ ] ;
let recorder = BDFDB . ReactUtils . findOwner ( this , { name : "KeybindRecorder" } ) ;
if ( recorder ) recorder . setState ( { codes : [ ] } ) ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( [ ] , this ) ;
if ( typeof this . props . onReset == "function" ) this . props . onReset ( this ) ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . disCN . hotkeywrapper ,
direction : InternalComponents . LibraryComponents . Flex . Direction . HORIZONTAL ,
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . KeybindRecorder , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
defaultValue : [ this . props . defaultValue ] . flat ( 10 ) . filter ( n => n ) . map ( keycode => [ BDFDB . DiscordConstants . KeyboardDeviceTypes . KEYBOARD _KEY , keycode , BDFDB . DiscordConstants . KeyboardEnvs . BROWSER ] ) ,
onChange : this . handleChange . bind ( this )
} ) , "reset" , "onReset" ) ) ,
this . props . reset || this . props . onReset ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
text : BDFDB . LanguageUtils . LanguageStrings . REMOVE _KEYBIND ,
tooltipConfig : { type : "top" } ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , {
className : BDFDB . disCN . hotkeyresetbutton ,
onClick : this . handleReset . bind ( this ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
iconSVG : ` <svg height="20" width="20" viewBox="0 0 20 20"><path fill="currentColor" d="M 14.348 14.849 c -0.469 0.469 -1.229 0.469 -1.697 0 l -2.651 -3.030 -2.651 3.029 c -0.469 0.469 -1.229 0.469 -1.697 0 -0.469 -0.469 -0.469 -1.229 0 -1.697l2.758 -3.15 -2.759 -3.152 c -0.469 -0.469 -0.469 -1.228 0 -1.697 s 1.228 -0.469 1.697 0 l 2.652 3.031 2.651 -3.031 c 0.469 -0.469 1.228 -0.469 1.697 0 s 0.469 1.229 0 1.697l -2.758 3.152 2.758 3.15 c 0.469 0.469 0.469 1.229 0 1.698 z"></path></svg> ` ,
} )
} )
} ) : null
] . filter ( n => n )
} ) ;
}
} ;
InternalComponents . LibraryComponents . ListRow = reactInitialized && class BDFDB _ListRow extends LibraryModules . React . Component {
2021-01-06 11:57:04 +01:00
render ( ) {
2020-09-19 21:32:19 +02:00
return BDFDB . ReactUtils . createElement ( "div" , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . listrowwrapper , this . props . className , BDFDB . disCN . listrow ) ,
children : [
this . props . prefix ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . listrowcontent ,
style : { flex : "1 1 auto" } ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . listname , this . props . labelClassName ) ,
style : { flex : "1 1 auto" } ,
children : this . props . label
} ) ,
typeof this . props . note == "string" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormText , {
type : InternalComponents . LibraryComponents . FormComponents . FormText . Types . DESCRIPTION ,
children : this . props . note
} ) : null
] . filter ( n => n )
} ) ,
this . props . suffix
] . filter ( n => n )
} ) , "label" , "note" , "suffix" , "prefix" , "labelClassName" ) ) ;
}
} ;
InternalComponents . LibraryComponents . MemberRole = reactInitialized && class BDFDB _MemberRole extends LibraryModules . React . Component {
handleClick ( e ) { if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ; }
handleContextMenu ( e ) { if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ; }
render ( ) {
let color = BDFDB . ColorUtils . convert ( this . props . role . colorString || BDFDB . DiscordConstants . Colors . PRIMARY _DARK _300 , "RGB" ) ;
return BDFDB . ReactUtils . createElement ( "li" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . userpopoutrole , this . props . className ) ,
style : { borderColor : BDFDB . ColorUtils . setAlpha ( color , 0.6 ) } ,
onClick : this . handleClick . bind ( this ) ,
onContextMenu : this . handleContextMenu . bind ( this ) ,
children : [
! this . props . noCircle ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . userpopoutrolecircle ,
style : { backgroundColor : color }
} ) : null ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . userpopoutrolename ,
children : this . props . role . name
} )
] . filter ( n => n )
} ) ;
}
} ;
InternalComponents . LibraryComponents . MenuItems . MenuCheckboxItem = reactInitialized && class BDFDB _MenuCheckboxItem extends LibraryModules . React . Component {
handleClick ( ) {
if ( this . props . state ) {
this . props . state . checked = ! this . props . state . checked ;
if ( typeof this . props . action == "function" ) this . props . action ( this . props . state . checked , this ) ;
}
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . MenuCheckboxItem , Object . assign ( { } , this . props , {
checked : this . props . state && this . props . state . checked ,
action : this . handleClick . bind ( this )
} ) ) ;
}
} ;
InternalComponents . LibraryComponents . MenuItems . MenuHint = reactInitialized && class BDFDB _MenuHint extends LibraryModules . React . Component {
render ( ) {
return ! this . props . hint ? null : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . menuhint ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextScroller , {
children : this . props . hint
} )
} ) ;
}
} ;
InternalComponents . LibraryComponents . MenuItems . MenuIcon = reactInitialized && class BDFDB _MenuIcon extends LibraryModules . React . Component {
render ( ) {
let isString = typeof this . props . icon == "string" ;
return ! this . props . icon ? null : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . menuicon ,
2020-10-06 11:57:12 +02:00
nativeClass : true ,
2020-09-19 21:32:19 +02:00
iconSVG : isString ? this . props . icon : null ,
name : ! isString ? this . props . icon : null
} ) ;
}
} ;
InternalComponents . LibraryComponents . MenuItems . MenuSliderItem = reactInitialized && class BDFDB _MenuSliderItem extends LibraryModules . React . Component {
handleValueChange ( value ) {
if ( this . props . state ) {
this . props . state . value = Math . round ( BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , [ this . props . minValue , this . props . maxValue ] , value ) * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ;
if ( typeof this . props . onValueChange == "function" ) this . props . onValueChange ( this . props . state . value , this ) ;
}
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
handleValueRender ( value ) {
let newValue = Math . round ( BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , [ this . props . minValue , this . props . maxValue ] , value ) * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ;
if ( typeof this . props . onValueRender == "function" ) {
let tempReturn = this . props . onValueRender ( newValue , this ) ;
if ( tempReturn != undefined ) newValue = tempReturn ;
}
return newValue ;
}
render ( ) {
let value = this . props . state && this . props . state . value || 0 ;
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . MenuControlItem , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
label : typeof this . props . renderLabel == "function" ? this . props . renderLabel ( Math . round ( value * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ) : this . props . label ,
control : ( menuItemProps , ref ) => {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . menuslidercontainer ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . Slider , Object . assign ( { } , menuItemProps , {
ref : ref ,
className : BDFDB . disCN . menuslider ,
mini : true ,
initialValue : Math . round ( BDFDB . NumberUtils . mapRange ( [ this . props . minValue , this . props . maxValue ] , [ 0 , 100 ] , value ) * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ,
onValueChange : this . handleValueChange . bind ( this ) ,
onValueRender : this . handleValueRender . bind ( this )
} ) )
} ) ;
}
} ) , "digits" , "renderLabel" ) ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . MenuItems . MenuSliderItem , { minValue : 0 , maxValue : 100 , digits : 0 } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . ModalComponents . ModalContent = reactInitialized && class BDFDB _ModalContent extends LibraryModules . React . Component {
render ( ) {
return this . props . scroller ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Scrollers . Thin , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . modalcontent , this . props . className ) ,
ref : this . props . scrollerRef ,
children : this . props . children
} ) : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . DOMUtils . formatClassName ( this . props . content && BDFDB . disCN . modalcontent , BDFDB . disCN . modalnoscroller , this . props . className ) ,
direction : this . props . direction || InternalComponents . LibraryComponents . Flex . Direction . VERTICAL ,
align : InternalComponents . LibraryComponents . Flex . Align . STRETCH ,
children : this . props . children
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . ModalComponents . ModalContent , { scroller : true , content : true } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . ModalComponents . ModalTabContent = reactInitialized && class BDFDB _ModalTabContent extends LibraryModules . React . Component {
render ( ) {
2021-01-29 22:18:18 +01:00
return ! this . props . open ? null : BDFDB . ReactUtils . createElement ( this . props . scroller ? InternalComponents . LibraryComponents . Scrollers . Thin : "div" , Object . assign ( BDFDB . ObjectUtils . exclude ( this . props , "scroller" , "open" ) , {
2020-09-19 21:32:19 +02:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . modaltabcontent , this . props . open && BDFDB . disCN . modaltabcontentopen , this . props . className ) ,
2021-01-29 22:18:18 +01:00
children : this . props . children
} ) ) ;
2020-09-19 21:32:19 +02:00
}
} ;
2021-01-29 22:18:18 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . ModalComponents . ModalTabContent , { tab : "unnamed" } ) ;
2020-09-19 21:32:19 +02:00
2020-10-08 17:35:36 +02:00
InternalComponents . LibraryComponents . ModalComponents . ModalFooter = reactInitialized && class BDFDB _ModalFooter extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
2020-11-23 20:27:07 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . modalfooter , this . props . className ) ,
2020-10-08 17:35:36 +02:00
direction : this . props . direction || InternalComponents . LibraryComponents . Flex . Direction . HORIZONTAL _REVERSE ,
align : InternalComponents . LibraryComponents . Flex . Align . STRETCH ,
2020-10-15 12:54:49 +02:00
grow : 0 ,
2020-10-31 11:49:46 +01:00
shrink : 0 ,
2020-10-08 17:35:36 +02:00
children : this . props . children
} ) ;
}
} ;
2020-10-29 20:34:51 +01:00
InternalComponents . LibraryComponents . MultiInput = reactInitialized && class BDFDB _MultiInput extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
this . state = { focused : false } ;
}
render ( ) {
if ( this . props . children && this . props . children . props ) this . props . children . props . className = BDFDB . DOMUtils . formatClassName ( this . props . children . props . className , BDFDB . disCN . inputmultifield ) ;
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . inputwrapper , BDFDB . disCN . inputmultiwrapper ) ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . input , BDFDB . disCN . inputmulti , this . state . focused && BDFDB . disCN . inputfocused ) ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . innerClassName , BDFDB . disCN . inputwrapper , BDFDB . disCN . inputmultifirst ) ,
children : this . props . children
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextInput , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
className : BDFDB . disCN . inputmultilast ,
inputClassName : BDFDB . disCN . inputmultifield ,
onFocus : e => { this . setState ( { focused : true } ) } ,
onBlur : e => { this . setState ( { focused : false } ) }
2020-10-30 17:55:12 +01:00
} ) , "children" , "innerClassName" ) )
2020-10-29 20:34:51 +01:00
]
} )
} ) ;
}
} ;
InternalComponents . LibraryComponents . ListInput = reactInitialized && class BDFDB _ListInput extends LibraryModules . React . Component {
handleChange ( ) {
if ( typeof this . props . onChange ) this . props . onChange ( this . props . items , this ) ;
}
render ( ) {
2020-10-31 11:12:54 +01:00
if ( ! BDFDB . ArrayUtils . is ( this . props . items ) ) this . props . items = [ ] ;
2020-10-30 18:13:44 +01:00
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . MultiInput , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
2020-10-29 20:34:51 +01:00
className : BDFDB . disCN . inputlist ,
innerClassName : BDFDB . disCN . inputlistitems ,
onKeyDown : e => {
if ( e . which == 13 && e . target . value && e . target . value . trim ( ) ) {
2020-10-30 18:13:44 +01:00
let value = e . target . value . trim ( ) ;
2020-10-29 20:34:51 +01:00
this . props . value = "" ;
if ( ! this . props . items . includes ( value ) ) {
this . props . items . push ( value ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
this . handleChange . apply ( this , [ ] ) ;
}
}
} ,
2020-10-31 11:12:54 +01:00
children : this . props . items . map ( item => BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Badges . TextBadge , {
2020-10-29 20:34:51 +01:00
className : BDFDB . disCN . inputlistitem ,
2020-12-16 16:35:56 +01:00
color : "var(--bdfdb-blurple)" ,
2020-10-29 20:34:51 +01:00
style : { borderRadius : "3px" } ,
text : [
item ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . inputlistdelete ,
name : InternalComponents . LibraryComponents . SvgIcon . Names . CLOSE ,
onClick : _ => {
BDFDB . ArrayUtils . remove ( this . props . items , item ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
this . handleChange . apply ( this , [ ] ) ;
}
} )
]
} ) )
2020-10-30 18:13:44 +01:00
} ) , "items" ) ) ;
2020-10-29 20:34:51 +01:00
}
} ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . PaginatedList = reactInitialized && class BDFDB _PaginatedList extends LibraryModules . React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
offset : props . offset
} ;
}
2021-01-09 20:11:20 +01:00
handleJump ( offset ) {
2020-09-19 21:32:19 +02:00
if ( offset > - 1 && offset < Math . ceil ( this . props . items . length / this . props . amount ) && this . state . offset != offset ) {
this . state . offset = offset ;
if ( typeof this . props . onJump == "function" ) this . props . onJump ( offset , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
}
2021-01-09 20:11:20 +01:00
renderPagination ( bottom ) {
2020-09-19 21:32:19 +02:00
let maxOffset = Math . ceil ( this . props . items . length / this . props . amount ) - 1 ;
return this . props . items . length > this . props . amount && BDFDB . ReactUtils . createElement ( "nav" , {
2021-01-09 20:11:20 +01:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . pagination , bottom ? BDFDB . disCN . paginationbottom : BDFDB . disCN . paginationtop , this . props . mini && BDFDB . disCN . paginationmini ) ,
2020-09-19 21:32:19 +02:00
children : [
2021-01-09 20:11:20 +01:00
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Paginator , {
totalCount : this . props . items . length ,
currentPage : this . state . offset + 1 ,
pageSize : this . props . amount ,
maxVisiblePages : this . props . maxVisiblePages ,
onPageChange : page => { this . handleJump ( isNaN ( parseInt ( page ) ) ? - 1 : page - 1 ) ; }
2020-09-19 21:32:19 +02:00
} ) ,
2020-10-08 17:35:36 +02:00
this . props . jump && BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextInput , {
2020-09-19 21:32:19 +02:00
type : "number" ,
2020-10-08 17:35:36 +02:00
size : InternalComponents . LibraryComponents . TextInput . Sizes . MINI ,
2020-09-19 21:32:19 +02:00
value : this . state . offset + 1 ,
min : 1 ,
max : maxOffset + 1 ,
2021-01-09 20:11:20 +01:00
onKeyDown : ( event , instance ) => { if ( event . which == 13 ) this . handleJump ( isNaN ( parseInt ( instance . props . value ) ) ? - 1 : instance . props . value - 1 ) ; }
2020-09-19 21:32:19 +02:00
} ) ,
] . filter ( n => n )
} ) ;
}
render ( ) {
let items = [ ] , alphabet = { } ;
if ( BDFDB . ArrayUtils . is ( this . props . items ) && this . props . items . length ) {
if ( ! this . props . alphabetKey ) items = this . props . items ;
else {
let unsortedItems = [ ] . concat ( this . props . items ) ;
for ( let key of [ "0-9" , "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" , "P" , "Q" , "R" , "S" , "T" , "U" , "V" , "W" , "X" , "Y" , "Z" ] ) {
let numbers = key == "0-9" , alphaItems = [ ] ;
for ( let item of unsortedItems ) if ( item && item [ this . props . alphabetKey ] && ( numbers && ! isNaN ( parseInt ( item [ this . props . alphabetKey ] [ 0 ] ) ) || item [ this . props . alphabetKey ] . toUpperCase ( ) . indexOf ( key ) == 0 ) ) alphaItems . push ( item ) ;
for ( let sortedItem of alphaItems ) BDFDB . ArrayUtils . remove ( unsortedItems , sortedItem ) ;
2020-11-19 16:51:14 +01:00
alphabet [ key ] = { items : BDFDB . ArrayUtils . keySort ( alphaItems , this . props . alphabetKey ) , disabled : ! alphaItems . length } ;
2020-09-19 21:32:19 +02:00
}
2020-11-19 16:51:14 +01:00
alphabet [ "?!" ] = { items : BDFDB . ArrayUtils . keySort ( unsortedItems , this . props . alphabetKey ) , disabled : ! unsortedItems . length } ;
2020-09-19 21:32:19 +02:00
for ( let key in alphabet ) items . push ( alphabet [ key ] . items ) ;
items = items . flat ( 10 ) ;
}
}
return typeof this . props . renderItem != "function" || ! items . length ? null : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Scrollers . Thin , {
2021-01-09 20:11:20 +01:00
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . paginationlist , this . props . mini && BDFDB . disCN . paginationlistmini ) ,
2020-09-19 21:32:19 +02:00
fade : this . props . fade ,
children : [
this . renderPagination ( ) ,
items . length > this . props . amount && this . props . alphabetKey && BDFDB . ReactUtils . createElement ( "nav" , {
className : BDFDB . disCN . paginationlistalphabet ,
2020-10-08 17:35:36 +02:00
children : Object . keys ( alphabet ) . map ( key => BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , {
2020-09-19 21:32:19 +02:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . paginationlistalphabetchar , alphabet [ key ] . disabled && BDFDB . disCN . paginationlistalphabetchardisabled ) ,
2021-01-09 20:11:20 +01:00
onClick : _ => { if ( ! alphabet [ key ] . disabled ) this . handleJump ( Math . floor ( items . indexOf ( alphabet [ key ] . items [ 0 ] ) / this . props . amount ) ) ; } ,
2020-09-19 21:32:19 +02:00
children : key
} ) )
} ) ,
this . props . header ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . paginationlistcontent ,
children : items . slice ( this . state . offset * this . props . amount , ( this . state . offset + 1 ) * this . props . amount ) . map ( ( data , i ) => { return this . props . renderItem ( data , i ) ; } ) . flat ( 10 ) . filter ( n => n )
} ) ,
2021-01-09 20:11:20 +01:00
this . props . copyToBottom && this . renderPagination ( true )
2020-09-19 21:32:19 +02:00
] . flat ( 10 ) . filter ( n => n )
} ) ;
}
} ;
2021-01-09 20:11:20 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . PaginatedList , { amount : 50 , offset : 0 , mini : true , jump : true , maxVisiblePages : 7 , copyToBottom : false , fade : true } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . Popout = reactInitialized && class BDFDB _Popout extends LibraryModules . React . Component {
componentWillUnmount ( ) {
delete this . props . containerInstance . popout ;
if ( typeof this . props . onClose == "function" ) this . props . onClose ( this . props . containerInstance , this ) ;
}
render ( ) {
let pos = typeof this . props . position == "string" ? this . props . position . toLowerCase ( ) : null ;
let positionClass = pos && DiscordClasses [ "popout" + pos ] ? BDFDB . disCN [ "popout" + pos ] : BDFDB . disCN . popouttop ;
let arrowClass = ! this . props . arrow ? BDFDB . disCN . popoutnoarrow : ( pos && pos . indexOf ( "top" ) > - 1 && pos != "top" ? BDFDB . disCN . popoutarrowalignmenttop : BDFDB . disCN . popoutarrowalignmentmiddle ) ;
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PopoutFocusLock , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . popoutwrapper , BDFDB . disCN . popout , positionClass , this . props . invert && pos && pos != "bottom" && BDFDB . disCN . popoutinvert , arrowClass , ! this . props . shadow && BDFDB . disCN . popoutnoshadow ) ,
id : this . props . id ,
onClick : e => { e . stopPropagation ( ) ; } ,
style : Object . assign ( { } , this . props . style , {
position : this . props . isChild ? "relative" : "absolute"
} ) ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , this . props . themed && BDFDB . disCN . popoutthemedpopout ) ,
style : BDFDB . ObjectUtils . extract ( this . props , "padding" , "height" , "maxHeight" , "minHeight" , "width" , "maxWidth" , "minWidth" ) ,
children : this . props . children
} )
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . Popout , { themed : true } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . PopoutContainer = reactInitialized && class BDFDB _PopoutContainer extends LibraryModules . React . Component {
handleRender ( e ) {
let children = typeof this . props . renderPopout == "function" ? this . props . renderPopout ( this ) : null ;
return this . context . popout = ! children ? null : ( ! this . props . wrap ? children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Popout , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
className : this . props . popoutClassName ,
containerInstance : this ,
isChild : true ,
position : e . position ,
style : this . props . popoutStyle ,
onClose : typeof this . props . onClose == "function" ? this . props . onClose . bind ( this ) : _ => { } ,
children : children
} ) , "popoutStyle" , "popoutClassName" ) ) ) ;
}
componentDidMount ( ) {
2020-11-19 16:51:14 +01:00
let basePopout = BDFDB . ReactUtils . findOwner ( this , { name : "BasePopout" } ) ;
2020-09-19 21:32:19 +02:00
if ( ! basePopout || ! basePopout . handleClick ) return ;
basePopout . isBDFDBpopout = true ;
this . handleClick = e => { return basePopout . handleClick ( BDFDB . ObjectUtils . is ( e ) ? e : ( new MouseEvent ( { } ) ) ) ; } ;
this . close = basePopout . close ;
this . domElementRef = basePopout . domElementRef ;
}
render ( ) {
let child = ( BDFDB . ArrayUtils . is ( this . props . children ) ? this . props . children [ 0 ] : this . props . children ) || BDFDB . ReactUtils . createElement ( "div" , { style : { height : "100%" , width : "100%" } } ) ;
child . props . className = BDFDB . DOMUtils . formatClassName ( child . props . className , this . props . className ) ;
let childClick = child . props . onClick , childContextMenu = child . props . onContextMenu ;
child . props . onClick = ( e , childThis ) => {
if ( ! this . domElementRef . current || this . domElementRef . current . contains ( e . target ) ) {
if ( ( this . props . openOnClick || this . props . openOnClick === undefined ) && typeof this . handleClick == "function" ) this . handleClick ( e ) ;
if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ;
if ( typeof childClick == "function" ) childClick ( e , childThis ) ;
}
else e . stopPropagation ( ) ;
} ;
child . props . onContextMenu = ( e , childThis ) => {
if ( ! this . domElementRef . current || this . domElementRef . current . contains ( e . target ) ) {
if ( this . props . openOnContextMenu && typeof this . handleClick == "function" ) this . handleClick ( e ) ;
if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ;
if ( typeof childContextMenu == "function" ) childContextMenu ( e , childThis ) ;
}
else e . stopPropagation ( ) ;
} ;
return BDFDB . ReactUtils . createElement ( LibraryModules . React . Fragment , {
children : BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . PopoutContainer , Object . assign ( { } , this . props , {
children : _ => { return child ; } ,
renderPopout : this . handleRender . bind ( this )
} ) )
} ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . PopoutContainer , { wrap : true } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . QuickSelect = reactInitialized && class BDFDB _QuickSelect extends LibraryModules . React . Component {
handleChange ( option ) {
this . props . value = option ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( option . value || option . key , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
let options = ( BDFDB . ArrayUtils . is ( this . props . options ) ? this . props . options : [ { } ] ) . filter ( n => n ) ;
let selectedOption = BDFDB . ObjectUtils . is ( this . props . value ) ? this . props . value : ( options [ 0 ] || { } ) ;
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . quickselectwrapper ) ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . disCN . quickselect ,
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . quickselectlabel ,
children : this . props . label
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
className : BDFDB . disCN . quickselectclick ,
onClick : event => {
LibraryModules . ContextMenuUtils . openContextMenu ( event , _ => {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Menu , {
navId : "bdfdb-quickselect" ,
2021-02-04 20:12:57 +01:00
onClose : LibraryModules . ContextMenuUtils . closeContextMenu ,
2020-09-19 21:32:19 +02:00
className : this . props . popoutClassName ,
children : BDFDB . ContextMenuUtils . createItem ( InternalComponents . LibraryComponents . MenuItems . MenuGroup , {
children : options . map ( ( option , i ) => {
let selected = option . value && option . value === selectedOption . value || option . key && option . key === selectedOption . key ;
return BDFDB . ContextMenuUtils . createItem ( InternalComponents . LibraryComponents . MenuItems . MenuItem , {
label : option . label ,
id : BDFDB . ContextMenuUtils . createItemId ( "option" , option . key || option . value || i ) ,
action : selected ? null : event2 => {
this . handleChange . bind ( this ) ( option )
}
} ) ;
} )
} )
} ) ;
} ) ;
} ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . quickselectvalue ,
children : typeof this . props . renderValue == "function" ? this . props . renderValue ( this . props . value ) : this . props . value . label
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . quickselectarrow
} )
]
} )
]
} )
} ) ;
}
} ;
InternalComponents . LibraryComponents . RadioGroup = reactInitialized && class BDFDB _RadioGroup extends LibraryModules . React . Component {
handleChange ( value ) {
this . props . value = value . value ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( value , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . RadioGroup , Object . assign ( { } , this . props , {
onChange : this . handleChange . bind ( this )
} ) ) ;
}
} ;
InternalComponents . LibraryComponents . SearchBar = reactInitialized && class BDFDB _SearchBar extends LibraryModules . React . Component {
handleChange ( query ) {
this . props . query = query ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( query , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
handleClear ( ) {
this . props . query = "" ;
if ( this . props . changeOnClear && typeof this . props . onChange == "function" ) this . props . onChange ( "" , this ) ;
if ( typeof this . props . onClear == "function" ) this . props . onClear ( this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
let props = Object . assign ( { } , this . props , {
onChange : this . handleChange . bind ( this ) ,
onClear : this . handleClear . bind ( this )
} ) ;
if ( typeof props . query != "string" ) props . query = "" ;
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . SearchBar , props ) ;
}
} ;
2020-10-06 23:53:08 +02:00
let NativeSubSelectExport = ( BDFDB . ModuleUtils . find ( m => m == InternalComponents . NativeSubComponents . Select , false ) || { exports : { } } ) . exports ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . Select = reactInitialized && class BDFDB _Select extends LibraryModules . React . Component {
handleChange ( value ) {
this . props . value = value . value || value ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( value , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
2020-10-06 23:53:08 +02:00
let lightTheme = BDFDB . DiscordUtils . getTheme ( ) == BDFDB . disCN . themelight ;
2020-09-19 21:32:19 +02:00
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
className : BDFDB . disCN . selectwrapper ,
direction : InternalComponents . LibraryComponents . Flex . Direction . HORIZONTAL ,
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . Select , Object . assign ( { } , this . props , {
2020-10-06 23:53:08 +02:00
lightThemeColorOverrides : NativeSubSelectExport [ lightTheme ? "LIGHT_THEME_COLORS" : "DARK_THEME_COLORS" ] ,
darkThemeColorOverrides : NativeSubSelectExport [ lightTheme ? "LIGHT_THEME_COLORS" : "DARK_THEME_COLORS" ] ,
2020-09-19 21:32:19 +02:00
onChange : this . handleChange . bind ( this )
} ) )
} ) ;
}
} ;
InternalComponents . LibraryComponents . SettingsGuildList = reactInitialized && class BDFDB _SettingsGuildList extends LibraryModules . React . Component {
render ( ) {
this . props . disabled = BDFDB . ArrayUtils . is ( this . props . disabled ) ? this . props . disabled : [ ] ;
2020-10-08 17:35:36 +02:00
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
2020-09-19 21:32:19 +02:00
className : this . props . className ,
2020-10-08 17:35:36 +02:00
wrap : InternalComponents . LibraryComponents . Flex . Wrap . WRAP ,
2021-02-04 20:12:57 +01:00
children : [ this . props . includeDMs && { name : BDFDB . LanguageUtils . LanguageStrings . DIRECT _MESSAGES , acronym : "DMs" , id : BDFDB . DiscordConstants . ME , getIconURL : _ => { } } ] . concat ( LibraryModules . FolderStore . getFlattenedGuilds ( ) ) . filter ( n => n ) . map ( guild => BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
2020-09-19 21:32:19 +02:00
text : guild . name ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . guildClassName , BDFDB . disCN . settingsguild , this . props . disabled . includes ( guild . id ) && BDFDB . disCN . settingsguilddisabled ) ,
2020-10-08 17:35:36 +02:00
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . GuildComponents . Icon , {
2020-09-19 21:32:19 +02:00
guild : guild ,
2020-10-08 17:35:36 +02:00
size : this . props . size || InternalComponents . LibraryComponents . GuildComponents . Icon . Sizes . MEDIUM
2020-09-19 21:32:19 +02:00
} ) ,
onClick : e => {
let isDisabled = this . props . disabled . includes ( guild . id ) ;
if ( isDisabled ) BDFDB . ArrayUtils . remove ( this . props . disabled , guild . id , true ) ;
else this . props . disabled . push ( guild . id ) ;
if ( typeof this . props . onClick == "function" ) this . props . onClick ( this . props . disabled , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
} )
} ) )
} ) ;
}
} ;
InternalComponents . LibraryComponents . SettingsPanel = reactInitialized && class BDFDB _SettingsPanel extends LibraryModules . React . Component {
2020-11-22 18:33:22 +01:00
componentDidMount ( ) {
2020-11-22 18:48:06 +01:00
this . props . _instance = this ;
2020-11-22 18:34:05 +01:00
let node = BDFDB . ReactUtils . findDOMNode ( this ) ;
2020-11-22 18:48:06 +01:00
if ( node ) this . props . _node = node ;
2020-11-22 18:33:22 +01:00
}
2020-09-19 21:32:19 +02:00
componentWillUnmount ( ) {
2020-11-22 18:33:22 +01:00
if ( BDFDB . ObjectUtils . is ( this . props . addon ) && typeof this . props . addon . onSettingsClosed == "function" ) this . props . addon . onSettingsClosed ( ) ;
2020-09-19 21:32:19 +02:00
}
2020-11-23 17:52:58 +01:00
render ( ) {
2020-09-19 21:32:19 +02:00
let panelItems = [
2020-11-22 18:33:22 +01:00
typeof this . props . children == "function" ? ( _ => {
return this . props . children ( this . props . collapseStates ) ;
} ) ( ) : this . props . children
2020-09-19 21:32:19 +02:00
] . flat ( 10 ) . filter ( n => n ) ;
2020-11-23 20:19:58 +01:00
return BDFDB . ReactUtils . createElement ( "div" , {
key : this . props . addon && this . props . addon . name && ` ${ this . props . addon . name } -settingsPanel ` ,
id : this . props . addon && this . props . addon . name && ` ${ this . props . addon . name } -settings ` ,
className : BDFDB . disCN . settingspanel ,
children : panelItems
2020-09-19 21:32:19 +02:00
} ) ;
}
} ;
2020-12-15 10:26:20 +01:00
InternalComponents . LibraryComponents . SettingsPanelList = InternalComponents . LibraryComponents . SettingsPanelInner = reactInitialized && class BDFDB _SettingsPanelInner extends LibraryModules . React . Component {
2020-09-19 21:32:19 +02:00
render ( ) {
2020-12-15 10:26:20 +01:00
return this . props . children ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . settingspanellistwrapper , this . props . mini && BDFDB . disCN . settingspanellistwrappermini ) ,
2020-09-19 21:32:19 +02:00
children : [
2020-12-15 10:13:56 +01:00
this . props . dividerTop ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormDivider , {
className : this . props . mini ? BDFDB . disCN . marginbottom4 : BDFDB . disCN . marginbottom8
2020-09-19 21:32:19 +02:00
} ) : null ,
typeof this . props . title == "string" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormTitle , {
className : BDFDB . disCN . marginbottom4 ,
tag : InternalComponents . LibraryComponents . FormComponents . FormTitle . Tags . H3 ,
children : this . props . title
} ) : null ,
2020-12-15 10:26:20 +01:00
BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . settingspanellist ,
children : this . props . children
} ) ,
2020-12-15 10:13:56 +01:00
this . props . dividerBottom ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormDivider , {
className : this . props . mini ? BDFDB . disCN . margintop4 : BDFDB . disCN . margintop8
2020-09-19 21:32:19 +02:00
} ) : null
]
} ) : null ;
}
} ;
InternalComponents . LibraryComponents . SettingsItem = reactInitialized && class BDFDB _SettingsItem extends LibraryModules . React . Component {
handleChange ( value ) {
if ( typeof this . props . onChange == "function" ) this . props . onChange ( value , this ) ;
}
render ( ) {
if ( typeof this . props . type != "string" || ! [ "BUTTON" , "SELECT" , "SLIDER" , "SWITCH" , "TEXTINPUT" ] . includes ( this . props . type . toUpperCase ( ) ) ) return null ;
let childComponent = InternalComponents . LibraryComponents [ this . props . type ] ;
if ( ! childComponent ) return null ;
if ( this . props . mini && childComponent . Sizes ) this . props . size = childComponent . Sizes . MINI || childComponent . Sizes . MIN ;
2020-11-23 18:49:37 +01:00
let label = this . props . label ? ( this . props . tag ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormTitle , {
className : BDFDB . DOMUtils . formatClassName ( this . props . labelClassName , BDFDB . disCN . marginreset ) ,
tag : this . props . tag ,
children : this . props . label
} ) : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SettingsLabel , {
className : BDFDB . DOMUtils . formatClassName ( this . props . labelClassName ) ,
mini : this . props . mini ,
label : this . props . label
} ) ) : null ;
2020-10-15 18:15:42 +02:00
let margin = this . props . margin != null ? this . props . margin : ( this . props . mini ? 0 : 8 ) ;
2020-10-14 19:24:48 +02:00
return BDFDB . ReactUtils . createElement ( "div" , {
2020-10-15 18:15:42 +02:00
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . settingsrow , BDFDB . disCN . settingsrowcontainer , this . props . disabled && BDFDB . disCN . settingsrowdisabled , margin != null && ( BDFDB . DiscordClasses [ ` marginbottom ${ margin } ` ] && BDFDB . disCN [ ` marginbottom ${ margin } ` ] || margin == 0 && BDFDB . disCN . marginreset ) ) ,
2020-09-19 21:32:19 +02:00
id : this . props . id ,
children : [
2020-10-14 21:21:08 +02:00
this . props . dividerTop ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormDivider , {
2020-09-19 21:32:19 +02:00
className : this . props . mini ? BDFDB . disCN . marginbottom4 : BDFDB . disCN . marginbottom8
} ) : null ,
2020-10-15 18:15:42 +02:00
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . settingsrowlabel ,
2020-09-19 21:32:19 +02:00
children : [
2020-11-23 19:48:03 +01:00
label && ! this . props . basis ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
2020-11-23 18:49:37 +01:00
grow : 1 ,
shrink : 1 ,
wrap : true ,
children : label
2020-11-23 19:48:03 +01:00
} ) : label ,
2021-02-05 21:45:34 +01:00
this . props . labelChildren ,
2020-09-19 21:32:19 +02:00
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
2020-10-14 21:21:08 +02:00
className : BDFDB . disCNS . settingsrowcontrol + BDFDB . disCN . flexchild ,
2020-09-19 21:32:19 +02:00
grow : 0 ,
shrink : this . props . basis ? 0 : 1 ,
basis : this . props . basis ,
wrap : true ,
children : BDFDB . ReactUtils . createElement ( childComponent , BDFDB . ObjectUtils . exclude ( Object . assign ( BDFDB . ObjectUtils . exclude ( this . props , "className" , "id" , "type" ) , this . props . childProps , {
onChange : this . handleChange . bind ( this ) ,
onValueChange : this . handleChange . bind ( this )
2021-02-05 21:45:34 +01:00
} ) , "basis" , "margin" , "dividerBottom" , "dividerTop" , "label" , "labelClassName" , "labelChildren" , "tag" , "mini" , "note" , "childProps" ) )
2020-09-19 21:32:19 +02:00
} )
] . flat ( 10 ) . filter ( n => n )
} ) ,
typeof this . props . note == "string" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
2020-10-14 19:24:48 +02:00
className : BDFDB . disCN . settingsrownote ,
2020-09-19 21:32:19 +02:00
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormText , {
disabled : this . props . disabled ,
type : InternalComponents . LibraryComponents . FormComponents . FormText . Types . DESCRIPTION ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextScroller , { speed : 2 , children : this . props . note } )
} )
} ) : null ,
2020-10-14 21:21:08 +02:00
this . props . dividerBottom ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FormComponents . FormDivider , {
2020-09-19 21:32:19 +02:00
className : this . props . mini ? BDFDB . disCN . margintop4 : BDFDB . disCN . margintop8
} ) : null
]
} ) ;
}
} ;
InternalComponents . LibraryComponents . SettingsLabel = reactInitialized && class BDFDB _SettingsLabel extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextScroller , {
2020-10-14 19:24:48 +02:00
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . settingsrowtitle , this . props . mini ? BDFDB . disCN . settingsrowtitlemini : BDFDB . disCN . settingsrowtitledefault , BDFDB . disCN . cursordefault ) ,
2020-09-19 21:32:19 +02:00
speed : 2 ,
children : this . props . label
} ) ;
}
} ;
InternalComponents . LibraryComponents . SettingsList = reactInitialized && class BDFDB _SettingsList extends LibraryModules . React . Component {
componentDidMount ( ) {
2020-11-25 19:04:08 +01:00
this . checkList ( ) ;
}
componentDidUpdate ( ) {
this . checkList ( ) ;
}
checkList ( ) {
2020-09-19 21:32:19 +02:00
let list = BDFDB . ReactUtils . findDOMNode ( this ) ;
2020-11-25 19:04:08 +01:00
if ( list && ! this . props . configWidth ) {
2020-09-19 21:32:19 +02:00
let headers = Array . from ( list . querySelectorAll ( BDFDB . dotCN . settingstableheader ) ) ;
headers . shift ( ) ;
2020-11-25 19:04:08 +01:00
if ( BDFDB . DOMUtils . getRects ( headers [ 0 ] ) . width == 0 ) BDFDB . TimeUtils . timeout ( _ => { this . resizeList ( headers ) ; } ) ;
else this . resizeList ( headers ) ;
2020-09-19 21:32:19 +02:00
}
}
2020-11-25 19:04:08 +01:00
resizeList ( headers ) {
let configWidth = 0 , biggestWidth = 0 ;
if ( ! configWidth ) {
2020-09-19 21:32:19 +02:00
for ( let header of headers ) {
header . style = "" ;
let width = BDFDB . DOMUtils . getRects ( header ) . width ;
2020-11-25 19:04:08 +01:00
configWidth = width > configWidth ? width : configWidth ;
2020-09-19 21:32:19 +02:00
}
2020-11-25 19:04:08 +01:00
configWidth += 4 ;
biggestWidth = configWidth ;
2020-09-19 21:32:19 +02:00
}
2020-11-25 19:04:08 +01:00
if ( headers . length * configWidth > 300 ) {
2020-09-19 21:32:19 +02:00
this . props . vertical = true ;
2020-11-25 19:04:08 +01:00
configWidth = parseInt ( 290 / headers . length ) ;
2020-09-19 21:32:19 +02:00
}
2020-11-25 19:04:08 +01:00
else if ( configWidth < 36 ) {
configWidth = 36 ;
biggestWidth = configWidth ;
2020-09-19 21:32:19 +02:00
}
2020-11-25 19:04:08 +01:00
this . props . configWidth = configWidth ;
2020-09-19 21:32:19 +02:00
this . props . biggestWidth = biggestWidth ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
2020-11-25 19:04:08 +01:00
renderHeaderOption ( props ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( props . className , BDFDB . disCN . colorbase , BDFDB . disCN . size10 , props . clickable && BDFDB . disCN . cursorpointer ) ,
onClick : _ => { if ( typeof this . props . onHeaderClick == "function" ) this . props . onHeaderClick ( props . label , this ) ; } ,
onContextMenu : _ => { if ( typeof this . props . onHeaderContextMenu == "function" ) this . props . onHeaderContextMenu ( props . label , this ) ; } ,
children : BDFDB . ReactUtils . createElement ( "span" , {
children : props . label
} )
} ) ;
}
renderItem ( props ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Card , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
className : BDFDB . DOMUtils . formatClassName ( [ this . props . cardClassName , props . className ] . filter ( n => n ) . join ( " " ) . indexOf ( BDFDB . disCN . card ) == - 1 && BDFDB . disCN . cardprimaryoutline , BDFDB . disCN . settingstablecard , this . props . cardClassName , props . className ) ,
cardId : props . key ,
2020-09-19 21:32:19 +02:00
backdrop : false ,
2020-11-24 10:53:53 +01:00
horizontal : true ,
2020-11-25 19:04:08 +01:00
style : Object . assign ( { } , this . props . cardStyle , props . style ) ,
2020-09-19 21:32:19 +02:00
children : [
2020-11-25 19:04:08 +01:00
BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . settingstablecardlabel ,
2020-11-25 19:04:08 +01:00
children : this . props . renderLabel ( props )
2020-09-19 21:32:19 +02:00
} ) ,
2020-11-25 19:04:08 +01:00
BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . settingstablecardconfigs ,
2020-11-25 19:04:08 +01:00
style : {
width : props . wrapperWidth || null ,
minWidth : props . wrapperWidth || null ,
maxWidth : props . wrapperWidth || null
} ,
children : this . props . settings . map ( setting => BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . checkboxcontainer ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Checkbox , {
2020-11-25 19:04:08 +01:00
disabled : props . disabled ,
cardId : props . key ,
2020-09-19 21:32:19 +02:00
settingId : setting ,
shape : InternalComponents . LibraryComponents . Checkbox . Shapes . ROUND ,
type : InternalComponents . LibraryComponents . Checkbox . Types . INVERTED ,
2020-12-25 16:28:49 +01:00
color : this . props . checkboxColor ,
2021-01-02 12:51:18 +01:00
getColor : this . props . getCheckboxColor ,
2020-11-25 19:04:08 +01:00
value : props [ setting ] ,
2021-01-02 12:51:18 +01:00
getValue : this . props . getCheckboxValue ,
2020-09-19 21:32:19 +02:00
onChange : this . props . onCheckboxChange
} )
} ) ) . flat ( 10 ) . filter ( n => n )
} )
]
2021-01-15 20:30:31 +01:00
} ) , "title" , "data" , "settings" , "renderLabel" , "cardClassName" , "cardStyle" , "checkboxColor" , "getCheckboxColor" , "getCheckboxValue" , "onCheckboxChange" , "configWidth" , "biggestWidth" , "pagination" ) ) ;
2020-11-25 19:04:08 +01:00
}
render ( ) {
this . props . settings = BDFDB . ArrayUtils . is ( this . props . settings ) ? this . props . settings : [ ] ;
this . props . renderLabel = typeof this . props . renderLabel == "function" ? this . props . renderLabel : data => data . label ;
this . props . data = ( BDFDB . ArrayUtils . is ( this . props . data ) ? this . props . data : [ { } ] ) . filter ( n => n ) ;
let wrapperWidth = this . props . configWidth && this . props . configWidth * this . props . settings . length ;
let isHeaderClickable = typeof this . props . onHeaderClick == "function" || typeof this . props . onHeaderContextMenu == "function" ;
let usePagination = BDFDB . ObjectUtils . is ( this . props . pagination ) ;
let header = BDFDB . ReactUtils . createElement ( "div" , {
2020-09-19 21:32:19 +02:00
className : BDFDB . disCN . settingstableheaders ,
style : this . props . vertical && this . props . biggestWidth ? {
marginTop : this . props . biggestWidth - 15 || 0
} : { } ,
2020-11-25 19:04:08 +01:00
children : [
this . renderHeaderOption ( {
className : BDFDB . disCN . settingstableheadername ,
clickable : this . props . title && isHeaderClickable ,
label : this . props . title || ""
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . settingstableheaderoptions ,
style : {
width : wrapperWidth || null ,
minWidth : wrapperWidth || null ,
maxWidth : wrapperWidth || null
} ,
children : this . props . settings . map ( setting => this . renderHeaderOption ( {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . settingstableheaderoption , this . props . vertical && BDFDB . disCN . settingstableheadervertical ) ,
clickable : isHeaderClickable ,
label : setting
} ) )
2020-09-19 21:32:19 +02:00
} )
2020-11-25 19:04:08 +01:00
]
2020-09-19 21:32:19 +02:00
} ) ;
return ! this . props . data . length ? null : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . settingstablelist , this . props . className ) ,
children : [
! usePagination && header ,
2020-11-25 19:04:08 +01:00
! usePagination ? this . props . data . map ( data => this . renderItem ( Object . assign ( { } , data , { wrapperWidth } ) ) ) : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PaginatedList , Object . assign ( { } , this . props . pagination , {
2020-09-19 21:32:19 +02:00
header : header ,
items : this . props . data ,
2020-11-25 19:04:08 +01:00
renderItem : data => this . renderItem ( Object . assign ( { } , data , { wrapperWidth } ) ) ,
2020-09-19 21:32:19 +02:00
onJump : ( offset , instance ) => {
this . props . pagination . offset = offset ;
if ( typeof this . props . pagination . onJump == "function" ) this . props . pagination . onJump ( offset , this , instance ) ;
}
} ) )
] . filter ( n => n )
} ) ;
}
} ;
InternalComponents . LibraryComponents . SettingsSaveItem = reactInitialized && class BDFDB _SettingsSaveItem extends LibraryModules . React . Component {
saveSettings ( value ) {
if ( ! BDFDB . ArrayUtils . is ( this . props . keys ) || ! BDFDB . ObjectUtils . is ( this . props . plugin ) ) return ;
let keys = this . props . keys . filter ( n => n ) ;
let option = keys . shift ( ) ;
if ( BDFDB . ObjectUtils . is ( this . props . plugin ) && option ) {
let data = BDFDB . DataUtils . load ( this . props . plugin , option ) ;
let newData = "" ;
for ( let key of keys ) newData += ` {" ${ key } ": ` ;
value = value != null && value . value != null ? value . value : value ;
let isString = typeof value == "string" ;
let marker = isString ? ` " ` : ` ` ;
newData += ( marker + ( isString ? value . replace ( /\\/g , "\\\\" ) : value ) + marker ) + "}" . repeat ( keys . length ) ;
newData = JSON . parse ( newData ) ;
BDFDB . DataUtils . save ( BDFDB . ObjectUtils . is ( newData ) ? BDFDB . ObjectUtils . deepAssign ( { } , data , newData ) : newData , this . props . plugin , option ) ;
this . props . plugin . SettingsUpdated = true ;
}
if ( typeof this . props . onChange == "function" ) this . props . onChange ( value , this ) ;
}
render ( ) {
if ( typeof this . props . type != "string" || ! [ "SELECT" , "SLIDER" , "SWITCH" , "TEXTINPUT" ] . includes ( this . props . type . toUpperCase ( ) ) ) return null ;
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SettingsItem , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
onChange : this . saveSettings . bind ( this )
} ) , "keys" , "key" , "plugin" ) ) ;
}
} ;
InternalComponents . LibraryComponents . SidebarList = reactInitialized && class BDFDB _SidebarList extends LibraryModules . React . Component {
handleItemSelect ( item ) {
this . props . selectedItem = item ;
if ( typeof this . props . onItemSelect == "function" ) this . props . onItemSelect ( item , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
let items = ( BDFDB . ArrayUtils . is ( this . props . items ) ? this . props . items : [ { } ] ) . filter ( n => n ) ;
let selectedItem = this . props . selectedItem || ( items [ 0 ] || { } ) . value ;
let selectedElements = ( items . find ( n => n . value == selectedItem ) || { } ) . elements ;
let renderElement = typeof this . props . renderElement == "function" ? this . props . renderElement : ( _ => { } ) ;
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( this . props . className , BDFDB . disCN . sidebarlist ) ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Scrollers . Thin , {
className : BDFDB . DOMUtils . formatClassName ( this . props . sidebarClassName , BDFDB . disCN . sidebar ) ,
fade : true ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TabBar , {
itemClassName : this . props . itemClassName ,
type : InternalComponents . LibraryComponents . TabBar . Types . SIDE ,
items : items ,
selectedItem : selectedItem ,
renderItem : this . props . renderItem ,
onItemSelect : this . handleItemSelect . bind ( this )
} )
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Scrollers . Thin , {
className : BDFDB . DOMUtils . formatClassName ( this . props . contentClassName , BDFDB . disCN . sidebarcontent ) ,
fade : true ,
children : [ selectedElements ] . flat ( 10 ) . filter ( n => n ) . map ( data => renderElement ( data ) )
} )
]
} ) ;
}
} ;
InternalComponents . LibraryComponents . Slider = reactInitialized && class BDFDB _Slider extends LibraryModules . React . Component {
handleMarkerRender ( marker ) {
let newMarker = BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , this . props . edges , marker ) ;
if ( typeof this . props . digits == "number" ) newMarker = Math . round ( newMarker * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ;
return newMarker ;
}
handleValueChange ( value ) {
let newValue = BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , this . props . edges , value ) ;
if ( typeof this . props . digits == "number" ) newValue = Math . round ( newValue * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ;
this . props . defaultValue = this . props . value = newValue ;
if ( typeof this . props . onValueChange == "function" ) this . props . onValueChange ( newValue , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
handleValueRender ( value ) {
let newValue = BDFDB . NumberUtils . mapRange ( [ 0 , 100 ] , this . props . edges , value ) ;
if ( typeof this . props . digits == "number" ) newValue = Math . round ( newValue * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ;
if ( typeof this . props . onValueRender == "function" ) {
let tempReturn = this . props . onValueRender ( newValue , this ) ;
if ( tempReturn != undefined ) newValue = tempReturn ;
}
return newValue ;
}
render ( ) {
let value = this . props . value || this . props . defaultValue || 0 ;
if ( ! BDFDB . ArrayUtils . is ( this . props . edges ) || this . props . edges . length != 2 ) this . props . edges = [ this . props . min || this . props . minValue || 0 , this . props . max || this . props . maxValue || 100 ] ;
this . props . minValue = 0 ;
this . props . maxValue = 100 ;
let defaultValue = BDFDB . NumberUtils . mapRange ( this . props . edges , [ 0 , 100 ] , value ) ;
if ( typeof this . props . digits == "number" ) defaultValue = Math . round ( defaultValue * Math . pow ( 10 , this . props . digits ) ) / Math . pow ( 10 , this . props . digits ) ;
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . Slider , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
initialValue : defaultValue ,
markers : typeof this . props . markerAmount == "number" ? Array . from ( Array ( this . props . markerAmount ) . keys ( ) ) . map ( ( _ , i ) => i * ( this . props . maxValue - this . props . minValue ) / 10 ) : undefined ,
onMarkerRender : this . handleMarkerRender . bind ( this ) ,
onValueChange : this . handleValueChange . bind ( this ) ,
onValueRender : this . handleValueRender . bind ( this )
} ) , "digits" , "edges" , "max" , "min" , "markerAmount" ) ) ;
}
} ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . Slider , { hideBubble : false } ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . SvgIcon = reactInitialized && class BDFDB _Icon extends LibraryModules . React . Component {
render ( ) {
if ( BDFDB . ObjectUtils . is ( this . props . name ) ) {
2020-11-20 10:17:09 +01:00
let calcClassName = [ ] ;
if ( BDFDB . ObjectUtils . is ( this . props . name . getClassName ) ) for ( let path in this . props . name . getClassName ) {
if ( ! path || BDFDB . ObjectUtils . get ( this , path ) ) calcClassName . push ( BDFDB . disCN [ this . props . name . getClassName [ path ] ] ) ;
}
if ( calcClassName . length || this . props . className ) this . props . nativeClass = true ;
2020-09-19 21:32:19 +02:00
this . props . iconSVG = this . props . name . icon ;
let props = Object . assign ( {
width : 24 ,
height : 24 ,
color : "currentColor"
} , this . props . name . defaultProps , this . props , {
2020-11-20 10:17:09 +01:00
className : BDFDB . DOMUtils . formatClassName ( calcClassName , this . props . className )
2020-09-19 21:32:19 +02:00
} ) ;
for ( let key in props ) this . props . iconSVG = this . props . iconSVG . replace ( new RegExp ( ` %% ${ key } ` , "g" ) , props [ key ] ) ;
}
if ( this . props . iconSVG ) {
let icon = BDFDB . ReactUtils . elementToReact ( BDFDB . DOMUtils . create ( this . props . iconSVG ) ) ;
if ( BDFDB . ReactUtils . isValidElement ( icon ) ) {
icon . props . className = BDFDB . DOMUtils . formatClassName ( ! this . props . nativeClass && BDFDB . disCN . svgicon , icon . props . className , this . props . className ) ;
icon . props . style = Object . assign ( { } , icon . props . style , this . props . style ) ;
icon . props = Object . assign ( { } , BDFDB . ObjectUtils . extract ( this . props , "onClick" , "onContextMenu" , "onMouseDown" , "onMouseUp" , "onMouseEnter" , "onMouseLeave" ) , icon . props ) ;
return icon ;
}
}
return null ;
}
} ;
2020-11-20 10:17:09 +01:00
InternalComponents . LibraryComponents . SvgIcon . Names = InternalData . SvgIcons || { } ;
2020-09-19 21:32:19 +02:00
2020-10-14 19:24:48 +02:00
const SwitchIconPaths = {
a : {
TOP : "M5.13231 6.72963L6.7233 5.13864L14.855 13.2704L13.264 14.8614L5.13231 6.72963Z" ,
BOTTOM : "M13.2704 5.13864L14.8614 6.72963L6.72963 14.8614L5.13864 13.2704L13.2704 5.13864Z"
} ,
b : {
TOP : "M6.56666 11.0013L6.56666 8.96683L13.5667 8.96683L13.5667 11.0013L6.56666 11.0013Z" ,
BOTTOM : "M13.5582 8.96683L13.5582 11.0013L6.56192 11.0013L6.56192 8.96683L13.5582 8.96683Z"
} ,
c : {
TOP : "M7.89561 14.8538L6.30462 13.2629L14.3099 5.25755L15.9009 6.84854L7.89561 14.8538Z" ,
BOTTOM : "M4.08643 11.0903L5.67742 9.49929L9.4485 13.2704L7.85751 14.8614L4.08643 11.0903Z"
}
} ;
const SwitchInner = function ( props ) {
let reducedMotion = BDFDB . ReactUtils . useContext ( LibraryModules . PreferencesContext . AccessibilityPreferencesContext ) . reducedMotion ;
let ref = BDFDB . ReactUtils . useRef ( null ) ;
let state = BDFDB . ReactUtils . useState ( false ) ;
let animation = InternalComponents . LibraryComponents . Animations . useSpring ( {
config : {
mass : 1 ,
tension : 250
} ,
opacity : props . disabled ? . 3 : 1 ,
state : state [ 0 ] ? ( props . value ? . 7 : . 3 ) : ( props . value ? 1 : 0 )
} ) ;
let fill = animation . state . to ( {
output : [ props . uncheckedColor , props . checkedColor ]
} ) ;
2020-10-15 18:15:42 +02:00
let mini = props . size == InternalComponents . LibraryComponents . Switch . Sizes . MINI ;
2020-10-14 19:24:48 +02:00
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . div , {
2020-10-15 18:15:42 +02:00
className : BDFDB . DOMUtils . formatClassName ( props . className , BDFDB . disCN . switch , mini && BDFDB . disCN . switchmini ) ,
2020-10-14 19:24:48 +02:00
onMouseDown : _ => {
return ! props . disabled && state [ 1 ] ( true ) ;
} ,
onMouseUp : _ => {
return state [ 1 ] ( false ) ;
} ,
onMouseLeave : _ => {
return state [ 1 ] ( false ) ;
} ,
style : {
opacity : animation . opacity ,
backgroundColor : animation . state . to ( {
output : [ props . uncheckedColor , props . checkedColor ]
} )
} ,
tabIndex : - 1 ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . svg , {
className : BDFDB . disCN . switchslider ,
viewBox : "0 0 28 20" ,
preserveAspectRatio : "xMinYMid meet" ,
style : {
left : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
2020-10-15 18:15:42 +02:00
output : mini ? [ - 1 , 2 , 6 , 9 ] : [ - 3 , 1 , 8 , 12 ]
2020-10-14 19:24:48 +02:00
} )
} ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . rect , {
fill : "white" ,
x : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
output : [ 4 , 0 , 0 , 4 ]
} ) ,
y : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
output : [ 0 , 1 , 1 , 0 ]
} ) ,
height : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
output : [ 20 , 18 , 18 , 20 ]
} ) ,
width : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
output : [ 20 , 28 , 28 , 20 ]
} ) ,
rx : "10"
} ) ,
BDFDB . ReactUtils . createElement ( "svg" , {
viewBox : "0 0 20 20" ,
fill : "none" ,
children : [
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . path , {
fill : fill ,
d : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
output : reducedMotion . enabled ? [ SwitchIconPaths . a . TOP , SwitchIconPaths . a . TOP , SwitchIconPaths . c . TOP , SwitchIconPaths . c . TOP ] : [ SwitchIconPaths . a . TOP , SwitchIconPaths . b . TOP , SwitchIconPaths . b . TOP , SwitchIconPaths . c . TOP ]
} )
} ) ,
BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . path , {
fill : fill ,
d : animation . state . to ( {
range : [ 0 , . 3 , . 7 , 1 ] ,
output : reducedMotion . enabled ? [ SwitchIconPaths . a . BOTTOM , SwitchIconPaths . a . BOTTOM , SwitchIconPaths . c . BOTTOM , SwitchIconPaths . c . BOTTOM ] : [ SwitchIconPaths . a . BOTTOM , SwitchIconPaths . b . BOTTOM , SwitchIconPaths . b . BOTTOM , SwitchIconPaths . c . BOTTOM ]
} )
} )
]
} )
]
} ) ,
2020-12-19 19:08:02 +01:00
BDFDB . ReactUtils . createElement ( "input" , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , props , {
2020-10-14 19:24:48 +02:00
id : props . id ,
type : "checkbox" ,
ref : ref ,
className : BDFDB . DOMUtils . formatClassName ( props . inputClassName , BDFDB . disCN . switchinner ) ,
tabIndex : props . disabled ? - 1 : 0 ,
onKeyDown : e => {
if ( ! props . disabled && ! e . repeat && ( e . key == " " || e . key == "Enter" ) ) state [ 1 ] ( true ) ;
} ,
onKeyUp : e => {
if ( ! props . disabled && ! e . repeat ) {
state [ 1 ] ( false ) ;
if ( e . key == "Enter" && ref . current ) ref . current . click ( ) ;
}
} ,
onChange : e => {
state [ 1 ] ( false ) ;
if ( typeof props . onChange == "function" ) props . onChange ( e . currentTarget . checked , e ) ;
} ,
checked : props . value ,
disabled : props . disabled
2020-12-19 19:40:03 +01:00
} ) , "uncheckedColor" , "checkedColor" , "size" , "value" ) )
2020-10-14 19:24:48 +02:00
]
} ) ;
} ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . Switch = reactInitialized && class BDFDB _Switch extends LibraryModules . React . Component {
handleChange ( ) {
this . props . value = ! this . props . value ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( this . props . value , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
2020-10-14 19:24:48 +02:00
return BDFDB . ReactUtils . createElement ( SwitchInner , Object . assign ( { } , this . props , {
onChange : this . handleChange . bind ( this )
} ) ) ;
2020-09-19 21:32:19 +02:00
}
} ;
2020-10-14 21:21:08 +02:00
InternalComponents . LibraryComponents . Switch . Sizes = {
DEFAULT : "default" ,
MINI : "mini" ,
} ;
2020-10-14 19:24:48 +02:00
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . Switch , {
2020-10-14 21:21:08 +02:00
size : InternalComponents . LibraryComponents . Switch . Sizes . DEFAULT ,
2020-10-14 19:24:48 +02:00
uncheckedColor : BDFDB . DiscordConstants . Colors . PRIMARY _DARK _400 ,
checkedColor : BDFDB . DiscordConstants . Colors . BRAND
} ) ;
2020-09-19 21:32:19 +02:00
InternalComponents . LibraryComponents . TabBar = reactInitialized && class BDFDB _TabBar extends LibraryModules . React . Component {
handleItemSelect ( item ) {
this . props . selectedItem = item ;
if ( typeof this . props . onItemSelect == "function" ) this . props . onItemSelect ( item , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
render ( ) {
let items = ( BDFDB . ArrayUtils . is ( this . props . items ) ? this . props . items : [ { } ] ) . filter ( n => n ) ;
let selectedItem = this . props . selectedItem || ( items [ 0 ] || { } ) . value ;
let renderItem = typeof this . props . renderItem == "function" ? this . props . renderItem : ( data => data . label || data . value ) ;
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . TabBar , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
selectedItem : selectedItem ,
onItemSelect : this . handleItemSelect . bind ( this ) ,
children : items . map ( data => BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TabBar . Item , {
className : BDFDB . DOMUtils . formatClassName ( this . props . itemClassName , selectedItem == data . value && this . props . itemSelectedClassName ) ,
itemType : this . props . type ,
id : data . value ,
children : renderItem ( data ) ,
"aria-label" : data . label || data . value
} ) )
} ) , "itemClassName" , "items" , "renderItem" ) ) ;
}
} ;
InternalComponents . LibraryComponents . Table = reactInitialized && class BDFDB _Table extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . Table , Object . assign ( { } , this . props , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . table , this . props . className ) ,
headerCellClassName : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tableheadercell , this . props . headerCellClassName ) ,
sortedHeaderCellClassName : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tableheadercellsorted , this . props . sortedHeaderCellClassName ) ,
bodyCellClassName : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . tablebodycell , this . props . bodyCellClassName ) ,
onSort : ( sortKey , sortDirection ) => {
this . props . sortDirection = this . props . sortKey != sortKey && sortDirection == InternalComponents . LibraryComponents . Table . SortDirection . ASCENDING && this . props . columns . filter ( n => n . key == sortKey ) [ 0 ] . reverse ? InternalComponents . LibraryComponents . Table . SortDirection . DESCENDING : sortDirection ;
this . props . sortKey = sortKey ;
this . props . data = BDFDB . ArrayUtils . keySort ( this . props . data , this . props . sortKey ) ;
if ( this . props . sortDirection == InternalComponents . LibraryComponents . Table . SortDirection . DESCENDING ) this . props . data . reverse ( ) ;
if ( typeof this . props . onSort == "function" ) this . props . onSort ( this . props . sortKey , this . props . sortDirection ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
} ) ) ;
}
} ;
InternalComponents . LibraryComponents . TextArea = reactInitialized && class BDFDB _TextArea extends LibraryModules . React . Component {
handleChange ( e ) {
this . props . value = e ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( e , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
handleBlur ( e ) { if ( typeof this . props . onBlur == "function" ) this . props . onBlur ( e , this ) ; }
handleFocus ( e ) { if ( typeof this . props . onFocus == "function" ) this . props . onFocus ( e , this ) ; }
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . NativeSubComponents . TextArea , Object . assign ( { } , this . props , {
onChange : this . handleChange . bind ( this ) ,
onBlur : this . handleBlur . bind ( this ) ,
onFocus : this . handleFocus . bind ( this )
} ) ) ;
}
} ;
InternalComponents . LibraryComponents . TextGradientElement = reactInitialized && class BDFDB _TextGradientElement extends LibraryModules . React . Component {
render ( ) {
if ( this . props . gradient && this . props . children ) return BDFDB . ReactUtils . createElement ( "span" , {
children : this . props . children ,
ref : instance => {
let ele = BDFDB . ReactUtils . findDOMNode ( instance ) ;
if ( ele ) {
ele . style . setProperty ( "background-image" , this . props . gradient , "important" ) ;
ele . style . setProperty ( "color" , "transparent" , "important" ) ;
ele . style . setProperty ( "-webkit-background-clip" , "text" , "important" ) ;
}
}
} ) ;
return this . props . children || null ;
}
} ;
InternalComponents . LibraryComponents . TextInput = reactInitialized && class BDFDB _TextInput extends LibraryModules . React . Component {
handleChange ( e ) {
let value = e = BDFDB . ObjectUtils . is ( e ) ? e . currentTarget . value : e ;
this . props . value = this . props . valuePrefix && ! value . startsWith ( this . props . valuePrefix ) ? ( this . props . valuePrefix + value ) : value ;
if ( typeof this . props . onChange == "function" ) this . props . onChange ( this . props . value , this ) ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
}
handleInput ( e ) { if ( typeof this . props . onInput == "function" ) this . props . onInput ( BDFDB . ObjectUtils . is ( e ) ? e . currentTarget . value : e , this ) ; }
handleKeyDown ( e ) { if ( typeof this . props . onKeyDown == "function" ) this . props . onKeyDown ( e , this ) ; }
handleBlur ( e ) { if ( typeof this . props . onBlur == "function" ) this . props . onBlur ( e , this ) ; }
handleFocus ( e ) { if ( typeof this . props . onFocus == "function" ) this . props . onFocus ( e , this ) ; }
handleMouseEnter ( e ) { if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ; }
handleMouseLeave ( e ) { if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ; }
handleNumberButton ( ins , value ) {
BDFDB . TimeUtils . clear ( ins . pressedTimeout ) ;
ins . pressedTimeout = BDFDB . TimeUtils . timeout ( _ => {
delete this . props . focused ;
BDFDB . ReactUtils . forceUpdate ( this ) ;
} , 1000 ) ;
this . props . focused = true ;
this . handleChange . bind ( this ) ( value ) ;
this . handleInput . bind ( this ) ( value ) ;
}
componentDidMount ( ) {
if ( this . props . type == "file" ) {
let navigatorInstance = BDFDB . ReactUtils . findOwner ( this , { name : "BDFDB_FileButton" } ) ;
if ( navigatorInstance ) navigatorInstance . refInput = this ;
}
let input = BDFDB . ReactUtils . findDOMNode ( this ) ;
if ( ! input ) return ;
input = input . querySelector ( "input" ) || input ;
if ( input && ! input . patched ) {
input . addEventListener ( "keydown" , e => {
this . handleKeyDown . bind ( this ) ( e ) ;
e . stopImmediatePropagation ( ) ;
} ) ;
input . patched = true ;
}
}
render ( ) {
let inputChildren = [
BDFDB . ReactUtils . createElement ( "input" , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
className : BDFDB . DOMUtils . formatClassName ( this . props . size && InternalComponents . LibraryComponents . TextInput . Sizes [ this . props . size . toUpperCase ( ) ] && BDFDB . disCN [ "input" + this . props . size . toLowerCase ( ) ] || BDFDB . disCN . inputdefault , this . props . inputClassName , this . props . focused && BDFDB . disCN . inputfocused , this . props . error || this . props . errorMessage ? BDFDB . disCN . inputerror : ( this . props . success && BDFDB . disCN . inputsuccess ) , this . props . disabled && BDFDB . disCN . inputdisabled , this . props . editable && BDFDB . disCN . inputeditable ) ,
type : this . props . type == "color" || this . props . type == "file" ? "text" : this . props . type ,
onChange : this . handleChange . bind ( this ) ,
onInput : this . handleInput . bind ( this ) ,
onKeyDown : this . handleKeyDown . bind ( this ) ,
onBlur : this . handleBlur . bind ( this ) ,
onFocus : this . handleFocus . bind ( this ) ,
onMouseEnter : this . handleMouseEnter . bind ( this ) ,
onMouseLeave : this . handleMouseLeave . bind ( this ) ,
maxLength : this . props . type == "file" ? false : this . props . maxLength ,
2020-10-31 11:12:54 +01:00
style : this . props . width ? { width : ` ${ this . props . width } px ` } : { } ,
2020-09-19 21:32:19 +02:00
ref : this . props . inputRef
} ) , "errorMessage" , "focused" , "error" , "success" , "inputClassName" , "inputChildren" , "valuePrefix" , "inputPrefix" , "size" , "editable" , "inputRef" , "style" , "mode" , "noAlpha" , "filter" , "useFilePath" , "searchFolders" ) ) ,
this . props . inputChildren ,
this . props . type == "color" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
wrap : true ,
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . ColorSwatches , {
colors : [ ] ,
color : this . props . value && this . props . mode == "comp" ? BDFDB . ColorUtils . convert ( this . props . value . split ( "," ) , "RGB" ) : this . props . value ,
onColorChange : color => {
this . handleChange ( ! color ? "" : ( this . props . mode == "comp" ? BDFDB . ColorUtils . convert ( color , "RGBCOMP" ) . slice ( 0 , 3 ) . join ( "," ) : ( this . props . noAlpha ? BDFDB . ColorUtils . convert ( color , "RGB" ) : color ) ) ) ;
} ,
2021-01-29 20:57:25 +01:00
ref : this . props . controlsRef ,
2020-11-19 16:51:14 +01:00
pickerConfig : { gradient : false , alpha : this . props . mode != "comp" && ! this . props . noAlpha }
2020-09-19 21:32:19 +02:00
} )
} ) : null ,
this . props . type == "file" ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . FileButton , {
filter : this . props . filter ,
mode : this . props . mode ,
useFilePath : this . props . useFilePath ,
2021-01-29 20:57:25 +01:00
searchFolders : this . props . searchFolders ,
ref : this . props . controlsRef
2020-09-19 21:32:19 +02:00
} ) : null
] . flat ( 10 ) . filter ( n => n ) ;
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . inputwrapper , this . props . type == "number" && ( this . props . size && InternalComponents . LibraryComponents . TextInput . Sizes [ this . props . size . toUpperCase ( ) ] && BDFDB . disCN [ "inputnumberwrapper" + this . props . size . toLowerCase ( ) ] || BDFDB . disCN . inputnumberwrapperdefault ) , this . props . className ) ,
style : this . props . style ,
children : [
this . props . inputPrefix ? BDFDB . ReactUtils . createElement ( "span" , {
className : BDFDB . disCN . inputprefix
} ) : null ,
this . props . type == "number" ? BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . inputnumberbuttons ,
children : [
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . inputnumberbuttonup ,
onClick : e => {
let min = parseInt ( this . props . min ) ;
let max = parseInt ( this . props . max ) ;
2020-11-02 23:15:43 +01:00
let newV = parseInt ( this . props . value ) + 1 || min || 0 ;
if ( isNaN ( max ) || ! isNaN ( max ) && newV <= max ) this . handleNumberButton . bind ( this ) ( e . _targetInst , isNaN ( min ) || ! isNaN ( min ) && newV >= min ? newV : min ) ;
2020-09-19 21:32:19 +02:00
}
} ) ,
BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . inputnumberbuttondown ,
onClick : e => {
let min = parseInt ( this . props . min ) ;
let max = parseInt ( this . props . max ) ;
2020-11-02 23:15:43 +01:00
let newV = parseInt ( this . props . value ) - 1 || min || 0 ;
if ( isNaN ( min ) || ! isNaN ( min ) && newV >= min ) this . handleNumberButton . bind ( this ) ( e . _targetInst , isNaN ( max ) || ! isNaN ( max ) && newV <= max ? newV : max ) ;
2020-09-19 21:32:19 +02:00
}
} )
]
} ) : null ,
inputChildren . length == 1 ? inputChildren [ 0 ] : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex , {
align : InternalComponents . LibraryComponents . Flex . Align . CENTER ,
2021-01-29 20:57:25 +01:00
children : inputChildren . map ( ( child , i ) => i != 0 ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Flex . Child , {
shrink : 0 ,
children : child
} ) : child )
2020-09-19 21:32:19 +02:00
} ) ,
this . props . errorMessage ? BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TextElement , {
className : BDFDB . disCN . carderror ,
size : InternalComponents . LibraryComponents . TextElement . Sizes . SIZE _12 ,
color : InternalComponents . LibraryComponents . TextElement . Colors . STATUS _RED ,
children : this . props . errorMessage
} ) : null
] . filter ( n => n )
} ) ;
}
} ;
InternalComponents . LibraryComponents . TextScroller = reactInitialized && class BDFDB _TextScroller extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . textscroller , this . props . className ) ,
style : Object . assign ( { } , this . props . style , {
position : "relative" ,
display : "block" ,
overflow : "hidden"
} ) ,
ref : instance => {
let ele = BDFDB . ReactUtils . findDOMNode ( instance ) ;
if ( ele && ele . parentElement ) {
let maxWidth = BDFDB . DOMUtils . getInnerWidth ( ele . parentElement ) ;
if ( maxWidth > 50 ) ele . style . setProperty ( "max-width" , ` ${ maxWidth } px ` ) ;
BDFDB . TimeUtils . timeout ( _ => {
2020-10-15 13:17:55 +02:00
if ( document . contains ( ele . parentElement ) ) BDFDB . ReactUtils . forceUpdate ( this ) ;
2020-09-19 21:32:19 +02:00
} , 3000 ) ;
let Animation = new LibraryModules . AnimationUtils . Value ( 0 ) ;
Animation
2020-11-19 16:51:14 +01:00
. interpolate ( { inputRange : [ 0 , 1 ] , outputRange : [ 0 , ( BDFDB . DOMUtils . getRects ( ele . firstElementChild ) . width - BDFDB . DOMUtils . getRects ( ele ) . width ) * - 1 ] } )
2020-09-19 21:32:19 +02:00
. addListener ( v => { ele . firstElementChild . style . setProperty ( "left" , ` ${ v . value } px ` , "important" ) ; } ) ;
this . scroll = p => {
let w = p + parseFloat ( ele . firstElementChild . style . getPropertyValue ( "left" ) ) / ( BDFDB . DOMUtils . getRects ( ele . firstElementChild ) . width - BDFDB . DOMUtils . getRects ( ele ) . width ) ;
w = isNaN ( w ) || ! isFinite ( w ) ? p : w ;
w *= BDFDB . DOMUtils . getRects ( ele . firstElementChild ) . width / ( BDFDB . DOMUtils . getRects ( ele ) . width * 2 ) ;
2020-11-19 16:51:14 +01:00
LibraryModules . AnimationUtils . parallel ( [ LibraryModules . AnimationUtils . timing ( Animation , { toValue : p , duration : Math . sqrt ( w * * 2 ) * 4000 / ( parseInt ( this . props . speed ) || 1 ) } ) ] ) . start ( ) ;
2021-01-26 21:14:48 +01:00
} ;
2020-09-19 21:32:19 +02:00
}
} ,
onClick : e => {
if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ;
} ,
onMouseEnter : e => {
if ( BDFDB . DOMUtils . getRects ( e . currentTarget ) . width < BDFDB . DOMUtils . getRects ( e . currentTarget . firstElementChild ) . width ) {
this . scrolling = true ;
e . currentTarget . firstElementChild . style . setProperty ( "display" , "block" , "important" ) ;
this . scroll ( 1 ) ;
}
} ,
onMouseLeave : e => {
if ( this . scrolling ) {
delete this . scrolling ;
e . currentTarget . firstElementChild . style . setProperty ( "display" , "inline" , "important" ) ;
this . scroll ( 0 ) ;
}
} ,
children : BDFDB . ReactUtils . createElement ( "div" , {
style : {
left : "0" ,
position : "relative" ,
display : "inline" ,
whiteSpace : "nowrap"
} ,
children : this . props . children
} )
} ) ;
}
} ;
InternalComponents . LibraryComponents . TooltipContainer = reactInitialized && class BDFDB _TooltipContainer extends LibraryModules . React . Component {
updateTooltip ( text ) {
if ( this . tooltip ) this . tooltip . update ( text ) ;
}
render ( ) {
2021-02-20 13:41:20 +01:00
let child = ( typeof this . props . children == "function" ? this . props . children ( ) : ( BDFDB . ArrayUtils . is ( this . props . children ) ? this . props . children [ 0 ] : this . props . children ) ) || BDFDB . ReactUtils . createElement ( "div" , { } ) ;
2020-09-19 21:32:19 +02:00
child . props . className = BDFDB . DOMUtils . formatClassName ( child . props . className , this . props . className ) ;
2020-10-08 19:37:46 +02:00
let childProps = Object . assign ( { } , child . props ) ;
2020-09-19 21:32:19 +02:00
let shown = false ;
child . props . onMouseEnter = ( e , childThis ) => {
2020-10-08 17:35:36 +02:00
if ( ! shown && ! e . currentTarget . BDFDBtooltipShown ) {
e . currentTarget . BDFDBtooltipShown = shown = true ;
this . tooltip = BDFDB . TooltipUtils . create ( e . currentTarget , typeof this . props . text == "function" ? this . props . text ( this ) : this . props . text , Object . assign ( {
2020-11-12 17:11:25 +01:00
delay : this . props . delay
2020-10-08 17:35:36 +02:00
} , this . props . tooltipConfig , {
onHide : ( tooltip , anker ) => {
delete anker . BDFDBtooltipShown ;
shown = false ;
if ( this . props . tooltipConfig && typeof this . props . tooltipConfig . onHide == "function" ) this . props . onHide ( tooltip , anker ) ;
}
} ) ) ;
2020-09-19 21:32:19 +02:00
if ( typeof this . props . onMouseEnter == "function" ) this . props . onMouseEnter ( e , this ) ;
2020-10-08 19:37:46 +02:00
if ( typeof childProps . onMouseEnter == "function" ) childProps . onMouseEnter ( e , childThis ) ;
2020-09-19 21:32:19 +02:00
}
} ;
child . props . onMouseLeave = ( e , childThis ) => {
if ( typeof this . props . onMouseLeave == "function" ) this . props . onMouseLeave ( e , this ) ;
2020-10-08 19:37:46 +02:00
if ( typeof childProps . onMouseLeave == "function" ) childProps . onMouseLeave ( e , childThis ) ;
2020-09-19 21:32:19 +02:00
} ;
child . props . onClick = ( e , childThis ) => {
if ( typeof this . props . onClick == "function" ) this . props . onClick ( e , this ) ;
2020-10-08 19:37:46 +02:00
if ( typeof childProps . onClick == "function" ) childProps . onClick ( e , childThis ) ;
2020-09-19 21:32:19 +02:00
} ;
child . props . onContextMenu = ( e , childThis ) => {
if ( typeof this . props . onContextMenu == "function" ) this . props . onContextMenu ( e , this ) ;
2020-10-08 19:37:46 +02:00
if ( typeof childProps . onContextMenu == "function" ) childProps . onContextMenu ( e , childThis ) ;
2020-09-19 21:32:19 +02:00
} ;
return BDFDB . ReactUtils . createElement ( LibraryModules . React . Fragment , {
children : child
} ) ;
}
} ;
InternalComponents . LibraryComponents . UserPopoutContainer = reactInitialized && class BDFDB _UserPopoutContainer extends LibraryModules . React . Component {
render ( ) {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . PopoutContainer , BDFDB . ObjectUtils . exclude ( Object . assign ( { } , this . props , {
wrap : false ,
renderPopout : instance => {
return BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . UserPopout , {
userId : this . props . userId ,
guildId : this . props . guildId ,
channelId : this . props . channelId
} ) ;
}
} ) , "userId" , "guildId" , "channelId" ) ) ;
}
} ;
for ( let type in InternalComponents . NativeSubComponents ) if ( InternalComponents . LibraryComponents [ type ] ) for ( let key in InternalComponents . NativeSubComponents [ type ] ) if ( key != "displayName" && key != "name" && ( typeof InternalComponents . NativeSubComponents [ type ] [ key ] != "function" || key . charAt ( 0 ) == key . charAt ( 0 ) . toUpperCase ( ) ) ) {
if ( key == "defaultProps" ) InternalComponents . LibraryComponents [ type ] [ key ] = Object . assign ( { } , InternalComponents . LibraryComponents [ type ] [ key ] , InternalComponents . NativeSubComponents [ type ] [ key ] ) ;
else InternalComponents . LibraryComponents [ type ] [ key ] = InternalComponents . NativeSubComponents [ type ] [ key ] ;
}
BDFDB . LibraryComponents = Object . assign ( { } , InternalComponents . LibraryComponents ) ;
2020-09-22 23:30:15 +02:00
2020-11-11 00:25:33 +01:00
InternalBDFDB . createCustomControl = function ( data ) {
2021-02-19 10:40:22 +01:00
let controlButton = BDFDB . DOMUtils . create ( ` < ${ isBeta ? "button" : "div" } class=" ${ BDFDB . DOMUtils . formatClassName ( isBeta && BDFDB . disCN . _repobutton , BDFDB . disCN . _repocontrolsbutton , BDFDB . disCN . _repocontrolscustom ) } "></ ${ isBeta ? "button" : "div" } > ` ) ;
2020-11-12 17:11:25 +01:00
BDFDB . ReactUtils . render ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
2020-11-11 00:25:33 +01:00
className : ! isBeta && BDFDB . disCN . _repoicon ,
2020-11-06 16:42:45 +01:00
nativeClass : true ,
name : data . svgName ,
2021-01-21 15:25:02 +01:00
width : isBeta ? "20" : "24" ,
height : isBeta ? "20" : "24"
2020-11-12 17:11:25 +01:00
} ) , controlButton ) ;
2020-11-06 16:42:45 +01:00
controlButton . addEventListener ( "click" , _ => { if ( typeof data . onClick == "function" ) data . onClick ( ) ; } ) ;
2020-11-12 17:11:25 +01:00
if ( data . tooltipText ) controlButton . addEventListener ( "mouseenter" , _ => { BDFDB . TooltipUtils . create ( controlButton , data . tooltipText ) ; } ) ;
2020-09-22 23:30:15 +02:00
return controlButton ;
} ;
InternalBDFDB . appendCustomControls = function ( card ) {
2021-02-19 10:40:22 +01:00
if ( ! card || card . querySelector ( BDFDB . dotCN . _repocontrolscustom ) ) return ;
2020-09-22 23:30:15 +02:00
let checkbox = card . querySelector ( BDFDB . dotCN . _reposwitch ) ;
if ( ! checkbox ) return ;
2020-10-06 23:53:08 +02:00
let props = BDFDB . ObjectUtils . get ( BDFDB . ReactUtils . getInstance ( card ) , "return.stateNode.props" ) ;
2020-10-24 10:57:08 +02:00
let plugin = props && props . addon && ( props . addon . plugin || props . addon . instance ) ;
2021-02-19 10:40:22 +01:00
if ( plugin && ( plugin == libraryInstance || plugin . name && plugin . name && PluginStores . loaded [ plugin . name ] && PluginStores . loaded [ plugin . name ] == plugin ) ) {
2021-02-04 18:22:04 +01:00
let url = InternalBDFDB . getPluginURL ( plugin ) ;
2020-10-19 14:06:37 +02:00
let controls = [ ] ;
2020-11-12 14:30:33 +01:00
let footerControls = card . querySelector ( "." + BDFDB . disCN . _repofooter . split ( " " ) [ 0 ] + " " + BDFDB . dotCN . _repocontrols ) ;
2020-11-06 16:42:45 +01:00
if ( plugin . changeLog ) controls . push ( InternalBDFDB . createCustomControl ( {
tooltipText : BDFDB . LanguageUtils . LanguageStrings . CHANGE _LOG ,
svgName : InternalComponents . LibraryComponents . SvgIcon . Names . CHANGELOG ,
onClick : _ => { BDFDB . PluginUtils . openChangeLog ( plugin ) ; }
2020-11-11 00:25:33 +01:00
} ) ) ;
2021-02-07 22:30:09 +01:00
if ( PluginStores . updateData . plugins [ url ] && PluginStores . updateData . plugins [ url ] . outdated ) controls . push ( InternalBDFDB . createCustomControl ( {
2020-11-06 16:42:45 +01:00
tooltipText : BDFDB . LanguageUtils . LanguageStrings . UPDATE _MANUALLY ,
svgName : InternalComponents . LibraryComponents . SvgIcon . Names . DOWNLOAD ,
onClick : _ => { BDFDB . PluginUtils . downloadUpdate ( plugin . name , url ) ; }
2020-11-11 00:25:33 +01:00
} ) ) ;
2020-11-06 16:42:45 +01:00
if ( footerControls ) for ( let control of controls ) footerControls . insertBefore ( control , footerControls . firstElementChild ) ;
else for ( let control of controls ) checkbox . parentElement . insertBefore ( control , checkbox . parentElement . firstElementChild ) ;
2020-09-22 23:30:15 +02:00
}
} ;
2021-02-09 13:05:30 +01:00
InternalBDFDB . addListObserver = function ( layer ) {
if ( ! layer ) return ;
2021-02-19 10:40:22 +01:00
BDFDB . ObserverUtils . connect ( BDFDB , layer , { name : "cardObserver" , instance : new MutationObserver ( changes => { changes . forEach ( change => { if ( change . addedNodes ) { change . addedNodes . forEach ( n => {
if ( BDFDB . DOMUtils . containsClass ( n , BDFDB . disCN . _repocard ) ) InternalBDFDB . appendCustomControls ( n ) ;
if ( n . nodeType != Node . TEXT _NODE ) for ( let c of n . querySelectorAll ( BDFDB . dotCN . _repocard ) ) InternalBDFDB . appendCustomControls ( c ) ;
InternalBDFDB . appendCustomControls ( BDFDB . DOMUtils . getParent ( BDFDB . dotCN . _repocard , n ) ) ;
2021-02-09 13:05:30 +01:00
} ) ; } } ) ; } ) } , { childList : true , subtree : true } ) ;
2021-02-19 10:40:22 +01:00
for ( let c of layer . querySelectorAll ( BDFDB . dotCN . _repocard ) ) InternalBDFDB . appendCustomControls ( c ) ;
2021-02-09 13:05:30 +01:00
}
2020-09-19 21:32:19 +02:00
const keyDownTimeouts = { } ;
BDFDB . ListenerUtils . add ( BDFDB , document , "keydown.BDFDBPressedKeys" , e => {
if ( ! pressedKeys . includes ( e . which ) ) {
BDFDB . TimeUtils . clear ( keyDownTimeouts [ e . which ] ) ;
pressedKeys . push ( e . which ) ;
keyDownTimeouts [ e . which ] = BDFDB . TimeUtils . timeout ( _ => {
BDFDB . ArrayUtils . remove ( pressedKeys , e . which , true ) ;
} , 60000 ) ;
}
} ) ;
BDFDB . ListenerUtils . add ( BDFDB , document , "keyup.BDFDBPressedKeys" , e => {
BDFDB . TimeUtils . clear ( keyDownTimeouts [ e . which ] ) ;
BDFDB . ArrayUtils . remove ( pressedKeys , e . which , true ) ;
} ) ;
BDFDB . ListenerUtils . add ( BDFDB , document , "mousedown.BDFDBMousePosition" , e => {
mousePosition = e ;
} ) ;
BDFDB . ListenerUtils . add ( BDFDB , window , "focus.BDFDBPressedKeysReset" , e => {
pressedKeys = [ ] ;
} ) ;
InternalBDFDB . patchedModules = {
after : {
DiscordTag : "default" ,
Message : "default" ,
MessageHeader : "default" ,
MemberListItem : [ "componentDidMount" , "componentDidUpdate" ] ,
PrivateChannel : [ "componentDidMount" , "componentDidUpdate" ] ,
UserPopout : [ "componentDidMount" , "componentDidUpdate" ] ,
UserProfile : [ "componentDidMount" , "componentDidUpdate" ] ,
2021-02-09 13:05:30 +01:00
SettingsView : "componentDidMount" ,
2021-02-05 21:45:34 +01:00
Shakeable : "render"
2020-09-19 21:32:19 +02:00
}
} ;
2021-02-09 13:05:30 +01:00
InternalBDFDB . processSettingsView = function ( e ) {
if ( e . node && e . node . parentElement && e . node . parentElement . getAttribute ( "aria-label" ) == BDFDB . DiscordConstants . Layers . USER _SETTINGS ) InternalBDFDB . addListObserver ( e . node . parentElement ) ;
}
2021-01-30 12:36:34 +01:00
let AppViewExport = BDFDB . ModuleUtils . findByName ( "AppView" , false ) ;
if ( AppViewExport ) InternalBDFDB . processShakeable = function ( e ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { name : "AppView" } ) ;
if ( index > - 1 ) children [ index ] = BDFDB . ReactUtils . createElement ( AppViewExport . exports . default , children [ index ] . props ) ;
} ;
2020-09-19 21:32:19 +02:00
let MessageHeaderExport = BDFDB . ModuleUtils . findByProperties ( "MessageTimestamp" , false ) ;
2020-12-16 11:11:55 +01:00
InternalBDFDB . processMessage = function ( e ) {
if ( MessageHeaderExport && BDFDB . ObjectUtils . get ( e , "instance.props.childrenHeader.type.type.name" ) && BDFDB . ObjectUtils . get ( e , "instance.props.childrenHeader.props.message" ) ) {
2020-09-19 21:32:19 +02:00
e . instance . props . childrenHeader . type = MessageHeaderExport . exports . default ;
}
2020-12-16 11:11:55 +01:00
if ( e . returnvalue && e . returnvalue . props && e . returnvalue . props . children && e . returnvalue . props . children . props ) {
let message ;
for ( let key in e . instance . props ) {
2021-01-29 11:25:59 +01:00
if ( ! message ) message = BDFDB . ObjectUtils . get ( e . instance . props [ key ] , "props.message" ) ;
else break ;
2020-12-16 11:11:55 +01:00
}
if ( message ) e . returnvalue . props . children . props [ "user_by_BDFDB" ] = message . author . id ;
}
2020-09-19 21:32:19 +02:00
} ;
const BDFDB _Patrons = Object . assign ( { } , InternalData . BDFDB _Patrons ) ;
InternalBDFDB . _processAvatarRender = function ( user , avatar ) {
if ( BDFDB . ReactUtils . isValidElement ( avatar ) && BDFDB . ObjectUtils . is ( user ) && ( avatar . props . className || "" ) . indexOf ( BDFDB . disCN . bdfdbbadgeavatar ) == - 1 ) {
avatar . props [ "user_by_BDFDB" ] = user . id ;
let role = "" , className = BDFDB . DOMUtils . formatClassName ( ( avatar . props . className || "" ) . replace ( BDFDB . disCN . avatar , "" ) ) , addBadge = settings . showSupportBadges , customBadge = false ;
if ( BDFDB _Patrons [ user . id ] && BDFDB _Patrons [ user . id ] . active ) {
role = BDFDB _Patrons [ user . id ] . t3 ? "BDFDB Patron Level 2" : "BDFDB Patron" ;
customBadge = addBadge && BDFDB _Patrons [ user . id ] . t3 && BDFDB _Patrons [ user . id ] . custom ;
className = BDFDB . DOMUtils . formatClassName ( className , addBadge && BDFDB . disCN . bdfdbhasbadge , BDFDB . disCN . bdfdbbadgeavatar , BDFDB . disCN . bdfdbsupporter , customBadge && BDFDB . disCN . bdfdbsupportercustom ) ;
}
if ( user . id == InternalData . myId ) {
addBadge = true ;
2020-12-24 11:46:03 +01:00
role = ` Theme ${ BDFDB . LanguageUtils . LibraryStrings . developer } ` ;
2020-09-19 21:32:19 +02:00
className = BDFDB . DOMUtils . formatClassName ( className , BDFDB . disCN . bdfdbhasbadge , BDFDB . disCN . bdfdbbadgeavatar , BDFDB . disCN . bdfdbdev ) ;
}
if ( role ) {
delete avatar . props [ "user_by_BDFDB" ] ;
if ( avatar . type == "img" ) avatar = BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . AvatarComponents . default , Object . assign ( { } , avatar . props , {
2020-10-08 17:35:36 +02:00
size : InternalComponents . LibraryComponents . AvatarComponents . Sizes . SIZE _40
2020-09-19 21:32:19 +02:00
} ) ) ;
delete avatar . props . className ;
avatar = BDFDB . ReactUtils . createElement ( "div" , {
className : className ,
style : { borderRadius : 0 , overflow : "visible" } ,
"custombadge_id" : customBadge ? user . id : null ,
"user_by_BDFDB" : user . id ,
children : [ avatar ]
} ) ;
if ( addBadge ) avatar . props . children . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . TooltipContainer , {
text : role ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . disCN . bdfdbbadge
} )
} ) ) ;
return avatar ;
}
}
} ;
InternalBDFDB . _processAvatarMount = function ( user , avatar , wrapper ) {
if ( Node . prototype . isPrototypeOf ( avatar ) && BDFDB . ObjectUtils . is ( user ) && ( avatar . className || "" ) . indexOf ( BDFDB . disCN . bdfdbbadgeavatar ) == - 1 ) {
if ( wrapper ) wrapper . setAttribute ( "user_by_BDFDB" , user . id ) ;
avatar . setAttribute ( "user_by_BDFDB" , user . id ) ;
let role = "" , addBadge = settings . showSupportBadges , customBadge = false ;
if ( BDFDB _Patrons [ user . id ] && BDFDB _Patrons [ user . id ] . active ) {
role = BDFDB _Patrons [ user . id ] . t3 ? "BDFDB Patron Level 2" : "BDFDB Patron" ;
customBadge = addBadge && BDFDB _Patrons [ user . id ] . t3 && BDFDB _Patrons [ user . id ] . custom ;
avatar . className = BDFDB . DOMUtils . formatClassName ( avatar . className , addBadge && BDFDB . disCN . bdfdbhasbadge , BDFDB . disCN . bdfdbbadgeavatar , BDFDB . disCN . bdfdbsupporter , customBadge && BDFDB . disCN . bdfdbsupportercustom ) ;
}
else if ( user . id == InternalData . myId ) {
addBadge = true ;
2020-12-24 12:27:14 +01:00
role = ` Theme ${ BDFDB . LanguageUtils . LibraryStrings . developer } ` ;
2020-09-19 21:32:19 +02:00
avatar . className = BDFDB . DOMUtils . formatClassName ( avatar . className , addBadge && BDFDB . disCN . bdfdbhasbadge , BDFDB . disCN . bdfdbbadgeavatar , BDFDB . disCN . bdfdbdev ) ;
}
if ( role && ! avatar . querySelector ( BDFDB . dotCN . bdfdbbadge ) ) {
if ( addBadge ) {
if ( customBadge ) avatar . setAttribute ( "custombadge_id" , user . id ) ;
let badge = document . createElement ( "div" ) ;
badge . className = BDFDB . disCN . bdfdbbadge ;
2021-02-05 21:45:34 +01:00
badge . addEventListener ( "mouseenter" , _ => BDFDB . TooltipUtils . create ( badge , role , { position : "top" } ) ) ;
2020-09-19 21:32:19 +02:00
avatar . style . setProperty ( "position" , "relative" ) ;
avatar . style . setProperty ( "overflow" , "visible" ) ;
avatar . style . setProperty ( "border-radius" , 0 ) ;
avatar . appendChild ( badge ) ;
}
}
}
} ;
InternalBDFDB . processMessageHeader = function ( e ) {
if ( e . instance . props . message && e . instance . props . message . author ) {
let avatarWrapper = BDFDB . ObjectUtils . get ( e , "returnvalue.props.children.0" ) ;
if ( avatarWrapper && avatarWrapper . props && typeof avatarWrapper . props . children == "function" ) {
let renderChildren = avatarWrapper . props . children ;
avatarWrapper . props . children = ( ... args ) => {
let renderedChildren = renderChildren ( ... args ) ;
return InternalBDFDB . _processAvatarRender ( e . instance . props . message . author , renderedChildren ) || renderedChildren ;
} ;
}
else if ( avatarWrapper && avatarWrapper . type == "img" ) e . returnvalue . props . children [ 0 ] = InternalBDFDB . _processAvatarRender ( e . instance . props . message . author , avatarWrapper ) || avatarWrapper ;
}
} ;
InternalBDFDB . processMemberListItem = function ( e ) {
2020-12-30 20:23:37 +01:00
InternalBDFDB . _processAvatarMount ( e . instance . props . user , e . node . querySelector ( BDFDB . dotCN . avatarwrapper ) , e . node ) ;
2020-09-19 21:32:19 +02:00
} ;
InternalBDFDB . processPrivateChannel = function ( e ) {
2020-12-30 20:23:37 +01:00
InternalBDFDB . _processAvatarMount ( e . instance . props . user , e . node . querySelector ( BDFDB . dotCN . avatarwrapper ) , e . node ) ;
2020-09-19 21:32:19 +02:00
} ;
InternalBDFDB . processUserPopout = function ( e ) {
InternalBDFDB . _processAvatarMount ( e . instance . props . user , e . node . querySelector ( BDFDB . dotCN . userpopoutavatarwrapper ) , e . node ) ;
} ;
InternalBDFDB . processUserProfile = function ( e ) {
InternalBDFDB . _processAvatarMount ( e . instance . props . user , e . node . querySelector ( BDFDB . dotCN . avatarwrapper ) , e . node ) ;
} ;
InternalBDFDB . processDiscordTag = function ( e ) {
if ( e . instance && e . instance . props && e . returnvalue && e . instance . props . user ) e . returnvalue . props . user = e . instance . props . user ;
} ;
2020-10-15 21:56:54 +02:00
const ContextMenuTypes = [ "UserSettingsCog" , "UserProfileActions" , "User" , "Developer" , "Slate" , "GuildFolder" , "GroupDM" , "SystemMessage" , "Message" , "Native" , "Role" , "Guild" , "Channel" ] ;
2020-09-19 21:32:19 +02:00
const QueuedComponents = BDFDB . ArrayUtils . removeCopies ( [ ] . concat ( ContextMenuTypes . map ( n => n + "ContextMenu" ) , [ "GuildHeaderContextMenu" , "MessageOptionContextMenu" , "MessageOptionToolbar" ] ) ) ;
InternalBDFDB . addContextListeners = function ( plugin ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
2021-02-09 13:05:30 +01:00
for ( let type of QueuedComponents ) if ( typeof plugin [ ` on ${ type } ` ] == "function" ) {
2020-09-19 21:32:19 +02:00
PluginStores . patchQueues [ type ] . query . push ( plugin ) ;
PluginStores . patchQueues [ type ] . query = BDFDB . ArrayUtils . removeCopies ( PluginStores . patchQueues [ type ] . query ) ;
2021-01-11 18:38:07 +01:00
PluginStores . patchQueues [ type ] . query . sort ( ( x , y ) => x . name < y . name ? - 1 : x . name > y . name ? 1 : 0 ) ;
2020-09-19 21:32:19 +02:00
for ( let module of PluginStores . patchQueues [ type ] . modules ) InternalBDFDB . patchContextMenuForPlugin ( plugin , type , module ) ;
}
} ;
InternalBDFDB . patchContextMenuForPlugin = function ( plugin , type , module ) {
plugin = plugin == BDFDB && InternalBDFDB || plugin ;
if ( module && module . exports && module . exports . default ) BDFDB . PatchUtils . patch ( plugin , module . exports , "default" , { after : e => {
2021-02-09 13:05:30 +01:00
if ( e . returnValue && typeof plugin [ ` on ${ type } ` ] == "function" ) plugin [ ` on ${ type } ` ] ( { instance : { props : e . methodArguments [ 0 ] } , returnvalue : e . returnValue , methodname : "default" , type : module . exports . default . displayName } ) ;
2020-09-19 21:32:19 +02:00
} } ) ;
} ;
InternalBDFDB . executeExtraPatchedPatches = function ( type , e ) {
if ( e . returnvalue && BDFDB . ObjectUtils . is ( PluginStores . patchQueues [ type ] ) && BDFDB . ArrayUtils . is ( PluginStores . patchQueues [ type ] . query ) ) {
2021-02-09 13:05:30 +01:00
for ( let plugin of PluginStores . patchQueues [ type ] . query ) if ( typeof plugin [ ` on ${ type } ` ] == "function" ) plugin [ ` on ${ type } ` ] ( e ) ;
2020-09-19 21:32:19 +02:00
}
} ;
2020-11-28 19:47:01 +01:00
2020-11-28 20:31:32 +01:00
BDFDB . ReactUtils . instanceKey = Object . keys ( document . querySelector ( BDFDB . dotCN . app ) || { } ) . some ( n => n . startsWith ( "__reactInternalInstance" ) ) ? "_reactInternalFiber" : "_reactInternals" ;
2020-09-19 21:32:19 +02:00
BDFDB . PluginUtils . load ( BDFDB ) ;
2020-11-14 15:52:37 +01:00
changeLogs = BDFDB . DataUtils . load ( BDFDB , "changeLogs" ) ;
2020-09-19 21:58:35 +02:00
BDFDB . PluginUtils . checkChangeLog ( BDFDB ) ;
2020-09-19 21:32:19 +02:00
InternalBDFDB . patchPlugin ( BDFDB ) ;
2020-11-19 16:51:14 +01:00
for ( let type of QueuedComponents ) if ( ! PluginStores . patchQueues [ type ] ) PluginStores . patchQueues [ type ] = { query : [ ] , modules : [ ] } ;
2020-09-19 21:32:19 +02:00
BDFDB . PatchUtils . patch ( BDFDB , LibraryModules . ContextMenuUtils , "openContextMenu" , { before : e => {
let menu = e . methodArguments [ 1 ] ( ) ;
if ( BDFDB . ObjectUtils . is ( menu ) && menu . type && menu . type . displayName ) {
for ( let type of ContextMenuTypes ) if ( menu . type . displayName . indexOf ( type ) > - 1 ) {
let patchType = type + "ContextMenu" ;
let module = BDFDB . ModuleUtils . find ( m => m == menu . type , false ) ;
if ( module && module . exports && module . exports . default && PluginStores . patchQueues [ patchType ] ) {
PluginStores . patchQueues [ patchType ] . modules . push ( module ) ;
PluginStores . patchQueues [ patchType ] . modules = BDFDB . ArrayUtils . removeCopies ( PluginStores . patchQueues [ patchType ] . modules ) ;
for ( let plugin of PluginStores . patchQueues [ patchType ] . query ) InternalBDFDB . patchContextMenuForPlugin ( plugin , patchType , module ) ;
}
break ;
}
}
} } ) ;
BDFDB . PatchUtils . patch ( BDFDB , BDFDB . ObjectUtils . get ( BDFDB . ModuleUtils . findByString ( "renderReactions" , "canAddNewReactions" , "showMoreUtilities" , false ) , "exports.default" ) , "type" , { after : e => {
2020-10-08 17:35:36 +02:00
if ( document . querySelector ( BDFDB . dotCN . emojipicker ) || ! BDFDB . ObjectUtils . toArray ( PluginStores . loaded ) . filter ( p => p . started ) . some ( p => p . onMessageOptionContextMenu || p . onMessageOptionToolbar ) ) return ;
2020-09-19 21:32:19 +02:00
let toolbar = BDFDB . ReactUtils . findChild ( e . returnValue , { filter : c => c && c . props && c . props . showMoreUtilities != undefined && c . props . showEmojiPicker != undefined && c . props . setPopout != undefined } ) ;
if ( toolbar ) BDFDB . PatchUtils . patch ( BDFDB , toolbar , "type" , { after : e2 => {
let menu = BDFDB . ReactUtils . findChild ( e2 . returnValue , { filter : c => c && c . props && typeof c . props . onRequestClose == "function" && c . props . onRequestClose . toString ( ) . indexOf ( "moreUtilities" ) > - 1 } ) ;
2020-11-19 16:51:14 +01:00
InternalBDFDB . executeExtraPatchedPatches ( "MessageOptionToolbar" , { instance : { props : e2 . methodArguments [ 0 ] } , returnvalue : e2 . returnValue , methodname : "default" } ) ;
2020-09-19 21:32:19 +02:00
if ( menu && typeof menu . props . renderPopout == "function" ) {
let renderPopout = menu . props . renderPopout ;
menu . props . renderPopout = ( ... args ) => {
let renderedPopout = renderPopout ( ... args ) ;
BDFDB . PatchUtils . patch ( BDFDB , renderedPopout , "type" , { after : e3 => {
2020-11-19 16:51:14 +01:00
InternalBDFDB . executeExtraPatchedPatches ( "MessageOptionContextMenu" , { instance : { props : e3 . methodArguments [ 0 ] } , returnvalue : e3 . returnValue , methodname : "default" } ) ;
2020-09-19 21:32:19 +02:00
} } , { noCache : true } ) ;
return renderedPopout ;
}
}
} } , { once : true } ) ;
} } ) ;
BDFDB . PatchUtils . patch ( BDFDB , BDFDB . ObjectUtils . get ( BDFDB . ModuleUtils . findByString ( "guild-header-popout" , false ) , "exports.default.prototype" ) , "render" , { after : e => {
BDFDB . PatchUtils . patch ( BDFDB , e . returnValue . type , "type" , { after : e2 => {
2020-11-19 16:51:14 +01:00
InternalBDFDB . executeExtraPatchedPatches ( "GuildHeaderContextMenu" , { instance : { props : e2 . methodArguments [ 0 ] } , returnvalue : e2 . returnValue , methodname : "type" } ) ;
2020-09-19 21:32:19 +02:00
} } , { noCache : true } ) ;
} } ) ;
InternalBDFDB . onSettingsClosed = function ( ) {
if ( InternalBDFDB . SettingsUpdated ) {
delete InternalBDFDB . SettingsUpdated ;
InternalBDFDB . forceUpdateAll ( ) ;
}
} ;
InternalBDFDB . forceUpdateAll = function ( ) {
2021-01-27 18:14:10 +01:00
if ( LibraryRequires . path ) {
settings = BDFDB . DataUtils . get ( BDFDB , "settings" ) ;
choices = BDFDB . DataUtils . get ( BDFDB , "choices" ) ;
}
2020-09-19 21:32:19 +02:00
BDFDB . MessageUtils . rerenderAll ( ) ;
BDFDB . PatchUtils . forceAllUpdates ( BDFDB ) ;
} ;
InternalBDFDB . addSpecialListeners ( BDFDB ) ;
if ( InternalComponents . LibraryComponents . GuildComponents . BlobMask ) {
let newBadges = [ "lowerLeftBadge" , "upperLeftBadge" ] ;
BDFDB . PatchUtils . patch ( BDFDB , InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype , "render" , {
before : e => {
e . thisObject . props = Object . assign ( { } , InternalComponents . LibraryComponents . GuildComponents . BlobMask . defaultProps , e . thisObject . props ) ;
for ( let type of newBadges ) if ( ! e . thisObject . state [ ` ${ type } Mask ` ] ) e . thisObject . state [ ` ${ type } Mask ` ] = new InternalComponents . LibraryComponents . Animations . Controller ( { spring : 0 } ) ;
} ,
after : e => {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnValue , { name : "TransitionGroup" } ) ;
if ( index > - 1 ) {
children [ index ] . props . children . push ( ! e . thisObject . props . lowerLeftBadge ? null : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . BadgeAnimationContainer , {
className : BDFDB . disCN . guildlowerleftbadge ,
key : "lower-left-badge" ,
animatedStyle : e . thisObject . getLowerLeftBadgeStyles ( ) ,
children : e . thisObject . props . lowerLeftBadge
} ) ) ;
children [ index ] . props . children . push ( ! e . thisObject . props . upperLeftBadge ? null : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . BadgeAnimationContainer , {
className : BDFDB . disCN . guildupperleftbadge ,
key : "upper-left-badge" ,
animatedStyle : e . thisObject . getUpperLeftBadgeStyles ( ) ,
children : e . thisObject . props . upperLeftBadge
} ) ) ;
}
[ children , index ] = BDFDB . ReactUtils . findParent ( e . returnValue , { name : "mask" } ) ;
if ( index > - 1 ) {
children [ index ] . props . children . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . rect , {
x : - 4 ,
y : - 4 ,
width : e . thisObject . props . upperLeftBadgeWidth + 8 ,
height : 24 ,
rx : 12 ,
ry : 12 ,
transform : e . thisObject . getLeftBadgePositionInterpolation ( e . thisObject . state . upperLeftBadgeMask , - 1 ) ,
fill : "black"
} ) ) ;
children [ index ] . props . children . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Animations . animated . rect , {
x : - 4 ,
y : 28 ,
width : e . thisObject . props . lowerLeftBadgeWidth + 8 ,
height : 24 ,
rx : 12 ,
ry : 12 ,
transform : e . thisObject . getLeftBadgePositionInterpolation ( e . thisObject . state . lowerLeftBadgeMask ) ,
fill : "black"
} ) ) ;
}
}
} ) ;
BDFDB . PatchUtils . patch ( BDFDB , InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype , "componentDidMount" , {
after : e => {
for ( let type of newBadges ) e . thisObject . state [ ` ${ type } Mask ` ] . update ( {
spring : e . thisObject . props [ type ] != null ? 1 : 0 ,
immediate : true
} ) . start ( ) ;
}
} ) ;
BDFDB . PatchUtils . patch ( BDFDB , InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype , "componentWillUnmount" , {
after : e => {
for ( let type of newBadges ) if ( e . thisObject . state [ ` ${ type } Mask ` ] ) e . thisObject . state [ ` ${ type } Mask ` ] . dispose ( ) ;
}
} ) ;
BDFDB . PatchUtils . patch ( BDFDB , InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype , "componentDidUpdate" , {
after : e => {
for ( let type of newBadges ) if ( e . thisObject . props [ type ] != null && e . methodArguments [ 0 ] [ type ] == null ) {
e . thisObject . state [ ` ${ type } Mask ` ] . update ( {
spring : 1 ,
immediate : ! document . hasFocus ( ) ,
config : { friction : 30 , tension : 900 , mass : 1 }
} ) . start ( ) ;
}
else if ( e . thisObject . props [ type ] == null && e . methodArguments [ 0 ] [ type ] != null ) {
e . thisObject . state [ ` ${ type } Mask ` ] . update ( {
spring : 0 ,
immediate : ! document . hasFocus ( ) ,
config : { duration : 150 , friction : 10 , tension : 100 , mass : 1 }
} ) . start ( ) ;
}
}
} ) ;
InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype . getLeftBadgePositionInterpolation = function ( e , t ) {
return void 0 === t && ( t = 1 ) , e . springs . spring . to ( [ 0 , 1 ] , [ 20 , 0 ] ) . to ( function ( e ) {
return "translate(" + e * - 1 + " " + e * t + ")" ;
} ) ;
} ;
InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype . getLowerLeftBadgeStyles = function ( ) {
var e = this . state . lowerLeftBadgeMask . springs . spring ;
return {
opacity : e . to ( [ 0 , . 5 , 1 ] , [ 0 , 0 , 1 ] ) ,
transform : e . to ( function ( e ) {
return "translate(" + - 1 * ( 16 - 16 * e ) + "px, " + ( 16 - 16 * e ) + "px)" ;
} )
} ;
} ;
InternalComponents . LibraryComponents . GuildComponents . BlobMask . prototype . getUpperLeftBadgeStyles = function ( ) {
var e = this . state . upperLeftBadgeMask . springs . spring ;
return {
opacity : e . to ( [ 0 , . 5 , 1 ] , [ 0 , 0 , 1 ] ) ,
transform : e . to ( function ( e ) {
return "translate(" + - 1 * ( 16 - 16 * e ) + "px, " + - 1 * ( 16 - 16 * e ) + "px)" ;
} )
} ;
} ;
let extraDefaultProps = { } ;
for ( let type of newBadges ) extraDefaultProps [ ` ${ type } Width ` ] = 16 ;
InternalBDFDB . setDefaultProps ( InternalComponents . LibraryComponents . GuildComponents . BlobMask , extraDefaultProps ) ;
}
BDFDB . PatchUtils . patch ( BDFDB , LibraryModules . GuildStore , "getGuild" , { after : e => {
2020-11-19 16:45:36 +01:00
if ( e . returnValue && e . methodArguments [ 0 ] == InternalData . myGuildId ) e . returnValue . banner = "https://mwittrien.github.io/BetterDiscordAddons/Library/_res/BDFDB.banner.png" ;
2020-09-19 21:32:19 +02:00
} } ) ;
BDFDB . PatchUtils . patch ( BDFDB , LibraryModules . IconUtils , "getGuildBannerURL" , { instead : e => {
return e . methodArguments [ 0 ] . id == InternalData . myGuildId ? e . methodArguments [ 0 ] . banner : e . callOriginalMethod ( ) ;
} } ) ;
InternalBDFDB . forceUpdateAll ( ) ;
const pluginQueue = window . BDFDB _Global && BDFDB . ArrayUtils . is ( window . BDFDB _Global . pluginQueue ) ? window . BDFDB _Global . pluginQueue : [ ] ;
2021-02-26 14:18:07 +01:00
if ( BDFDB . UserUtils . me . id == InternalData . myId || BDFDB . UserUtils . me . id == "350635509275557888" ) {
2020-09-19 21:32:19 +02:00
for ( let module in DiscordClassModules ) if ( ! DiscordClassModules [ module ] ) BDFDB . LogUtils . warn ( module + " not initialized in DiscordClassModules" ) ;
for ( let obj in DiscordObjects ) if ( ! DiscordObjects [ obj ] ) BDFDB . LogUtils . warn ( obj + " not initialized in DiscordObjects" ) ;
for ( let require in LibraryRequires ) if ( ! LibraryRequires [ require ] ) BDFDB . LogUtils . warn ( require + " not initialized in LibraryRequires" ) ;
for ( let module in LibraryModules ) if ( ! LibraryModules [ module ] ) BDFDB . LogUtils . warn ( module + " not initialized in LibraryModules" ) ;
for ( let component in InternalComponents . NativeSubComponents ) if ( ! InternalComponents . NativeSubComponents [ component ] ) BDFDB . LogUtils . warn ( component + " not initialized in NativeSubComponents" ) ;
for ( let component in InternalComponents . LibraryComponents ) if ( ! InternalComponents . LibraryComponents [ component ] ) BDFDB . LogUtils . warn ( component + " not initialized in LibraryComponents" ) ;
BDFDB . DevUtils = { } ;
2020-09-23 08:08:23 +02:00
BDFDB . DevUtils . generateClassId = InternalBDFDB . generateClassId ;
2020-09-19 21:32:19 +02:00
BDFDB . DevUtils . findByIndex = function ( index ) {
return BDFDB . DevUtils . req . c [ index ] ;
} ;
BDFDB . DevUtils . findPropAny = function ( ... strings ) {
window . t = { "$filter" : ( prop => [ ... strings ] . flat ( 10 ) . filter ( n => typeof n == "string" ) . every ( string => prop . toLowerCase ( ) . indexOf ( string . toLowerCase ( ) ) > - 1 ) ) } ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
if ( m && typeof m == "object" ) for ( let j in m ) if ( window . t . $filter ( j ) ) window . t [ j + "_" + i ] = m ;
if ( m && typeof m == "object" && typeof m . default == "object" ) for ( let j in m . default ) if ( window . t . $filter ( j ) ) window . t [ j + "_default_" + i ] = m . default ;
}
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . findPropFunc = function ( ... strings ) {
window . t = { "$filter" : ( prop => [ ... strings ] . flat ( 10 ) . filter ( n => typeof n == "string" ) . every ( string => prop . toLowerCase ( ) . indexOf ( string . toLowerCase ( ) ) > - 1 ) ) } ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
if ( m && typeof m == "object" ) for ( let j in m ) if ( window . t . $filter ( j ) && typeof m [ j ] != "string" ) window . t [ j + "_" + i ] = m ;
if ( m && typeof m == "object" && typeof m . default == "object" ) for ( let j in m . default ) if ( window . t . $filter ( j ) && typeof m . default [ j ] != "string" ) window . t [ j + "_default_" + i ] = m . default ;
}
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . findPropStringLib = function ( ... strings ) {
window . t = { "$filter" : ( prop => [ ... strings ] . flat ( 10 ) . filter ( n => typeof n == "string" ) . every ( string => prop . toLowerCase ( ) . indexOf ( string . toLowerCase ( ) ) > - 1 ) ) } ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
if ( m && typeof m == "object" ) for ( let j in m ) if ( window . t . $filter ( j ) && typeof m [ j ] == "string" && /^[A-z0-9]+\-[A-z0-9_-]{6}$/ . test ( m [ j ] ) ) window . t [ j + "_" + i ] = m ;
if ( m && typeof m == "object" && typeof m . default == "object" ) for ( let j in m . default ) if ( window . t . $filter ( j ) && typeof m . default [ j ] == "string" && /^[A-z0-9]+\-[A-z0-9_-]{6}$/ . test ( m . default [ j ] ) ) window . t [ j + "_default_" + i ] = m . default ;
}
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . findNameAny = function ( ... strings ) {
window . t = { "$filter" : ( modu => [ ... strings ] . flat ( 10 ) . filter ( n => typeof n == "string" ) . some ( string => typeof modu . displayName == "string" && modu . displayName . toLowerCase ( ) . indexOf ( string . toLowerCase ( ) ) > - 1 || modu . name == "string" && modu . name . toLowerCase ( ) . indexOf ( string . toLowerCase ( ) ) > - 1 ) ) } ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
if ( m && ( typeof m == "object" || typeof m == "function" ) && window . t . $filter ( m ) ) window . t [ ( m . displayName || m . name ) + "_" + i ] = m ;
if ( m && ( typeof m == "object" || typeof m == "function" ) && m . default && ( typeof m . default == "object" || typeof m . default == "function" ) && window . t . $filter ( m . default ) ) window . t [ ( m . default . displayName || m . default . name ) + "_" + i ] = m . default ;
}
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . findCodeAny = function ( ... strings ) {
window . t = { "$filter" : ( m => [ ... strings ] . flat ( 10 ) . filter ( n => typeof n == "string" ) . map ( string => string . toLowerCase ( ) ) . every ( string => typeof m == "function" && ( m . toString ( ) . toLowerCase ( ) . indexOf ( string ) > - 1 || typeof m . _ _originalMethod == "function" && m . _ _originalMethod . toString ( ) . toLowerCase ( ) . indexOf ( string ) > - 1 || typeof m . _ _originalFunction == "function" && m . _ _originalFunction . toString ( ) . toLowerCase ( ) . indexOf ( string ) > - 1 ) || BDFDB . ObjectUtils . is ( m ) && typeof m . type == "function" && m . type . toString ( ) . toLowerCase ( ) . indexOf ( string ) > - 1 ) ) } ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
2020-11-19 16:51:14 +01:00
if ( m && typeof m == "function" && window . t . $filter ( m ) ) window . t [ "module_" + i ] = { string : m . toString ( ) , func : m } ;
2020-09-19 21:32:19 +02:00
if ( m && m . _ _esModule ) {
2020-11-19 16:51:14 +01:00
for ( let j in m ) if ( m [ j ] && typeof m [ j ] == "function" && window . t . $filter ( m [ j ] ) ) window . t [ j + "_module_" + i ] = { string : m [ j ] . toString ( ) , func : m [ j ] , module : m } ;
if ( m . default && ( typeof m . default == "object" || typeof m . default == "function" ) ) for ( let j in m . default ) if ( m . default [ j ] && typeof m . default [ j ] == "function" && window . t . $filter ( m . default [ j ] ) ) window . t [ j + "_module_" + i + "_default" ] = { string : m . default [ j ] . toString ( ) , func : m . default [ j ] , module : m } ;
2020-09-19 21:32:19 +02:00
}
}
2021-02-04 19:07:37 +01:00
for ( let i in BDFDB . DevUtils . req . m ) if ( typeof BDFDB . DevUtils . req . m [ i ] == "function" && window . t . $filter ( BDFDB . DevUtils . req . m [ i ] ) ) window . t [ "function_" + i ] = { string : BDFDB . DevUtils . req . m [ i ] . toString ( ) , func : BDFDB . DevUtils . req . m [ i ] } ;
2020-09-19 21:32:19 +02:00
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . getAllModules = function ( ) {
window . t = { } ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
if ( m && typeof m == "object" ) window . t [ i ] = m ;
}
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . getAllStringLibs = function ( ) {
window . t = [ ] ;
for ( let i in BDFDB . DevUtils . req . c ) if ( BDFDB . DevUtils . req . c . hasOwnProperty ( i ) ) {
let m = BDFDB . DevUtils . req . c [ i ] . exports ;
if ( m && typeof m == "object" && ! BDFDB . ArrayUtils . is ( m ) && Object . keys ( m ) . length ) {
var string = true , stringlib = false ;
for ( let j in m ) {
if ( typeof m [ j ] != "string" ) string = false ;
if ( typeof m [ j ] == "string" && /^[A-z0-9]+\-[A-z0-9_-]{6}$/ . test ( m [ j ] ) ) stringlib = true ;
}
if ( string && stringlib ) window . t . push ( m ) ;
}
if ( m && typeof m == "object" && m . default && typeof m . default == "object" && ! BDFDB . ArrayUtils . is ( m . default ) && Object . keys ( m . default ) . length ) {
var string = true , stringlib = false ;
for ( let j in m . default ) {
if ( typeof m . default [ j ] != "string" ) string = false ;
if ( typeof m . default [ j ] == "string" && /^[A-z0-9]+\-[A-z0-9_-]{6}$/ . test ( m . default [ j ] ) ) stringlib = true ;
}
if ( string && stringlib ) window . t . push ( m . default ) ;
}
}
console . clear ( ) ;
console . log ( window . t ) ;
} ;
BDFDB . DevUtils . listen = function ( strings ) {
strings = BDFDB . ArrayUtils . is ( strings ) ? strings : Array . from ( arguments ) ;
BDFDB . DevUtils . listenStop ( ) ;
BDFDB . DevUtils . listen . p = BDFDB . PatchUtils . patch ( "WebpackSearch" , BDFDB . ModuleUtils . findByProperties ( strings ) , strings [ 0 ] , { after : e => {
console . log ( e ) ;
} } ) ;
} ;
BDFDB . DevUtils . listenStop = function ( ) {
if ( typeof BDFDB . DevUtils . listen . p == "function" ) BDFDB . DevUtils . listen . p ( ) ;
} ;
2020-12-20 17:42:06 +01:00
BDFDB . DevUtils . generateLanguageStrings = function ( strings , config = { } ) {
2020-12-21 19:56:36 +01:00
const language = config . language || "en" ;
const languages = BDFDB . ArrayUtils . removeCopies ( BDFDB . ArrayUtils . is ( config . languages ) ? config . languages : [ "en" ] . concat ( Object . keys ( BDFDB . ObjectUtils . filter ( BDFDB . LanguageUtils . languages , n => n . discord ) ) ) . filter ( n => ! n . startsWith ( "en-" ) && ! n . startsWith ( "$" ) && n != language ) ) . sort ( ) ;
2020-12-20 15:03:04 +01:00
let translations = { } ;
strings = BDFDB . ObjectUtils . sort ( strings ) ;
2021-01-10 11:41:01 +01:00
const stringKeys = Object . keys ( strings ) ;
2020-12-21 19:56:36 +01:00
translations [ language ] = BDFDB . ObjectUtils . toArray ( strings ) ;
let text = Object . keys ( translations [ language ] ) . map ( k => translations [ language ] [ k ] ) . join ( "\n\n" ) ;
2020-12-20 15:03:04 +01:00
let gt = ( lang , callback ) => {
2020-12-21 19:56:36 +01:00
let googleTranslateWindow = BDFDB . WindowUtils . open ( BDFDB , ` https://translate.google.com/# ${ language } / ${ { "zh" : "zh-CN" , "pt-BR" : "pt" } [lang] || lang}/ ${ encodeURIComponent ( text ) } ` , {
2020-12-20 15:03:04 +01:00
onLoad : _ => {
googleTranslateWindow . executeJavaScriptSafe ( `
2020-12-21 19:56:36 +01:00
let count = 0 , interval = setInterval ( _ => {
count ++ ;
let translation = Array . from ( document . querySelectorAll ( "[data-language-to-translate-into] span:not([class])" ) ) . map ( n => n . innerText ) . join ( "" ) ;
if ( translation || count > 50 ) {
clearInterval ( interval ) ;
2021-01-28 16:07:18 +01:00
require ( "electron" ) . ipcRenderer . sendTo ( $ { LibraryRequires . electron . remote . getCurrentWindow ( ) . webContents . id } , "BDFDB-translation" , [
2020-12-21 19:56:36 +01:00
translation ,
( document . querySelector ( "h2 ~ [lang]" ) || { } ) . lang
] ) ;
}
} , 100 ) ;
2020-12-20 15:03:04 +01:00
` );
}
} ) ;
2020-12-24 11:46:03 +01:00
BDFDB . WindowUtils . addListener ( BDFDB , "BDFDB-translation" , ( event , messageData ) => {
2020-12-20 15:03:04 +01:00
BDFDB . WindowUtils . close ( googleTranslateWindow ) ;
2020-12-24 11:46:03 +01:00
BDFDB . WindowUtils . removeListener ( BDFDB , "BDFDB-translation" ) ;
2020-12-20 15:03:04 +01:00
callback ( messageData [ 0 ] ) ;
} ) ;
} ;
let gt2 = ( lang , callback ) => {
2020-12-21 19:56:36 +01:00
BDFDB . LibraryRequires . request ( ` https://translate.googleapis.com/translate_a/single?client=gtx&sl= ${ language } &tl= ${ lang } &dt=t&dj=1&source=input&q= ${ encodeURIComponent ( text ) } ` , ( error , response , result ) => {
2020-12-20 15:03:04 +01:00
if ( ! error && result && response . statusCode == 200 ) {
try { callback ( JSON . parse ( result ) . sentences . map ( n => n && n . trans ) . filter ( n => n ) . join ( "" ) ) ; }
catch ( err ) { callback ( "" ) ; }
}
else {
if ( response . statusCode == 429 ) {
2020-12-24 11:46:03 +01:00
BDFDB . NotificationUtils . toast ( "Too many requests, switching to backup" , {
2021-01-24 13:27:39 +01:00
type : "danger"
2020-12-24 11:46:03 +01:00
} ) ;
2020-12-20 17:42:06 +01:00
config . useBackup = true ;
BDFDB . DevUtils . generateLanguageStrings ( strings , config ) ;
2020-12-20 15:03:04 +01:00
}
else {
2020-12-24 11:46:03 +01:00
BDFDB . NotificationUtils . toast ( "Failed to translate text" , {
2021-01-24 13:27:39 +01:00
type : "danger"
2020-12-24 11:46:03 +01:00
} ) ;
2020-12-20 15:03:04 +01:00
callback ( "" ) ;
}
}
} ) ;
} ;
2020-12-21 19:56:36 +01:00
let fails = 0 , next = lang => {
2020-12-20 15:03:04 +01:00
if ( ! lang ) {
2021-01-10 11:41:01 +01:00
let formatTranslation = ( l , s , i ) => {
l = l == "en" ? "default" : l ;
2021-02-04 20:12:57 +01:00
return config . cached && config . cached [ l ] && config . cached [ l ] [ stringKeys [ i ] ] || ( translations [ language ] [ i ] [ 0 ] == translations [ language ] [ i ] [ 0 ] . toUpperCase ( ) ? LibraryModules . StringUtils . upperCaseFirstChar ( s ) : s ) ;
2021-01-10 11:41:01 +01:00
} ;
2020-12-24 09:41:59 +01:00
let format = config . asObject ? ( ( l , isNotFirst ) => {
2021-01-10 11:41:01 +01:00
return ` ${ isNotFirst ? "," : "" } \n \t \t " ${ l == "en" ? "default" : l } ": { ${ translations [ l ] . map ( ( s , i ) => ` \n \t \t \t " ${ stringKeys [ i ] } ": " ${ formatTranslation ( l , s , i ) } " ` ) . join ( "," ) } \n \t \t } ` ;
2020-12-24 09:41:59 +01:00
} ) : ( ( l , isNotFirst ) => {
2021-01-10 11:41:01 +01:00
return ` \n \t \t \t \t \t ${ l == "en" ? "default" : ` case " ${ l } " ` } : ${ l . length > 2 ? "\t" : "\t\t" } // ${ BDFDB . LanguageUtils . languages [ l ] . name } \n \t \t \t \t \t \t return { ${ translations [ l ] . map ( ( s , i ) => ` \n \t \t \t \t \t \t \t ${ stringKeys [ i ] } : ${ "\t" . repeat ( 10 - ( ( stringKeys [ i ] . length + 2 ) / 4 ) ) } " ${ formatTranslation ( l , s , i ) } " ` ) . join ( "," ) } \n \t \t \t \t \t \t }; ` ;
2020-12-24 09:41:59 +01:00
} ) ;
let result = Object . keys ( translations ) . filter ( n => n != "en" ) . sort ( ) . map ( ( l , i ) => format ( l , i ) ) . join ( "" ) ;
if ( translations . en ) result += format ( "en" , result ? 1 : 0 ) ;
2020-12-24 11:46:03 +01:00
BDFDB . NotificationUtils . toast ( "Translation copied to clipboard" , {
type : "success"
} ) ;
2020-12-20 15:03:04 +01:00
BDFDB . LibraryRequires . electron . clipboard . write ( { text : result } ) ;
}
2020-12-20 17:42:06 +01:00
else ( config . useBackup ? gt : gt2 ) ( lang , translation => {
2021-01-28 17:47:49 +01:00
BDFDB . LogUtils . log ( lang ) ;
2020-12-20 15:03:04 +01:00
if ( ! translation ) {
console . warn ( "no translation" ) ;
2020-12-21 19:56:36 +01:00
fails ++ ;
if ( fails > 10 ) console . error ( "skipped language" ) ;
else languages . unshift ( lang ) ;
}
else {
fails = 0 ;
translations [ lang ] = translation . split ( "\n\n" ) ;
2020-12-20 15:03:04 +01:00
}
next ( languages . shift ( ) ) ;
} ) ;
} ;
next ( languages . shift ( ) ) ;
} ;
2020-09-19 21:32:19 +02:00
BDFDB . DevUtils . req = InternalBDFDB . getWebModuleReq ( ) ;
2021-01-09 22:09:34 +01:00
window . BDFDB = BDFDB ;
2020-09-19 21:32:19 +02:00
}
2021-01-09 22:09:34 +01:00
2020-09-19 21:32:19 +02:00
for ( let obj in DiscordObjects ) if ( ! DiscordObjects [ obj ] ) {
DiscordObjects [ obj ] = function ( ) { } ;
BDFDB . DiscordObjects [ obj ] = function ( ) { } ;
}
for ( let component in InternalComponents . NativeSubComponents ) if ( ! InternalComponents . NativeSubComponents [ component ] ) InternalComponents . NativeSubComponents [ component ] = "div" ;
for ( let component in InternalComponents . LibraryComponents ) if ( ! InternalComponents . LibraryComponents [ component ] ) {
InternalComponents . LibraryComponents [ component ] = "div" ;
BDFDB . LibraryComponents [ component ] = "div" ;
}
2021-02-03 11:33:55 +01:00
if ( ! document . querySelector ( "head #bd-stylesheet" ) ) BDFDB . DOMUtils . appendWebStyle ( "https://rauenzi.github.io/BetterDiscordApp/src/styles/index.css" ) ;
2020-09-19 21:32:19 +02:00
if ( css ) BDFDB . DOMUtils . appendLocalStyle ( "BDFDB" , css . replace ( /[\n\t\r]/g , "" ) . replace ( /\[REPLACE_CLASS_([A-z0-9_]+?)\]/g , function ( a , b ) { return BDFDB . dotCN [ b ] ; } ) ) ;
BDFDB . LogUtils . log ( "Finished loading library." ) ;
2021-01-10 11:41:01 +01:00
window . BDFDB _Global = Object . assign ( {
started : true ,
loaded : true ,
PluginUtils : {
buildPlugin : BDFDB . PluginUtils . buildPlugin ,
cleanUp : BDFDB . PluginUtils . cleanUp
}
} , config ) ;
2021-02-05 21:45:34 +01:00
while ( PluginStores . delayed . loads . length ) PluginStores . delayed . loads . shift ( ) . load ( ) ;
while ( PluginStores . delayed . starts . length ) PluginStores . delayed . starts . shift ( ) . start ( ) ;
2020-09-19 21:32:19 +02:00
while ( pluginQueue . length ) {
let pluginName = pluginQueue . shift ( ) ;
if ( pluginName ) BDFDB . TimeUtils . timeout ( _ => BDFDB . BDUtils . reloadPlugin ( pluginName ) ) ;
}
} , "Could not initiate library!" , config . name ) ) ;
} ) ;
} ;
loadLibrary ( true ) ;
return class BDFDB _Frame {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
getDescription ( ) { return config . info . description ; }
2020-09-19 21:32:19 +02:00
2021-01-06 12:38:36 +01:00
load ( ) {
2020-09-22 23:30:15 +02:00
libraryInstance = this ;
2020-10-06 23:53:08 +02:00
Object . assign ( this , config . info , BDFDB . ObjectUtils . exclude ( config , "info" ) ) ;
2020-09-22 23:30:15 +02:00
if ( ! BDFDB . BDUtils . isPluginEnabled ( config . info . name ) ) BDFDB . BDUtils . enablePlugin ( config . info . name ) ;
}
2021-01-06 12:38:36 +01:00
start ( ) { }
stop ( ) {
2020-09-22 23:30:15 +02:00
if ( ! BDFDB . BDUtils . isPluginEnabled ( config . info . name ) ) BDFDB . BDUtils . enablePlugin ( config . info . name ) ;
}
2020-09-19 21:32:19 +02:00
getSettingsPanel ( collapseStates = { } ) {
2020-11-22 18:33:22 +01:00
let settingsPanel ;
2021-01-27 18:14:10 +01:00
let getString = ( type , key , property ) => {
2021-02-04 20:12:57 +01:00
return BDFDB . LanguageUtils . LibraryStringsCheck [ ` settings_ ${ key } _ ${ property } ` ] ? BDFDB . LanguageUtils . LibraryStringsFormat ( ` settings_ ${ key } _ ${ property } ` , BDFDB . BDUtils . getSettingsProperty ( "name" , BDFDB . BDUtils . settingsIds [ key ] ) || LibraryModules . StringUtils . upperCaseFirstChar ( key . replace ( /([A-Z])/g , " $1" ) ) ) : InternalBDFDB . defaults [ type ] [ key ] [ property ] ;
2020-12-24 11:46:03 +01:00
} ;
2020-11-22 18:33:22 +01:00
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( BDFDB , {
collapseStates : collapseStates ,
children : _ => {
let settingsItems = [ ] ;
2021-01-27 18:14:10 +01:00
for ( let key in choices ) settingsItems . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SettingsSaveItem , {
type : "Select" ,
plugin : InternalBDFDB ,
keys : [ "choices" , key ] ,
label : getString ( "choices" , key , "description" ) ,
note : getString ( "choices" , key , "note" ) ,
basis : "50%" ,
value : choices [ key ] ,
2021-02-04 20:51:20 +01:00
options : Object . keys ( LibraryConstants [ InternalBDFDB . defaults . choices [ key ] . items ] || { } ) . map ( p => ( {
value : p ,
label : BDFDB . LanguageUtils . LibraryStrings [ p ] || p
} ) ) ,
2021-02-05 21:45:34 +01:00
searchable : true
2021-01-27 18:14:10 +01:00
} ) ) ;
2020-12-24 11:51:12 +01:00
for ( let key in settings ) {
let nativeSetting = BDFDB . BDUtils . getSettings ( BDFDB . BDUtils . settingsIds [ key ] ) ;
2021-02-04 20:51:20 +01:00
let disabled = typeof InternalBDFDB . defaults . settings [ key ] . isDisabled == "function" && InternalBDFDB . defaults . settings [ key ] . isDisabled ( {
value : settings [ key ] ,
nativeValue : nativeSetting
} ) ;
2020-12-24 11:51:12 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : InternalBDFDB ,
2021-02-04 20:51:20 +01:00
disabled : disabled ,
2020-12-24 11:51:12 +01:00
keys : [ "settings" , key ] ,
2021-01-27 18:14:10 +01:00
label : getString ( "settings" , key , "description" ) ,
2021-02-04 20:51:20 +01:00
note : ( typeof InternalBDFDB . defaults . settings [ key ] . hasNote == "function" ? InternalBDFDB . defaults . settings [ key ] . hasNote ( {
value : settings [ key ] ,
nativeValue : nativeSetting ,
disabled : disabled
} ) : InternalBDFDB . defaults . settings [ key ] . hasNote ) && getString ( "settings" , key , "note" ) ,
value : ( typeof InternalBDFDB . defaults . settings [ key ] . getValue == "function" ? InternalBDFDB . defaults . settings [ key ] . getValue ( {
value : settings [ key ] ,
nativeValue : nativeSetting ,
disabled : disabled
} ) : true ) && ( settings [ key ] || nativeSetting )
2020-12-24 11:51:12 +01:00
} ) ) ;
}
2021-02-05 21:45:34 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SettingsItem , {
type : "Button" ,
label : BDFDB . LanguageUtils . LibraryStrings . update _check _info ,
dividerTop : true ,
basis : "20%" ,
2021-02-12 18:16:18 +01:00
children : BDFDB . LanguageUtils . LibraryStrings . check _for _updates ,
2021-02-05 21:45:34 +01:00
labelChildren : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . Clickable , {
children : BDFDB . ReactUtils . createElement ( InternalComponents . LibraryComponents . SvgIcon , {
name : InternalComponents . LibraryComponents . SvgIcon . Names . QUESTIONMARK ,
2021-02-06 20:27:22 +01:00
width : 20 ,
height : 20 ,
2021-02-05 21:45:34 +01:00
onClick : _ => BDFDB . ModalUtils . open ( BDFDB , {
header : "Plugins" ,
subHeader : "" ,
contentClassName : BDFDB . disCN . marginbottom20 ,
text : BDFDB . ObjectUtils . toArray ( Object . assign ( { } , window . PluginUpdates && window . PluginUpdates . plugins , PluginStores . updateData . plugins ) ) . map ( p => p . name ) . filter ( n => n ) . sort ( ) . join ( ", " )
} )
} )
} ) ,
onClick : _ => {
let loadingString = ` ${ BDFDB . LanguageUtils . LanguageStrings . CHECKING _FOR _UPDATES } - ${ BDFDB . LanguageUtils . LibraryStrings . please _wait } ` ;
let currentLoadingString = loadingString ;
let toastInterval , toast = BDFDB . NotificationUtils . toast ( loadingString , {
type : "info" ,
timeout : 0 ,
onClose : _ => { BDFDB . TimeUtils . clear ( toastInterval ) ; }
} ) ;
toastInterval = BDFDB . TimeUtils . interval ( _ => {
currentLoadingString = currentLoadingString . endsWith ( "....." ) ? loadingString : currentLoadingString + "." ;
toast . update ( currentLoadingString ) ;
} , 500 ) ;
2021-02-06 20:29:22 +01:00
BDFDB . PluginUtils . checkAllUpdates ( ) . then ( outdated => {
2021-02-05 21:45:34 +01:00
toast . close ( ) ;
if ( outdated > 0 ) BDFDB . NotificationUtils . toast ( BDFDB . LanguageUtils . LibraryStringsFormat ( "update_check_complete_outdated" , outdated ) , {
type : "danger"
} ) ;
else BDFDB . NotificationUtils . toast ( BDFDB . LanguageUtils . LibraryStrings . update _check _complete , {
type : "success"
} ) ;
} ) ;
}
} ) ) ;
2020-11-22 18:33:22 +01:00
return settingsItems ;
}
} ) ;
2020-09-19 21:32:19 +02:00
}
}
2020-09-26 20:11:27 +02:00
} ) ( ) ;
2020-11-19 19:59:02 +01:00
/* //META{"name":" */