@@ -73,7 +73,7 @@ export class Controller {
7373 frames : Frame [ ] = [ ] ;
7474 cookieJar = new $scramjet . CookieJar ( ) ;
7575
76- private rpc : RpcHelper < Controllerbound , SWbound > ;
76+ rpc : RpcHelper < Controllerbound , SWbound > ;
7777 private ready : Promise < void > ;
7878 private readyResolve : ( ) => void ;
7979
@@ -228,29 +228,58 @@ function yieldGetInjectScripts(
228228 "data:text/javascript;base64," +
229229 btoa ( `
230230 (()=>{
231- $scramjet.setWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));
231+ const { ScramjetClient, CookieJar, setWasm } = $scramjet;
232+
233+ setWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));
232234 delete self.WASM;
233- const cookieJar = new $scramjet.CookieJar();
235+
236+ const cookieJar = new CookieJar();
234237 const config = ${ JSON . stringify ( config ) } ;
235238 const sjconfig = ${ JSON . stringify ( sjconfig ) } ;
236239 cookieJar.load(${ cookieJar . dump ( ) } );
237240
238241 const prefix = new URL("${ prefix . href } ");
242+ const sw = navigator.serviceWorker.controller;
239243
240- $scramjet.loadAndHook({
241- context: {
242- interface: {
243- getInjectScripts: (${ yieldGetInjectScripts . toString ( ) } )(cookieJar, config, sjconfig, prefix),
244- codecEncode: ${ codecEncode . toString ( ) } ,
245- codecDecode: ${ codecDecode . toString ( ) } ,
246- },
247- prefix,
248- cookieJar,
249- config: sjconfig
244+ const context = {
245+ interface: {
246+ getInjectScripts: (${ yieldGetInjectScripts . toString ( ) } )(cookieJar, config, sjconfig, prefix),
247+ codecEncode: ${ codecEncode . toString ( ) } ,
248+ codecDecode: ${ codecDecode . toString ( ) } ,
250249 },
250+ prefix,
251+ cookieJar,
252+ config: sjconfig
253+ };
254+ function createFrameId() {
255+ return \`\${Array(8)
256+ .fill(0)
257+ .map(() => Math.floor(Math.random() * 36).toString(36))
258+ .join("")}\`;
259+ }
260+
261+ const frame = globalThis.frameElement;
262+ if (frame && !frame.name) {
263+ frame.name = createFrameId();
264+ }
265+
266+ const client = new ScramjetClient(globalThis, {
267+ context,
251268 transport: null,
252- })
269+ sendSetCookie: async (url, cookie) => {
270+ // sw.postMessage({
271+ // $controller$setCookie: {
272+ // url,
273+ // cookie
274+ // }
275+ // });
276+ },
277+ shouldPassthroughWebsocket: (url) => {
278+ return url === "wss://anura.pro/";
279+ }
280+ });
253281
282+ client.hook();
254283 document.currentScript.remove();
255284 })();
256285 ` )
0 commit comments