mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -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(
|
/(application|text)\/javascript|module|importmap|undefined/.test(
|
||||||
node.attribs.type
|
node.attribs.type
|
||||||
) &&
|
) &&
|
||||||
node.children[0] !== undefined
|
node.children[0] !== undefined &&
|
||||||
&& !(node.attribs["data-scramjet"])
|
!node.attribs["data-scramjet"]
|
||||||
) {
|
) {
|
||||||
let js = node.children[0].data;
|
let js = node.children[0].data;
|
||||||
const htmlcomment = /<!--[\s\S]*?-->/g;
|
const htmlcomment = /<!--[\s\S]*?-->/g;
|
||||||
js = js.replace(htmlcomment, "");
|
js = js.replace(htmlcomment, "");
|
||||||
node.children[0].data = rewriteJs(js, origin);
|
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.name === "meta" && hasAttrib(node, "http-equiv")) {
|
||||||
if (node.attribs["http-equiv"] === "content-security-policy") {
|
if (node.attribs["http-equiv"] === "content-security-policy") {
|
||||||
|
@ -121,15 +121,22 @@ function traverseParsedHtml(node, origin?: URL) {
|
||||||
if (node.name === "head") {
|
if (node.name === "head") {
|
||||||
const scripts = [];
|
const scripts = [];
|
||||||
|
|
||||||
const codecs = new Element("script", { src: self.$scramjet.config["codecs"], "data-scramjet": "true" });
|
const codecs = new Element("script", {
|
||||||
const config = new Element("script", { "data-scramjet": "true" }, [], ElementType.Script);
|
src: self.$scramjet.config["codecs"],
|
||||||
config.children[0] = new Text(`self.$scramjet.config = ${JSON.stringify(self.$scramjet.config)};
|
"data-scramjet": "true",
|
||||||
self.$scramjet.codec = self.$scramjet.codecs[self.$scramjet.config.codec];`);
|
});
|
||||||
console.log(config.children[0]);
|
const shared = new Element("script", {
|
||||||
const shared = new Element("script", { src: self.$scramjet.config["shared"], "data-scramjet": "true" });
|
src: self.$scramjet.config["shared"],
|
||||||
const client = new Element("script", { src: self.$scramjet.config["client"], "data-scramjet": "true" });
|
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);
|
node.children.unshift(...scripts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { rewriteJs } from "./js";
|
import { rewriteJs } from "./js";
|
||||||
|
|
||||||
const clientscripts = ["codecs", "config", "shared", "client"];
|
const clientscripts = ["codecs", "shared", "client"];
|
||||||
export function rewriteWorkers(js: string | ArrayBuffer, origin?: URL) {
|
export function rewriteWorkers(js: string | ArrayBuffer, origin?: URL) {
|
||||||
let dest = origin.searchParams.get("dest");
|
let dest = origin.searchParams.get("dest");
|
||||||
let type = origin.searchParams.get("type");
|
let type = origin.searchParams.get("type");
|
||||||
|
@ -24,6 +24,8 @@ export function rewriteWorkers(js: string | ArrayBuffer, origin?: URL) {
|
||||||
if (rewritten instanceof Uint8Array) {
|
if (rewritten instanceof Uint8Array) {
|
||||||
rewritten = new TextDecoder().decode(rewritten);
|
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;
|
str += "\n" + rewritten;
|
||||||
|
|
||||||
dbg.log("Rewrite", type, dest, str);
|
dbg.log("Rewrite", type, dest, str);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue