mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-17 08:00:02 -04:00
refactor: everything
This commit is contained in:
parent
78e666d314
commit
506d99f9b6
37 changed files with 925 additions and 885 deletions
8
src/client/shared/requests/beacon.ts
Normal file
8
src/client/shared/requests/beacon.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
export default function (client, self) {
|
||||
// goodybye spyware~
|
||||
client.Proxy("navigator.sendBeacon", {
|
||||
apply(ctx) {
|
||||
ctx.return(null);
|
||||
},
|
||||
});
|
||||
}
|
29
src/client/shared/requests/fetch.ts
Normal file
29
src/client/shared/requests/fetch.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
// ts throws an error if you dont do window.fetch
|
||||
|
||||
import { encodeUrl, rewriteHeaders } from "../../shared";
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
client.Proxy("fetch", {
|
||||
apply(ctx) {
|
||||
ctx.args[0] = encodeUrl(ctx.args[0]);
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Headers", {
|
||||
construct(ctx) {
|
||||
ctx.args[0] = rewriteHeaders(ctx.args[0]);
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Request", {
|
||||
construct(ctx) {
|
||||
if (typeof ctx.args[0] === "string") ctx.args[0] = encodeUrl(ctx.args[0]);
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("Response.redirect", {
|
||||
apply(ctx) {
|
||||
ctx.args[0] = encodeUrl(ctx.args[0]);
|
||||
},
|
||||
});
|
||||
}
|
23
src/client/shared/requests/websocket.ts
Normal file
23
src/client/shared/requests/websocket.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { ScramjetClient } from "../../client";
|
||||
import { BareClient } from "../../shared";
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
const bare = new BareClient();
|
||||
|
||||
client.Proxy("WebSocket", {
|
||||
construct(ctx) {
|
||||
ctx.return(
|
||||
bare.createWebSocket(
|
||||
ctx.args[0],
|
||||
ctx.args[1],
|
||||
ctx.fn as typeof WebSocket,
|
||||
{
|
||||
"User-Agent": self.navigator.userAgent,
|
||||
Origin: client.url.origin,
|
||||
},
|
||||
ArrayBuffer.prototype
|
||||
)
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
18
src/client/shared/requests/xmlhttprequest.ts
Normal file
18
src/client/shared/requests/xmlhttprequest.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { encodeUrl, rewriteHeaders } from "../../shared";
|
||||
|
||||
export default function (client, self) {
|
||||
client.Proxy("XMLHttpRequest.prototype.open", {
|
||||
apply(ctx) {
|
||||
if (ctx.args[1]) ctx.args[1] = encodeUrl(ctx.args[1]);
|
||||
},
|
||||
});
|
||||
|
||||
client.Proxy("XMLHttpRequest.prototype.setRequestHeader", {
|
||||
apply(ctx) {
|
||||
let headerObject = Object.fromEntries([ctx.args]);
|
||||
headerObject = rewriteHeaders(headerObject);
|
||||
|
||||
ctx.args = Object.entries(headerObject)[0];
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue