mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
start bootstrapper
This commit is contained in:
parent
034c8e1c6d
commit
17b440ea37
15 changed files with 166 additions and 131 deletions
|
@ -1,5 +1,5 @@
|
|||
import { Parser } from "htmlparser2";
|
||||
import { DomHandler, Element } from "domhandler";
|
||||
import { ElementType, Parser } from "htmlparser2";
|
||||
import { DomHandler, Element, Text } from "domhandler";
|
||||
import { hasAttrib } from "domutils";
|
||||
import render from "dom-serializer";
|
||||
import { encodeUrl } from "./url";
|
||||
|
@ -8,7 +8,7 @@ import { rewriteJs } from "./js";
|
|||
|
||||
export function isScramjetFile(src: string) {
|
||||
let bool = false;
|
||||
["codecs", "client", "shared", "worker", "config"].forEach((file) => {
|
||||
["codecs", "client", "shared", "worker"].forEach((file) => {
|
||||
if (src === self.$scramjet.config[file]) bool = true;
|
||||
});
|
||||
|
||||
|
@ -96,11 +96,13 @@ function traverseParsedHtml(node, origin?: URL) {
|
|||
node.attribs.type
|
||||
) &&
|
||||
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)
|
||||
}
|
||||
if (node.name === "meta" && hasAttrib(node, "http-equiv")) {
|
||||
if (node.attribs["http-equiv"] === "content-security-policy") {
|
||||
|
@ -117,17 +119,19 @@ function traverseParsedHtml(node, origin?: URL) {
|
|||
}
|
||||
|
||||
if (node.name === "head") {
|
||||
const scramjetScripts = [];
|
||||
["codecs", "config", "shared", "client"].forEach((script) => {
|
||||
scramjetScripts.push(
|
||||
new Element("script", {
|
||||
src: self.$scramjet.config[script],
|
||||
"data-scramjet": "",
|
||||
})
|
||||
);
|
||||
});
|
||||
const scripts = [];
|
||||
|
||||
node.children.unshift(...scramjetScripts);
|
||||
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" });
|
||||
|
||||
scripts.push(codecs, config, shared, client);
|
||||
|
||||
node.children.unshift(...scripts);
|
||||
}
|
||||
|
||||
if (node.childNodes) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue