@@ -450,51 +450,31 @@ window.Spicetify = {
450450 // Force all webpack modules to load
451451 const require = webpackChunkclient_web . push ( [ [ Symbol ( ) ] , { } , ( re ) => re ] ) ;
452452 while ( ! require . m ) await new Promise ( ( r ) => setTimeout ( r , 50 ) ) ;
453+ console . log ( "[spicetifyWrapper] Waiting for required webpack modules to load" ) ;
454+ let webpackDidCallback = false ;
455+ // https://github.com/webpack/webpack/blob/main/lib/runtime/OnChunksLoadedRuntimeModule.js
456+ require . O (
457+ null ,
458+ [ ] ,
459+ ( ) => {
460+ webpackDidCallback = true ;
461+ } ,
462+ 6
463+ ) ;
453464
454465 let chunks = Object . entries ( require . m ) ;
455466 let cache = Object . keys ( require . m ) . map ( ( id ) => require ( id ) ) ;
456467
457468 // For _renderNavLinks to work
458469 Spicetify . React = cache . find ( ( m ) => m ?. useMemo ) ;
459470
460- // Get all script tags matching root directory
461- // Some link tags modules are not included in require.m/unused
462- const scripts = [ ...document . querySelectorAll ( "script" ) ]
463- // Get scripts from root dir
464- . filter ( ( script ) => script . src ?. includes ( "xpui.app.spotify.com" ) )
465- // Filter out non-webpack scripts
466- . filter ( ( script ) => [ "extensions" , "spicetify" , "helper" , "theme" ] . every ( ( str ) => ! script . src ?. includes ( str ) ) ) ;
467-
468- //console.time("sanitize");
469- await Promise . all (
470- scripts . map ( async ( script ) => {
471- try {
472- const res = await fetch ( script . src ) ;
473- const text = await res . text ( ) ;
474- // remove every string from the content
475- const sanitizedText = text . replace ( / ( [ " ' ` ] ) (?: \\ .| [ ^ \\ \1] ) * ?\1/ g, "" ) ;
476- const src = script . src . split ( "/" ) . pop ( ) ;
477- console . log ( `[spicetifyWrapper] Waiting for ${ src } ` ) ;
478- for ( const pack of sanitizedText . match ( / (?< ! [ " ' ` ] ) (?: , | { ) ( \d + ) : ? \( ., ., ./ g) . map ( ( str ) => str . slice ( 0 , - 7 ) . slice ( 1 ) ) ) {
479- //console.debug(`[spicetifyWrapper] Waiting for ${pack} of ${src}`);
480- while ( ! require . m || ! Object . keys ( require . m ) . includes ( pack ) ) {
481- await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
482- }
483- }
484- console . log ( `[spicetifyWrapper] Loaded ${ src } ` ) ;
485- } catch ( e ) {
486- return console . error ( e ) ;
487- }
488- } )
489- ) . then ( ( ) => {
490- console . log ( "[spicetifyWrapper] All required webpack modules loaded" ) ;
491- //console.timeEnd("sanitize");
492- chunks = Object . entries ( require . m ) ;
493- cache = Object . keys ( require . m ) . map ( ( id ) => require ( id ) ) ;
494-
495- // Fire platformLoaded event there because of the sleep functions before
496- Spicetify . Events . platformLoaded . fire ( ) ;
497- } ) ;
471+ while ( ! webpackDidCallback ) {
472+ await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
473+ }
474+ console . log ( "[spicetifyWrapper] All required webpack modules loaded" ) ;
475+ chunks = Object . entries ( require . m ) ;
476+ cache = Object . keys ( require . m ) . map ( ( id ) => require ( id ) ) ;
477+ Spicetify . Events . platformLoaded . fire ( ) ;
498478
499479 const modules = cache
500480 . filter ( ( module ) => typeof module === "object" )
0 commit comments