@@ -5,36 +5,13 @@ import { URLMeta, rewriteUrl } from "@rewriters/url";
55import { rewriteCss } from "@rewriters/css" ;
66import { rewriteJs } from "@rewriters/js" ;
77import { CookieJar } from "@/shared/cookie" ;
8- import { config } from "@/shared" ;
8+ import { config , iface } from "@/shared" ;
99import { htmlRules } from "@/shared/htmlRules" ;
1010
11- export function getInjectScripts < T > (
12- cookieStore : CookieJar ,
13- script : ( src : string ) => T
14- ) : T [ ] {
15- const dump = JSON . stringify ( cookieStore . dump ( ) ) ;
16- const injected = `
17- self.COOKIE = ${ dump } ;
18- $scramjetLoadClient().loadAndHook(${ JSON . stringify ( config ) } );
19- if ("document" in self && document?.currentScript) {
20- document.currentScript.remove();
21- }
22- ` ;
23-
24- // for compatibility purpose
25- const base64Injected = bytesToBase64 ( encoder . encode ( injected ) ) ;
26-
27- return [
28- script ( config . files . wasm ) ,
29- script ( config . files . all ) ,
30- script ( "data:application/javascript;base64," + base64Injected ) ,
31- ] ;
32- }
33-
3411const encoder = new TextEncoder ( ) ;
3512function rewriteHtmlInner (
3613 html : string ,
37- cookieStore : CookieJar ,
14+ cookieJar : CookieJar ,
3815 meta : URLMeta ,
3916 fromTop : boolean = false ,
4017 preRewrite ?: ( handler : DomHandler ) => void ,
@@ -46,7 +23,7 @@ function rewriteHtmlInner(
4623 parser . write ( html ) ;
4724 parser . end ( ) ;
4825 if ( preRewrite ) preRewrite ( handler ) ;
49- traverseParsedHtml ( handler . root , cookieStore , meta ) ;
26+ traverseParsedHtml ( handler . root , cookieJar , meta ) ;
5027
5128 function findhead ( node ) {
5229 if ( node . type === ElementType . Tag && node . name === "head" ) {
@@ -69,7 +46,9 @@ function rewriteHtmlInner(
6946 }
7047
7148 const script = ( src : string ) => new Element ( "script" , { src } ) ;
72- head . children . unshift ( ...getInjectScripts ( cookieStore , script ) ) ;
49+ head . children . unshift (
50+ ...iface . getInjectScripts ( meta , handler , config , cookieJar , script )
51+ ) ;
7352 }
7453
7554 if ( postRewrite ) postRewrite ( handler ) ;
0 commit comments