@ -1,92 +1,18 @@
import { openModal , closeModal } from '@vizality/modal' ;
import { getModule ByDisplayName, getModule , instance } from '@vizality/webpack' ;
import { getModule , contextMenu } from '@vizality/webpack' ;
import { SettingsContextMenu } from '@vizality/components/vizality' ;
import { Content , Layout } from '@vizality/components/dashboard' ;
import { toPlural , toTitleCase } from '@vizality/util/string' ;
import { toPlural } from '@vizality/util/string' ;
import { Confirm , ContextMenu , Modal } from '@vizality/components' ;
import { joinClassNames } from '@vizality/util/dom' ;
import { joinClassNames , waitForElement } from '@vizality/util/dom' ;
import { patch , unpatch } from '@vizality/patcher' ;
import { Builtin } from '@vizality/entities' ;
import { Messages } from '@vizality/i18n' ;
import React from 'react' ;
import { webFrame } from 'electron'
import SettingsPage from './components/Settings' ;
/ * *
* Contributed by DoggyBootsy , originally written by Strencher .
* /
{
const modules = Object . values ( instance . m ) . filter ( e => e . toString ( ) . search ( /openContextMenuLazy[)(]/ ) > - 1 ) ;
const regex = [
{
regex : /return Promise\.all\(\[(.*?)\]\)\.then\(\D+(.+?)\)\)/ ,
parse ( match ) {
return {
imports : matchAll ( /\(([\de]+)\)/g , match [ 0 ] ) . map ( e => Number ( e ) ) ,
main : match [ 1 ]
} ;
}
} ,
{
regex : /return Promise\.resolve\(\)\.then\(\D+(.+?)\)/ ,
parse ( match ) {
return {
imports : [ ] ,
main : match [ 0 ]
} ;
}
} ,
{
regex : /return [rn]\.e\((\d+)\)\.then\(\D+(\d+)\)\)/ ,
parse ( match ) {
return {
imports : [ match [ 0 ] ] ,
main : match [ 0 ]
} ;
}
}
] ;
function matchAll ( regex , input , parent = false ) {
const output = [ ] ;
let matches ,
lastIndex = 0 ;
while ( matches = regex . exec ( input . slice ( lastIndex ) ) ) {
if ( ! regex . global ) lastIndex += matches . index + matches [ 0 ] . length ;
if ( parent ) output . push ( matches ) ;
else {
const [ , ... match ] = matches ;
output . push ( match ) ;
}
}
return output ;
}
const found = [ ] ;
for ( let i = 0 ; i < modules . length ; i ++ ) {
const str = modules [ i ] . toString ( ) ;
for ( let i2 = 0 ; i2 < regex . length ; i2 ++ ) {
const { regex : reg , parse } = regex [ i2 ] ;
if ( ! reg . test ( str ) ) continue ;
const result = matchAll ( reg , str ) . map ( res => ( { ... parse ( res ) , module : modules [ i ] , reg } ) ) ;
found . push ( ... result ) ;
break ;
}
}
Promise . all ( found . map ( item => {
try {
const imports = item . imports . map ( i => instance . e ( i ) ) ;
return Promise . all ( imports ) . then ( instance . bind ( instance , item . main ) ) . catch ( ( ) => void 0 ) ;
} catch ( error ) {
return Promise . resolve ( ) ;
}
} ) ) ;
}
/ * *
* The settings page categories .
* /
@ -183,22 +109,59 @@ export default class Settings extends Builtin {
) ) ;
}
async waitFor ( filter ) {
const exists = await getModule ( filter , true , true )
if ( exists ) return exists
return await this . waitFor ( filter )
}
async patchSettingsContextMenu ( ) {
const DiscordSettingsContextMenu = await getModule ( m => m . default ? . displayName === 'UserSettingsCogContextMenu' , true ) ;
const { panels } = await getModule ( 'panels' , 'downloadProgressCircle' , 'hasNotice' , true )
const { container } = await getModule ( 'container' , 'usernameContainer' , 'godlike' , true )
const { button } = await getModule ( 'button' , 'disabled' , 'enabled' , true )
await waitForElement ( ` . ${ panels } > . ${ container } . ${ button } :last-child ` ) ;
const settingsNode = webFrame . top . context . document . querySelector ( ` . ${ panels } > . ${ container } . ${ button } :last-child ` ) ;
settingsNode . _ _reactProps$ . onContextMenu ( {
stopPropagation ( ) { } ,
currentTarget : { contains : ( ) => true } ,
preventDefault ( ) { }
} ) ;
contextMenu . closeContextMenu ( ) ;
const DiscordSettingsContextMenu = await this . waitFor ( m => {
if ( ! m . default ) return ;
const string = String ( m . default ) ;
return string . includes ( '.AnalyticsLocationProvider,' ) && string . includes ( '.createElement(' ) && ! string . includes ( 'return function' ) && ! m .
default . displayName ;
} ) ;
patch ( 'vz-settings-context-menu' , DiscordSettingsContextMenu , 'default' , ( _ , res ) => {
const items = res . props . children . find ( child => Array . isArray ( child ) ) ;
items . push (
< >
< ContextMenu . Separator / >
< ContextMenu . Item
id = 'vizality-dashboard'
label = 'Vizality'
action = { ( ) => vizality . api . routes . navigateTo ( 'dashboard' ) }
>
{ SettingsContextMenu . type ( ) . props . children }
< / C o n t e x t M e n u . I t e m >
< / >
) ;
const { children } = res . props ;
const old = children . type ;
children . type = ( ) => {
const result = old ( children . props ) ;
const items = result . props . children . props . children . find ( child => Array . isArray ( child ) ) ;
items . push (
< >
< ContextMenu . Separator / >
< ContextMenu . Item
id = 'vizality-dashboard'
label = 'Vizality'
action = { ( ) => vizality . api . routes . navigateTo ( 'dashboard' ) }
>
{ SettingsContextMenu . type ( ) . props . children }
< / C o n t e x t M e n u . I t e m >
< / >
) ;
return result ;
} ;
} ) ;
}