1
- /* Copyright © 2024
2
-
3
- *
4
- * This file is part of bespoke/hooks.
5
- *
6
- * bespoke/hooks is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * bespoke/hooks is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with bespoke/hooks. If not, see <https://www.gnu.org/licenses/>.
1
+ /*
2
+ * Copyright (C) 2024 Delusoire
3
+ * SPDX-License-Identifier: GPL-3.0-or-later
18
4
*/
19
5
20
6
import { nsUrlHandlers } from "./protocol.js" ;
@@ -23,100 +9,103 @@ import { sources, type Transformer } from "./transform.js";
23
9
import { matchLast } from "./util.js" ;
24
10
25
11
declare global {
26
- var __applyTransforms : typeof applyTransforms ;
27
- var __interceptNavigationControlMessage : typeof interceptNavigationControlMessage ;
12
+ var __applyTransforms : typeof applyTransforms ;
13
+ var __interceptNavigationControlMessage : typeof interceptNavigationControlMessage ;
28
14
}
29
15
30
- export const applyTransforms = ( path : string ) => {
31
- const i = Paths . indexOf ( path as any ) ;
32
- const source = sources [ i ] ;
33
- console . info ( "loadResource" , { path, source } ) ;
34
- if ( ! source ) return path ;
35
- return source . getObjectURL ( ) ;
16
+ export const applyTransforms = ( path : string ) => {
17
+ const i = Paths . indexOf ( path as any ) ;
18
+ const source = sources [ i ] ;
19
+ console . info ( "loadResource" , { path, source } ) ;
20
+ if ( ! source ) return path ;
21
+ return source . getObjectURL ( ) ;
36
22
} ;
37
23
38
24
globalThis . __applyTransforms = applyTransforms ;
39
25
40
26
const rpc = "spotify:app:rpc:" ;
41
- function interceptNavigationControlMessage ( e : Event ) : boolean {
42
- const uri : string = ( e as any ) . data . data ;
43
- if ( ! uri . startsWith ( rpc ) ) {
44
- return true ;
45
- }
46
- const trimmedUri = uri . slice ( rpc . length ) ;
47
- if ( trimmedUri === "reload" ) {
48
- document . location . reload ( ) ;
49
- }
50
- {
51
- const hash = trimmedUri . slice ( 0 , 47 ) ;
52
- nsUrlHandlers . get ( hash ) ?.( trimmedUri ) ;
53
- }
54
- return false ;
27
+ function interceptNavigationControlMessage ( e : Event ) : boolean {
28
+ const uri : string = ( e as any ) . data . data ;
29
+ if ( ! uri . startsWith ( rpc ) ) {
30
+ return true ;
31
+ }
32
+ const trimmedUri = uri . slice ( rpc . length ) ;
33
+ if ( trimmedUri === "reload" ) {
34
+ document . location . reload ( ) ;
35
+ }
36
+ {
37
+ const hash = trimmedUri . slice ( 0 , 47 ) ;
38
+ nsUrlHandlers . get ( hash ) ?.( trimmedUri ) ;
39
+ }
40
+ return false ;
55
41
}
56
42
57
43
globalThis . __interceptNavigationControlMessage = interceptNavigationControlMessage ;
58
44
59
- export default async function ( transformer : Transformer ) {
60
- transformer (
61
- emit => str => {
62
- str = str . replace (
63
- / ( ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) = ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \. p \+ \3\. u \( [ a - z A - Z _ \$ ] [ \w \$ ] * \) ) / ,
64
- "$1,$2=await __applyTransforms($2)" ,
65
- ) ;
66
- const i = str . search ( '"Loading chunk "' ) ;
67
- const { index } = matchLast ( str . slice ( 0 , i ) , / = \( [ a - z A - Z _ \$ ] [ \w \$ ] * , [ a - z A - Z _ \$ ] [ \w \$ ] * \) = > \{ / g ) ;
68
- str = `${ str . slice ( 0 , index ! + 1 ) } async${ str . slice ( index ! + 1 ) } ` ;
45
+ export default async function ( transformer : Transformer ) {
46
+ transformer (
47
+ emit => str => {
48
+ str = str . replace (
49
+ / ( ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) = ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \. p \+ \3\. u \( [ a - z A - Z _ \$ ] [ \w \$ ] * \) ) / ,
50
+ "$1,$2=await __applyTransforms($2)" ,
51
+ ) ;
52
+ const i = str . search ( '"Loading chunk "' ) ;
53
+ const { index } = matchLast (
54
+ str . slice ( 0 , i ) ,
55
+ / = \( [ a - z A - Z _ \$ ] [ \w \$ ] * , [ a - z A - Z _ \$ ] [ \w \$ ] * \) = > \{ / g,
56
+ ) ;
57
+ str = `${ str . slice ( 0 , index ! + 1 ) } async${ str . slice ( index ! + 1 ) } ` ;
69
58
70
- str = str . replace (
71
- / ( n e w P r o m i s e \( \( ) ( \( [ a - z A - Z _ \$ ] [ \w \$ ] * , [ a - z A - Z _ \$ ] [ \w \$ ] * \) = > \{ v a r ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) = ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \. m i n i C s s F \( [ a - z A - Z _ \$ ] [ \w \$ ] * \) , ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) = \4\. p \+ \3) / ,
72
- "$1async$2,$5=await __applyTransforms($5)" ,
73
- ) ;
59
+ str = str . replace (
60
+ / ( n e w P r o m i s e \( \( ) ( \( [ a - z A - Z _ \$ ] [ \w \$ ] * , [ a - z A - Z _ \$ ] [ \w \$ ] * \) = > \{ v a r ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) = ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \. m i n i C s s F \( [ a - z A - Z _ \$ ] [ \w \$ ] * \) , ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) = \4\. p \+ \3) / ,
61
+ "$1async$2,$5=await __applyTransforms($5)" ,
62
+ ) ;
74
63
75
- emit ( ) ;
76
- return str ;
77
- } ,
78
- {
79
- glob : / ^ \/ x p u i \. j s / ,
80
- } ,
81
- ) ;
64
+ emit ( ) ;
65
+ return str ;
66
+ } ,
67
+ {
68
+ glob : / ^ \/ x p u i \. j s / ,
69
+ } ,
70
+ ) ;
82
71
83
- transformer (
84
- emit => str => {
85
- str = str . replace ( / ( \( " [ ^ " ] + s e n t r y .i o ) / , ",$1" ) ;
86
- emit ( ) ;
87
- return str ;
88
- } ,
89
- {
90
- glob : / ^ \/ x p u i \. j s / ,
91
- } ,
92
- ) ;
72
+ transformer (
73
+ emit => str => {
74
+ str = str . replace ( / ( \( " [ ^ " ] + s e n t r y .i o ) / , ",$1" ) ;
75
+ emit ( ) ;
76
+ return str ;
77
+ } ,
78
+ {
79
+ glob : / ^ \/ x p u i \. j s / ,
80
+ } ,
81
+ ) ;
93
82
94
- transformer (
95
- emit => str => {
96
- str = str . replace ( / ( " i n c o g n i t o - e n a b l e d " : [ a - z A - Z _ \$ ] [ \w \$ ] * ) / , '$1,employee:"1"' ) ;
97
- str = str . replace (
98
- / ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \( " a p p \. e n a b l e - d e v e l o p e r - m o d e " , ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \) / ,
99
- '$1("app.enable-developer-mode",$2);$1("app-developer",$2?2:0)' ,
100
- ) ;
101
- emit ( ) ;
102
- return str ;
103
- } ,
104
- {
105
- glob : / ^ \/ x p u i \. j s / ,
106
- } ,
107
- ) ;
83
+ transformer (
84
+ emit => str => {
85
+ str = str . replace ( / ( " i n c o g n i t o - e n a b l e d " : [ a - z A - Z _ \$ ] [ \w \$ ] * ) / , '$1,employee:"1"' ) ;
86
+ str = str . replace (
87
+ / ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \( " a p p \. e n a b l e - d e v e l o p e r - m o d e " , ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \) / ,
88
+ '$1("app.enable-developer-mode",$2);$1("app-developer",$2?2:0)' ,
89
+ ) ;
90
+ emit ( ) ;
91
+ return str ;
92
+ } ,
93
+ {
94
+ glob : / ^ \/ x p u i \. j s / ,
95
+ } ,
96
+ ) ;
108
97
109
- transformer (
110
- emit => str => {
111
- str = str . replace (
112
- / ( ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \. d a t a \. t y p e = = = (?: [ a - z A - Z _ \$ ] [ \w \$ ] * \. ) { 2 } N A V I G A T I O N & & ) / ,
113
- "$1__interceptNavigationControlMessage($2)&&" ,
114
- ) ;
115
- emit ( ) ;
116
- return str ;
117
- } ,
118
- {
119
- glob : / ^ \/ x p u i \. j s / ,
120
- } ,
121
- ) ;
98
+ transformer (
99
+ emit => str => {
100
+ str = str . replace (
101
+ / ( ( [ a - z A - Z _ \$ ] [ \w \$ ] * ) \. d a t a \. t y p e = = = (?: [ a - z A - Z _ \$ ] [ \w \$ ] * \. ) { 2 } N A V I G A T I O N & & ) / ,
102
+ "$1__interceptNavigationControlMessage($2)&&" ,
103
+ ) ;
104
+ emit ( ) ;
105
+ return str ;
106
+ } ,
107
+ {
108
+ glob : / ^ \/ x p u i \. j s / ,
109
+ } ,
110
+ ) ;
122
111
}
0 commit comments