scuffed as fuck blob rewriting

This commit is contained in:
velzie 2024-07-30 08:19:14 -04:00
parent 9b9905f640
commit 12b17bc3b4
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
2 changed files with 42 additions and 1 deletions

View file

@ -6,7 +6,18 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
construct({ args }) {
if (args[0] instanceof URL) args[0] = args[0].href;
if (args[0].startsWith("blob:") || args[0].startsWith("data:")) {
// TODO
if (args[0].startsWith("blob:")) {
args[0] =
"data:application/javascript;base64," + btoa(syncfetch(args[0]));
}
args[0] = "/scramjet/worker?data=" + args[0];
if (args[1] && args[1].type === "module") {
args[0] += "&type=module";
}
args[0] += "&origin=" + encodeURIComponent(client.url.origin);
return;
}
@ -18,3 +29,11 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
},
});
}
function syncfetch(url: string) {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send();
return xhr.responseText;
}