2018-06-13 22:25:08 +00:00
/ *
EndPwn3 System ( settings UI )
Copyright 2018 EndPwn Project
Permission is hereby granted , free of charge , to any person obtaining a copy of this software and associated documentation files ( the "Software" ) , to deal in the Software without restriction , including without limitation the rights to use , copy , modify , merge , publish , distribute , sublicense , and / or sell copies of the Software , and to permit persons to whom the Software is furnished to do so , subject to the following conditions :
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software .
THE SOFTWARE IS PROVIDED "AS IS" , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
DO NOT EDIT THIS FILE ! Your bootstrap may overwrite changes to it , and you will lose your work !
EndPwn3 users : You can prevent this by creating a file in the same directory named DONTUPDATE
https : //github.com/endpwn/
* /
2018-07-12 00:32:22 +00:00
if ( window . $api === undefined && typeof $api != "undefined" ) {
console . warn (
"$api is defined, but window.$api is not! assuming we are running under epapi6 and exporting an empty object..."
) ;
exports = { } ;
} else
exports = {
manifest : {
replacements : [
{
signature : /{section:(\w)\.SectionTypes\.DIVIDER},{section:"logout",/g ,
payload :
'{section:$1.SectionTypes.DIVIDER},{section:"ENDPWN",label:"ΣndPwn Settings",element:window.BlankSettingsElement,color:"#0cc"},{section:$1.SectionTypes.DIVIDER},{section:"logout",'
}
]
} ,
init : function ( ) {
delete endpwn . settings . init ;
var currentSection = "" ;
/ * $ a p i . e v e n t s . l i s t e n ( ' E N D P W N _ P S E U D O _ I P C ' , m s g = > {
$api . localStorage . set ( 'customizer_signature' , JSON . parse ( msg . data ) . signature ) ;
console . log ( currentSection ) ;
renderSettings ( currentSection ) ;
} ) ; * /
window . BlankSettingsElement = $api . util . findConstructor (
"FormSection" ,
"FormSection"
) . FormSection ;
var buttons = $api . util . findFuncExports ( "button-" , "colorBlack" ) ;
var checkboxes = $api . util . findFuncExports ( "checkboxEnabled" ) ;
var misc = $api . util . findFuncExports ( "statusRed-" , "inputDefault" ) ;
var misc2 = $api . util . findFuncExports ( "multiInputField" ) ;
var headers = $api . util . findFuncExports ( "h5-" , "h5" ) ;
var panels = wc . findFunc ( "flexChild-" ) [ 0 ] . exports ;
var panels2 = $api . util . findFuncExports (
"errorMessage-" ,
"inputWrapper"
) ;
function createVerticalPanel ( ) {
return createElement ( "div" ) . withClass (
panels2 . vertical ,
"epButtonPanel"
2018-06-15 23:50:37 +00:00
) ;
2018-07-12 00:32:22 +00:00
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function createHorizontalPanel ( ) {
return createElement ( "div" ) . withClass (
panels . horizontal ,
"epButtonPanel"
2018-06-15 23:50:37 +00:00
) ;
2018-07-12 00:32:22 +00:00
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function createButton ( name ) {
return createElement ( "button" )
. withContents ( name )
. withClass (
buttons . button ,
buttons . lookFilled ,
buttons . colorBrand ,
buttons . sizeSmall ,
buttons . grow ,
"epMargin"
) ;
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function createWarnButton ( name ) {
return createElement ( "button" )
. withContents ( name )
. withClass (
buttons . button ,
buttons . lookOutlined ,
buttons . colorYellow ,
buttons . sizeSmall ,
buttons . grow ,
"epMargin"
) ;
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function createDangerButton ( name ) {
return createElement ( "button" )
. withContents ( name )
. withClass (
buttons . button ,
buttons . lookOutlined ,
buttons . colorRed ,
buttons . sizeSmall ,
buttons . grow ,
"epMargin"
) ;
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function createH2 ( text ) {
//h2-2gWE-o title-3sZWYQ size16-14cGz5 height20-mO2eIN weightSemiBold-NJexzi defaultColor-1_ajX0 defaultMarginh2-2LTaUL marginBottom20-32qID7
return createElement ( "h2" )
. withClass (
headers . h2 ,
headers . title ,
headers . size16 ,
headers . height20 ,
headers . weightSemiBold ,
headers . defaultColor ,
"epMargin"
)
. withText ( text ) ;
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function createH5 ( text ) {
return createElement ( "h5" )
. withClass (
headers . h5 ,
headers . title ,
headers . size12 ,
headers . height16 ,
headers . weightSemiBold
)
. withText ( text ) ;
2018-06-13 22:25:08 +00:00
}
2018-07-12 00:32:22 +00:00
function createInput ( v ) {
return createElement ( "input" )
. withClass (
misc . inputDefault ,
misc . input ,
misc . size16 ,
"epMargin"
)
. modify ( x => ( x . value = v ) ) ;
2018-06-13 22:25:08 +00:00
}
2018-07-12 00:32:22 +00:00
//<input class="checkboxEnabled-CtinEn checkbox-2tyjJg" type="checkbox">
//switchEnabled-V2WDBB switch-3wwwcV valueUnchecked-2lU_20 value-2hFrkk sizeDefault-2YlOZr size-3rFEHg themeDefault-24hCdX
//switchEnabled-V2WDBB switch-3wwwcV valueChecked-m-4IJZ value-2hFrkk sizeDefault-2YlOZr size-3rFEHg themeDefault-24hCdX
function updateSwitch ( s , w ) {
if ( s . checked ) {
w . classList . remove ( checkboxes . valueUnchecked . split ( " " ) [ 0 ] ) ;
w . classList . add ( checkboxes . valueChecked . split ( " " ) [ 0 ] ) ;
} else {
w . classList . remove ( checkboxes . valueChecked . split ( " " ) [ 0 ] ) ;
w . classList . add ( checkboxes . valueUnchecked . split ( " " ) [ 0 ] ) ;
}
}
function createSwitch ( c , i ) {
if ( c === undefined ) c = ( ) => { } ;
if ( i === undefined ) i = false ;
var s ,
w = createElement ( "div" )
2018-06-15 23:50:37 +00:00
. withClass (
2018-07-12 00:32:22 +00:00
checkboxes . switch ,
checkboxes . switchEnabled ,
checkboxes . size ,
checkboxes . sizeDefault ,
checkboxes . themeDefault
2018-06-15 23:50:37 +00:00
)
2018-07-12 00:32:22 +00:00
. withChildren (
( s = createElement ( "input" )
. withClass (
checkboxes . checkbox ,
checkboxes . checkboxEnabled
)
. modify ( x => ( x . type = "checkbox" ) )
. modify ( x => ( x . checked = i ) )
. modify (
x =>
( x . onchange = ( ) => {
updateSwitch ( s , w ) ;
c ( s . checked ) ;
} )
) )
) ;
updateSwitch ( s , w ) ;
return w ;
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
/ * f u n c t i o n a u t h o r i z e C u s t o m i z e r ( ) {
var endpoint = $api . internal . constants . API _HOST ;
var url = ` https:// ${ endpoint } /oauth2/authorize?client_id=436715820970803203&redirect_uri=https%3A%2F%2Fendpwn.cathoderay.tube%2Fauth%2Fdiscord%2Fintegratedcallback&response_type=code&scope=identify ` ;
var win = new window . electron . BrowserWindow ( {
width : 420 ,
height : 500 ,
transparent : false ,
frame : false ,
resizable : true ,
nodeIntegration : true
2018-06-15 23:50:37 +00:00
} ) ;
2018-07-12 00:32:22 +00:00
win . loadURL ( url ) ;
}
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function submitCustomizer ( d , b ) {
fetch ( 'https://endpwn.cathoderay.tube/set' , {
headers : {
'Content-type' : 'application/json'
} ,
method : 'POST' ,
body : JSON . stringify ( {
id : $me ( ) ,
signature : $api . localStorage . get ( 'customizer_signature' ) ,
discriminator : d ,
bot : b
} )
} ) . then ( r => {
r . text ( ) . then ( k => {
$api . ui . showDialog ( {
title : 'Server Response' ,
body : k
} ) ;
} ) ;
2018-06-15 23:50:37 +00:00
2018-07-12 00:32:22 +00:00
endpwn . customizer . update ( ) ;
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
} ) ;
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
} * /
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
function renderSettings ( e ) {
currentSection = e ;
if ( $ ( "#ep_settings" ) ) $ ( "#ep_settings" ) . remove ( ) ;
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
if ( e . section == "ENDPWN" ) {
var pane = $ ( ".content-column.default" ) ;
if ( ! pane ) return ;
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
//var needAuth = !$api.localStorage.get('customizer_signature');
2018-06-13 22:25:08 +00:00
2018-07-12 00:32:22 +00:00
var content = createElement ( "div" )
. withId ( "ep_settings" )
. withClass ( "flex-vertical" )
2018-06-13 22:25:08 +00:00
. withChildren (
2018-07-12 00:32:22 +00:00
createElement ( "div" )
. withClass ( "epSettingsHeader" )
. withText ( "ΣndPwn Settings" )
2018-06-13 22:25:08 +00:00
)
2018-07-12 00:32:22 +00:00
. appendTo ( pane ) ;
/ * i f ( ! $ a p i . l o c a l S t o r a g e . g e t ( ' c u s t o m i z e r _ s i g n a t u r e ' ) ) {
createHorizontalPanel ( )
. withChildren (
createButton ( "Authorize EndPwn Customizer" )
. modify ( x => x . onclick = authorizeCustomizer )
)
. appendTo ( content ) ;
}
else {
var discrim , bot ;
createVerticalPanel ( )
. withChildren (
createH5 ( 'Discriminator' ) ,
createHorizontalPanel ( )
. withChildren (
discrim = createInput ( endpwn . customizer . me . discrim ? endpwn . customizer . me . discrim : '' )
. withClass ( 'epDiscrimField' )
. modify ( x => x . maxLength = 4 ) ,
createVerticalPanel ( )
. withChildren (
createH5 ( 'Bot?' ) ,
bot = createSwitch ( ( ) => { } , endpwn . customizer . me . bot )
) ,
createButton ( "Submit" )
. modify ( x => x . onclick = ( ) => submitCustomizer ( discrim . value , bot . children [ 0 ] . checked ) )
)
)
. appendTo ( content ) ;
} * /
createElement ( "div" )
. withClass ( panels . horizontal , "epButtonPanel" )
2018-06-13 22:25:08 +00:00
. withChildren (
2018-07-12 00:32:22 +00:00
createButton ( "Open Data Folder" ) . modify (
x =>
( x . onclick = ( ) => {
electron . shell . openExternal ( $api . data ) ;
} )
) ,
createWarnButton ( "Restart in safe mode" ) . modify (
x => ( x . onclick = endpwn . safemode )
) ,
createDangerButton ( "Uninstall EndPwn" ) . modify (
x => ( x . onclick = endpwn . uninstall )
)
/ * c r e a t e B u t t o n ( " T o g g l e C u s t o m i z e r " )
. modify ( x => x . onclick = function ( ) {
window . _ _ _ _customizerToggled = ! window . _ _ _ _customizerToggled ;
$api . localStorage . set ( "customizerToggled" , window . _ _ _ _customizerToggled ) ;
const restart = confirm ( "For toggle to be in full effect, you will need to refresh. Press \"OK\" to refresh or \"Cancel\" to refresh later on your own." ) ;
if ( restart ) {
window . electron . getCurrentWindow ( ) . reload ( ) ;
}
} ) * /
2018-06-13 22:25:08 +00:00
)
. appendTo ( content ) ;
}
}
2018-07-12 00:32:22 +00:00
$api . events . hook ( "USER_SETTINGS_MODAL_SET_SECTION" , renderSettings ) ;
$api . events . hook ( "USER_SETTINGS_MODAL_INIT" , e =>
setTimeout ( _ => renderSettings ( e ) , 200 )
) ;
2018-06-13 22:25:08 +00:00
}
2018-07-12 00:32:22 +00:00
} ;