2020-09-10 08:56:11 +02:00
( _ => {
let DiscordClassModules , DiscordClasses , userId ;
window . global = window ;
2021-04-01 14:36:36 +02:00
const nativeRequire = window . require || ( _ => { } ) ;
const nativeWebpackJsonp = window . webpackJsonp ;
const getWindow = _ => {
let electron = nativeRequire ( "electron" ) ;
if ( electron && electron . remote ) {
let browserWindow = electron . remote . getCurrentWindow ( ) ;
2021-04-01 18:52:05 +02:00
if ( browserWindow ) return browserWindow ;
2021-04-01 14:36:36 +02:00
}
} ;
2021-04-01 18:58:57 +02:00
const respondToParent = ( data = { } ) => {
2020-09-10 08:56:11 +02:00
if ( window . parent && typeof window . parent . postMessage == "function" ) window . parent . postMessage ( data , "*" ) ;
if ( data . hostId != null && data . hostName != null ) {
let ipcRenderer = ( nativeRequire ( "electron" ) || { } ) . ipcRenderer ;
if ( ipcRenderer && typeof ipcRenderer . sendTo == "function" ) ipcRenderer . sendTo ( data . hostId , data . hostName , data ) ;
}
} ;
window . onload = function ( ) {
2021-04-01 14:36:36 +02:00
respondToParent ( {
2020-09-10 08:56:11 +02:00
origin : "DiscordPreview" ,
reason : "OnLoad"
} ) ;
} ;
window . onkeyup = function ( e ) {
2021-04-01 14:36:36 +02:00
respondToParent ( {
2020-09-10 08:56:11 +02:00
origin : "DiscordPreview" ,
reason : "KeyUp" ,
which : e . which
} ) ;
} ;
window . onmessage = function ( e ) {
let data = e . data || e ;
if ( typeof data === "object" && ( data . origin == "PluginRepo" || data . origin == "ThemeRepo" ) ) {
switch ( data . reason ) {
case "OnLoad" :
document . body . innerHTML = document . body . innerHTML . replace ( /\t|\n|\r/g , "" ) ;
if ( data . username ) {
document . body . innerHTML = document . body . innerHTML . replace ( /REPLACE_USERNAMESMALL/gi , data . username . toLowerCase ( ) ) ;
document . body . innerHTML = document . body . innerHTML . replace ( /REPLACE_USERNAME/gi , data . username ) ;
}
if ( data . id ) {
userId = data . id ;
document . body . innerHTML = document . body . innerHTML . replace ( /REPLACE_USERID/gi , data . id ) ;
}
if ( data . avatar ) document . body . innerHTML = document . body . innerHTML . replace ( /REPLACE_AVATAR/gi , data . avatar . split ( '"' ) . join ( '' ) + "?size=" ) ;
if ( data . discriminator ) document . body . innerHTML = document . body . innerHTML . replace ( /REPLACE_DISCRIMINATOR/gi , data . discriminator ) ;
if ( data . classes ) DiscordClasses = JSON . parse ( data . classes ) ;
2021-04-01 14:35:57 +02:00
if ( data . classModules ) DiscordClassModules = JSON . parse ( data . classModules ) ;
2020-09-10 08:56:11 +02:00
if ( disCN != undefined && DiscordClasses != undefined && DiscordClassModules != undefined ) {
let oldHTML = document . body . innerHTML . split ( "REPLACE_CLASS_" ) ;
let newHTML = oldHTML . shift ( ) ;
for ( let html of oldHTML ) {
let reg = /([A-z0-9_]+)(.+)/ . exec ( html ) ;
newHTML += disCN [ reg [ 1 ] ] + reg [ 2 ] ;
}
document . body . innerHTML = newHTML ;
}
2020-09-19 14:32:38 +02:00
if ( data . nativeCSS ) {
let theme = document . createElement ( "style" ) ;
2020-09-19 19:51:49 +02:00
theme . innerText = data . nativeCSS ;
2020-09-10 08:56:11 +02:00
document . head . appendChild ( theme ) ;
}
2021-07-05 17:42:48 +02:00
if ( data . bdCSS ) {
let theme = document . createElement ( "style" ) ;
theme . innerText = data . bdCSS ;
document . head . appendChild ( theme ) ;
}
2021-04-01 20:05:14 +02:00
if ( data . htmlClassName ) document . documentElement . className = data . htmlClassName ;
2021-04-01 19:56:24 +02:00
if ( window . parent && typeof window . parent . postMessage == "function" ) document . documentElement . classList . add ( "iframe-mode" ) ;
2021-04-01 20:05:14 +02:00
document . documentElement . classList . add ( "app-focused" ) ;
2020-09-10 08:56:11 +02:00
document . documentElement . classList . add ( "mouse-mode" ) ;
document . documentElement . classList . add ( "full-motion" ) ;
2021-04-01 14:36:36 +02:00
if ( data . titleBar ) document . querySelector ( ".preview-titlebar" ) . outerHTML = data . titleBar ;
2020-09-10 08:56:11 +02:00
document . body . firstElementChild . style . removeProperty ( "display" ) ;
2021-04-01 14:36:36 +02:00
document . addEventListener ( "click" , event => {
let button = getParent ( dotCNC . titlebarmacbutton + dotCN . titlebarwinbutton , event . target ) ;
if ( button ) {
let browserWindow = getWindow ( ) ;
if ( button . className . indexOf ( disCN . titlebarmacbuttonclose ) > - 1 || button . className . indexOf ( disCN . titlebarwinbuttonclose ) > - 1 ) {
if ( browserWindow ) browserWindow . close ( ) ;
2021-04-01 18:54:56 +02:00
respondToParent ( {
origin : "DiscordPreview" ,
reason : "close"
} ) ;
2021-04-01 14:36:36 +02:00
}
else if ( button . className . indexOf ( disCN . titlebarmacbuttonmax ) > - 1 || ( button . className . indexOf ( disCN . titlebarwinbuttonminmax ) > - 1 && button . parentElement . lastElementChild != button ) ) {
if ( browserWindow ) {
2020-09-10 08:56:11 +02:00
if ( browserWindow . isMaximized ( ) ) browserWindow . unmaximize ( ) ;
else browserWindow . maximize ( ) ;
}
2021-04-01 18:54:56 +02:00
respondToParent ( {
origin : "DiscordPreview" ,
reason : "maximize"
} ) ;
2020-09-10 08:56:11 +02:00
}
2021-04-01 14:36:36 +02:00
else if ( button . className . indexOf ( disCN . titlebarmacbuttonmin ) > - 1 || ( button . className . indexOf ( disCN . titlebarwinbuttonminmax ) > - 1 && button . parentElement . lastElementChild == button ) ) {
if ( browserWindow ) browserWindow . minimize ( ) ;
2021-04-01 18:54:56 +02:00
respondToParent ( {
origin : "DiscordPreview" ,
reason : "minimize"
} ) ;
2021-04-01 14:36:36 +02:00
}
}
} ) ;
2020-09-10 08:56:11 +02:00
break ;
case "NewTheme" :
case "CustomCSS" :
case "ThemeFixer" :
document . querySelectorAll ( "style." + data . reason ) . forEach ( theme => theme . remove ( ) ) ;
if ( data . checked ) {
let theme = document . createElement ( "style" ) ;
theme . classList . add ( data . reason ) ;
theme . innerText = data . css ;
document . head . appendChild ( theme ) ;
}
break ;
case "DarkLight" :
if ( data . checked ) {
document . documentElement . className = document . documentElement . className . replace ( new RegExp ( disCN . themedark , "g" ) , disCN . themelight ) ;
document . body . innerHTML = document . body . innerHTML . replace ( new RegExp ( disCN . themedark , "g" ) , disCN . themelight ) ;
}
else {
document . documentElement . className = document . documentElement . className . replace ( new RegExp ( disCN . themelight , "g" ) , disCN . themedark ) ;
document . body . innerHTML = document . body . innerHTML . replace ( new RegExp ( disCN . themelight , "g" ) , disCN . themedark ) ;
}
break ;
case "Normalize" :
let oldHTML2 = document . body . innerHTML . split ( 'class="' ) ;
let newHTML2 = oldHTML2 . shift ( ) ;
for ( let html of oldHTML2 ) {
html = html . split ( '"' ) ;
newHTML2 += 'class="' + ( data . checked ? html [ 0 ] . split ( " " ) . map ( n => n . replace ( /([A-z0-9]+?)-([A-z0-9_-]{6})/g , "$1-$2 da-$1" ) ) . join ( " " ) : html [ 0 ] . split ( " " ) . filter ( n => n . indexOf ( "da-" ) != 0 ) . join ( " " ) ) + '"' + html . slice ( 1 ) . join ( '"' ) ;
}
document . body . innerHTML = newHTML2 ;
break ;
}
}
} ;
let disCN = new Proxy ( { } , {
get : function ( list , item ) {
return getDiscordClass ( item , false ) . replace ( "#" , "" ) ;
}
} ) ;
let disCNS = new Proxy ( { } , {
get : function ( list , item ) {
return getDiscordClass ( item , false ) . replace ( "#" , "" ) + " " ;
}
} ) ;
let disCNC = new Proxy ( { } , {
get : function ( list , item ) {
return getDiscordClass ( item , false ) . replace ( "#" , "" ) + "," ;
}
} ) ;
let dotCN = new Proxy ( { } , {
get : function ( list , item ) {
let className = getDiscordClass ( item , true ) ;
return ( className . indexOf ( "#" ) == 0 ? "" : "." ) + className ;
}
} ) ;
let dotCNS = new Proxy ( { } , {
get : function ( list , item ) {
let className = getDiscordClass ( item , true ) ;
return ( className . indexOf ( "#" ) == 0 ? "" : "." ) + className + " " ;
}
} ) ;
let dotCNC = new Proxy ( { } , {
get : function ( list , item ) {
let className = getDiscordClass ( item , true ) ;
return ( className . indexOf ( "#" ) == 0 ? "" : "." ) + className + "," ;
}
} ) ;
let notCN = new Proxy ( { } , {
get : function ( list , item ) {
return ` :not(. ${ getDiscordClass ( item , true ) . split ( "." ) [ 0 ] } ) ` ;
}
} ) ;
let notCNS = new Proxy ( { } , {
get : function ( list , item ) {
return ` :not(. ${ getDiscordClass ( item , true ) . split ( "." ) [ 0 ] } ) ` ;
}
} ) ;
let notCNC = new Proxy ( { } , {
get : function ( list , item ) {
return ` :not(. ${ getDiscordClass ( item , true ) . split ( "." ) [ 0 ] } ), ` ;
}
} ) ;
let getDiscordClass = function ( item , selector ) {
2020-09-23 08:08:23 +02:00
let className = fallbackClassName = "Preview_undefined" ;
2020-09-10 08:56:11 +02:00
if ( DiscordClasses [ item ] === undefined ) {
2020-11-19 16:51:14 +01:00
if ( userId == "278543574059057154" ) console . warn ( ` %c[Preview]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , item + ' not found in DiscordClasses' ) ;
2020-09-10 08:56:11 +02:00
return className ;
}
else if ( ! Array . isArray ( DiscordClasses [ item ] ) || DiscordClasses [ item ] . length != 2 ) {
2020-11-19 16:51:14 +01:00
if ( userId == "278543574059057154" ) console . warn ( ` %c[Preview]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , item + ' is not an Array of Length 2 in DiscordClasses' ) ;
2020-09-10 08:56:11 +02:00
return className ;
}
else if ( DiscordClassModules [ DiscordClasses [ item ] [ 0 ] ] === undefined ) {
2020-11-19 16:51:14 +01:00
if ( userId == "278543574059057154" ) console . warn ( ` %c[Preview]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , DiscordClasses [ item ] [ 0 ] + ' not found in DiscordClassModules' ) ;
2020-09-10 08:56:11 +02:00
return className ;
}
2020-09-20 13:52:03 +02:00
else if ( [ DiscordClasses [ item ] [ 1 ] ] . flat ( ) . every ( prop => DiscordClassModules [ DiscordClasses [ item ] [ 0 ] ] [ prop ] === undefined ) ) {
2020-11-19 16:51:14 +01:00
if ( userId == "278543574059057154" ) console . warn ( ` %c[Preview]%c ` , 'color: #3a71c1; font-weight: 700;' , '' , DiscordClasses [ item ] [ 1 ] + ' not found in ' + DiscordClasses [ item ] [ 0 ] + ' in DiscordClassModules' ) ;
2020-09-10 08:56:11 +02:00
return className ;
}
else {
2020-09-20 13:52:03 +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:52:03 +02:00
}
2020-09-10 08:56:11 +02:00
className = DiscordClassModules [ DiscordClasses [ item ] [ 0 ] ] [ DiscordClasses [ item ] [ 1 ] ] ;
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-10 08:56:11 +02:00
}
2020-09-23 08:08:23 +02:00
return className || fallbackClassName ;
2020-09-10 08:56:11 +02:00
}
} ;
let 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 ;
} ;
window . require = function ( ) {
return _ => { } ;
} ;
window . getString = function ( obj ) {
let string = "" ;
if ( typeof obj == "string" ) string = obj ;
else if ( obj && obj . props ) {
if ( typeof obj . props . children == "string" ) string = obj . props . children ;
else if ( Array . isArray ( obj . props . children ) ) for ( let c of obj . props . children ) string += typeof c == "string" ? c : getString ( c ) ;
}
return string ;
} ;
2021-02-17 13:13:48 +01:00
window . webpackJsonp = {
push : _ => ( {
m : { } ,
c : { }
} )
2020-09-10 08:56:11 +02:00
} ;
window . fetch = function ( ) {
return new Promise ( _ => { } ) ;
} ;
let XMLHttpRequestProto = XMLHttpRequest . prototype ;
window . XMLHttpRequest = class { } ;
for ( let key of Object . keys ( XMLHttpRequestProto ) ) try {
if ( typeof XMLHttpRequestProto [ key ] == "function" ) window . XMLHttpRequest . prototype [ key ] = _ => { return new Promise ( _ => { } ) ; } ;
} catch ( err ) { }
let WebModulesFind = function ( filter ) {
const id = "PluginRepo-WebModules" ;
2021-02-17 13:13:48 +01:00
const req = nativeWebpackJsonp . push ( [ [ ] , { [ id ] : ( module , exports , req ) => module . exports = req } , [ [ id ] ] ] ) ;
2020-09-10 08:56:11 +02:00
delete req . m [ id ] ;
delete req . c [ id ] ;
for ( let m in req . c ) {
if ( req . c . hasOwnProperty ( m ) ) {
var module = req . c [ m ] . exports ;
if ( module && module . _ _esModule && module . default && filter ( module . default ) ) return module . default ;
if ( module && filter ( module ) ) return module ;
}
}
} ;
let WebModulesFindByProperties = function ( properties ) {
properties = Array . isArray ( properties ) ? properties : Array . from ( arguments ) ;
let module = WebModulesFind ( module => properties . every ( prop => module [ prop ] !== undefined ) ) ;
if ( ! module ) {
module = { } ;
for ( let property of properties ) module [ property ] = property ;
}
return module ;
} ;
let WebModulesFindByName = function ( name ) {
return WebModulesFind ( module => module . displayName === name ) || "" ;
} ;
window . BDV2 = { } ;
window . BDV2 . react = window . React ;
window . BDV2 . reactDom = window . ReactDOM ;
window . BDV2 . WebpackModules = { } ;
window . BDV2 . WebpackModules . find = WebModulesFind ;
window . BDV2 . WebpackModules . findByUniqueProperties = WebModulesFindByProperties ;
window . BDV2 . WebpackModules . findByDisplayName = WebModulesFindByName ;
window . BdApi = { } ;
window . BdApi . getData = _ => ( { } ) ;
window . BdApi . loadData = _ => ( { } ) ;
window . BdApi . saveData = _ => { } ;
window . BdApi . React = window . React ;
window . BdApi . ReactDOM = window . ReactDOM ;
window . BdApi . findModule = WebModulesFind ;
window . BdApi . findModuleByProps = WebModulesFindByProperties ;
window . BdApi . findModuleByDisplayName = WebModulesFindByName ;
} ) ( ) ;