This commit is contained in:
velzie 2024-10-10 20:38:06 -04:00
commit 41288749e4
11 changed files with 31 additions and 24 deletions

View file

@ -18,6 +18,7 @@
"no-undef": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{

View file

@ -18,7 +18,10 @@
"lint": "eslint ./src/ --ext .ts",
"lint:fix": "eslint ./src/ --ext .ts --fix"
},
"files": ["dist", "lib"],
"files": [
"dist",
"lib"
],
"keywords": [],
"author": "",
"license": "ISC",

View file

@ -108,7 +108,7 @@ export class ScramjetClient {
resolve(data.port);
}
});
}),
})
);
}
@ -239,7 +239,7 @@ export class ScramjetClient {
h.construct = function (
constructor: any,
argArray: any[],
newTarget: AnyFunction,
newTarget: AnyFunction
) {
let returnValue: any = undefined;
let earlyreturn = false;
@ -354,7 +354,7 @@ export class ScramjetClient {
RawTrap<T>(
target: any,
prop: string,
descriptor: Trap<T>,
descriptor: Trap<T>
): PropertyDescriptor {
if (!target) return;
if (!prop) return;

View file

@ -52,7 +52,7 @@ export default function (client: ScramjetClient, self: typeof window) {
for (const element of attrObject[attr]) {
const descriptor = nativeGetOwnPropertyDescriptor(
element.prototype,
attr,
attr
);
Object.defineProperty(element.prototype, attr, {
get() {
@ -80,7 +80,7 @@ export default function (client: ScramjetClient, self: typeof window) {
base: new URL(client.url.origin),
origin: new URL(client.url.origin),
} as URLMeta,
true,
true
);
} else if (["srcset", "imagesrcset"].includes(attr)) {
value = rewriteSrcset(value, client.meta);
@ -171,9 +171,10 @@ export default function (client: ScramjetClient, self: typeof window) {
// since the prototype chain is fucked
const style = ctx.get() as CSSStyleDeclaration;
return new Proxy(style, {
get(t, p) {
let v = Reflect.get(t, p);
const v = Reflect.get(t, p);
if (typeof v === "function") {
return new Proxy(v, {
apply(target, thisArg, argArray) {
@ -189,6 +190,7 @@ export default function (client: ScramjetClient, self: typeof window) {
if (v == "" || typeof v !== "string") {
return Reflect.set(t, p, v);
}
return Reflect.set(t, p, rewriteCss(v, client.meta));
},
});
@ -216,8 +218,8 @@ export default function (client: ScramjetClient, self: typeof window) {
return atob(
client.natives["Element.prototype.getAttribute"].call(
ctx.this,
"data-scramjet-script-source-src",
),
"data-scramjet-script-source-src"
)
);
}
if (ctx.this instanceof self.HTMLStyleElement) {
@ -307,7 +309,7 @@ export default function (client: ScramjetClient, self: typeof window) {
ctx.args[0],
client.cookieStore,
client.meta,
false,
false
);
}
},
@ -319,7 +321,7 @@ export default function (client: ScramjetClient, self: typeof window) {
ctx.args[0],
client.cookieStore,
client.meta,
true,
true
);
},
});
@ -330,7 +332,7 @@ export default function (client: ScramjetClient, self: typeof window) {
ctx.args[0],
client.cookieStore,
client.meta,
false,
false
);
},
});

View file

@ -14,12 +14,6 @@ export function disabled(client: ScramjetClient, self: Self) {
export default function (client: ScramjetClient, self: Self) {
let registration;
client.Proxy("Worklet.prototype.addModule", {
apply(ctx) {
ctx.args[0] = encodeUrl(ctx.args[0], client.meta);
},
});
client.Proxy("EventTarget.prototype.addEventListener", {
apply(ctx) {
if (registration === ctx.this) {

View file

@ -9,7 +9,8 @@ export default function (client: ScramjetClient, self: Self) {
client.Trap("IDBDatabase.prototype.name", {
get(ctx) {
let name = ctx.get() as string;
const name = ctx.get() as string;
return name.substring(name.indexOf("@") + 1);
},
});

View file

@ -47,7 +47,7 @@ export default function (client: ScramjetClient, self: Self) {
body: ctx.args[0],
});
let now = performance.now();
const now = performance.now();
while (view.getUint8(0) === 0) {
if (performance.now() - now > 1000) {
throw new Error("xhr timeout");
@ -85,12 +85,14 @@ export default function (client: ScramjetClient, self: Self) {
client.RawTrap(ctx.this, "response", {
get() {
if (ctx.this.responseType === "arraybuffer") return bodyab.buffer;
return body;
},
});
client.RawTrap(ctx.this, "responseXML", {
get() {
const parser = new DOMParser();
return parser.parseFromString(body, "text/xml");
},
});
@ -104,6 +106,7 @@ export default function (client: ScramjetClient, self: Self) {
return (header: string) => {
const re = new RegExp(`^${header}: (.*)$`, "m");
const match = re.exec(headers);
return match ? match[1] : null;
};
},

View file

@ -66,6 +66,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
if (typeof v === "string" && v.includes("scramjet")) {
debugger;
}
return v;
};

View file

@ -219,7 +219,7 @@ function traverseParsedHtml(
) {
let js = node.children[0].data;
// node.attribs[`data-scramjet-script-source-src`] = btoa(js);
node.attribs[`data-scramjet-script-source-src`] = bytesToBase64(
node.attribs["data-scramjet-script-source-src"] = bytesToBase64(
new TextEncoder().encode(js)
);
const htmlcomment = /<!--[\s\S]*?-->/g;
@ -272,6 +272,7 @@ export function rewriteSrcset(srcset: string, meta: URLMeta) {
function base64ToBytes(base64) {
const binString = atob(base64);
return Uint8Array.from(binString, (m) => m.codePointAt(0));
}
@ -279,5 +280,6 @@ function bytesToBase64(bytes: Uint8Array) {
const binString = Array.from(bytes, (byte) =>
String.fromCodePoint(byte)
).join("");
return btoa(binString);
}

View file

@ -45,7 +45,7 @@ export function decodeUrl(url: string | URL) {
if (
tryCanParseURL(url)?.pathname.startsWith(
self.$scramjet.config.prefix + "worker",
self.$scramjet.config.prefix + "worker"
)
) {
return new URL(new URL(url).searchParams.get("origin")).href;
@ -55,7 +55,7 @@ export function decodeUrl(url: string | URL) {
return url;
} else if (tryCanParseURL(url)) {
return self.$scramjet.codec.decode(
url.slice((location.origin + self.$scramjet.config.prefix).length),
url.slice((location.origin + self.$scramjet.config.prefix).length)
);
} else {
return url;

View file

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Scramjet</title>
<link rel="icon" href="favicon.webp">
<link rel="icon" href="favicon.webp" />
<link rel="prefetch" href="/scram/scramjet.worker.js" />
<link rel="prefetch" href="/scram/scramjet.shared.js" />
<link