mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
parent
a7f882a3c5
commit
f5d4f00ae8
4 changed files with 12 additions and 18 deletions
|
@ -1,5 +1,3 @@
|
||||||
import BareClient from "@mercuryworkshop/bare-mux";
|
|
||||||
|
|
||||||
import "./scope.ts";
|
import "./scope.ts";
|
||||||
import "./window.ts";
|
import "./window.ts";
|
||||||
import "./event.ts";
|
import "./event.ts";
|
||||||
|
@ -23,10 +21,5 @@ declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
$s: any;
|
$s: any;
|
||||||
$sImport: any;
|
$sImport: any;
|
||||||
$client: BareClient;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new BareClient();
|
|
||||||
|
|
||||||
export { client };
|
|
|
@ -1,19 +1,13 @@
|
||||||
// ts throws an error if you dont do window.fetch
|
// ts throws an error if you dont do window.fetch
|
||||||
|
|
||||||
import { encodeUrl, rewriteHeaders } from "../shared";
|
import { encodeUrl, rewriteHeaders } from "../shared";
|
||||||
import { client } from "../index";
|
|
||||||
|
|
||||||
window.fetch = new Proxy(window.fetch, {
|
window.fetch = new Proxy(window.fetch, {
|
||||||
async apply(target, thisArg, argArray) {
|
apply(target, thisArg, argArray) {
|
||||||
// @ts-expect-error
|
argArray[0] = encodeUrl(argArray[0]);
|
||||||
const response = await client.fetch(...argArray);
|
|
||||||
|
|
||||||
return new Response(response.body, {
|
return Reflect.apply(target, thisArg, argArray);
|
||||||
status: response.status,
|
},
|
||||||
statusText: response.statusText,
|
|
||||||
headers: response.headers
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Headers = new Proxy(Headers, {
|
Headers = new Proxy(Headers, {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { decodeUrl } from "../../shared/rewriters/url";
|
import { decodeUrl } from "../../shared/rewriters/url";
|
||||||
import { client } from "../index";
|
import { BareClient } from "../shared";
|
||||||
|
const client = new BareClient();
|
||||||
|
|
||||||
WebSocket = new Proxy(WebSocket, {
|
WebSocket = new Proxy(WebSocket, {
|
||||||
construct(target, args) {
|
construct(target, args) {
|
||||||
|
|
|
@ -15,6 +15,12 @@ export const windowProxy = new Proxy(window, {
|
||||||
return window.parent;
|
return window.parent;
|
||||||
} else if (propIsString && prop === "$scramjet") {
|
} else if (propIsString && prop === "$scramjet") {
|
||||||
return;
|
return;
|
||||||
|
} else if (propIsString && prop === "addEventListener") {
|
||||||
|
return new Proxy(window.addEventListener, {
|
||||||
|
apply(target1, thisArg, argArray) {
|
||||||
|
window.addEventListener(argArray[0], argArray[1]);
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = Reflect.get(target, prop);
|
const value = Reflect.get(target, prop);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue