mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
fix bootstrapper somewhat (bootstrapper still does not work on first load)
This commit is contained in:
parent
17b440ea37
commit
5d61913f65
2 changed files with 21 additions and 12 deletions
|
@ -95,14 +95,14 @@ function traverseParsedHtml(node, origin?: URL) {
|
|||
/(application|text)\/javascript|module|importmap|undefined/.test(
|
||||
node.attribs.type
|
||||
) &&
|
||||
node.children[0] !== undefined
|
||||
&& !(node.attribs["data-scramjet"])
|
||||
node.children[0] !== undefined &&
|
||||
!node.attribs["data-scramjet"]
|
||||
) {
|
||||
let js = node.children[0].data;
|
||||
const htmlcomment = /<!--[\s\S]*?-->/g;
|
||||
js = js.replace(htmlcomment, "");
|
||||
node.children[0].data = rewriteJs(js, origin);
|
||||
console.log(node.children)
|
||||
console.log(node.children);
|
||||
}
|
||||
if (node.name === "meta" && hasAttrib(node, "http-equiv")) {
|
||||
if (node.attribs["http-equiv"] === "content-security-policy") {
|
||||
|
@ -121,15 +121,22 @@ function traverseParsedHtml(node, origin?: URL) {
|
|||
if (node.name === "head") {
|
||||
const scripts = [];
|
||||
|
||||
const codecs = new Element("script", { src: self.$scramjet.config["codecs"], "data-scramjet": "true" });
|
||||
const config = new Element("script", { "data-scramjet": "true" }, [], ElementType.Script);
|
||||
config.children[0] = new Text(`self.$scramjet.config = ${JSON.stringify(self.$scramjet.config)};
|
||||
self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec];`);
|
||||
console.log(config.children[0]);
|
||||
const shared = new Element("script", { src: self.$scramjet.config["shared"], "data-scramjet": "true" });
|
||||
const client = new Element("script", { src: self.$scramjet.config["client"], "data-scramjet": "true" });
|
||||
const codecs = new Element("script", {
|
||||
src: self.$scramjet.config["codecs"],
|
||||
"data-scramjet": "true",
|
||||
});
|
||||
const shared = new Element("script", {
|
||||
src: self.$scramjet.config["shared"],
|
||||
onload: `self.$scramjet.config = ${JSON.stringify(self.$scramjet.config)};
|
||||
self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec];`,
|
||||
"data-scramjet": "true",
|
||||
});
|
||||
const client = new Element("script", {
|
||||
src: self.$scramjet.config["client"],
|
||||
"data-scramjet": "true",
|
||||
});
|
||||
|
||||
scripts.push(codecs, config, shared, client);
|
||||
scripts.push(codecs, shared, client);
|
||||
|
||||
node.children.unshift(...scripts);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { rewriteJs } from "./js";
|
||||
|
||||
const clientscripts = ["codecs", "config", "shared", "client"];
|
||||
const clientscripts = ["codecs", "shared", "client"];
|
||||
export function rewriteWorkers(js: string | ArrayBuffer, origin?: URL) {
|
||||
let dest = origin.searchParams.get("dest");
|
||||
let type = origin.searchParams.get("type");
|
||||
|
@ -24,6 +24,8 @@ export function rewriteWorkers(js: string | ArrayBuffer, origin?: URL) {
|
|||
if (rewritten instanceof Uint8Array) {
|
||||
rewritten = new TextDecoder().decode(rewritten);
|
||||
}
|
||||
str += `self.$scramjet.config = ${JSON.stringify(self.$scramjet.config)};
|
||||
self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec];\n`;
|
||||
str += "\n" + rewritten;
|
||||
|
||||
dbg.log("Rewrite", type, dest, str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue