mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
prettier
This commit is contained in:
parent
5d61913f65
commit
23e5fe2c51
5 changed files with 70 additions and 70 deletions
|
@ -16,7 +16,7 @@ export default defineConfig({
|
|||
client: join(__dirname, "src/client/index.ts"),
|
||||
config: join(__dirname, "src/scramjet.config.ts"),
|
||||
codecs: join(__dirname, "src/codecs/index.ts"),
|
||||
bootstrapper: join(__dirname, "src/bootsrapper/index.ts")
|
||||
bootstrapper: join(__dirname, "src/bootsrapper/index.ts"),
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".ts", ".js"],
|
||||
|
@ -47,9 +47,9 @@ export default defineConfig({
|
|||
],
|
||||
parser: {
|
||||
javascript: {
|
||||
dynamicImportMode: "eager"
|
||||
}
|
||||
}
|
||||
dynamicImportMode: "eager",
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
filename: "scramjet.[name].js",
|
||||
|
|
|
@ -3,68 +3,71 @@ import { ScramjetConfig } from "../types";
|
|||
import { Codec } from "../codecs";
|
||||
|
||||
export class ScramjetBootstrapper {
|
||||
config: ScramjetConfig;
|
||||
private store: IDBMap;
|
||||
codec: Codec;
|
||||
config: ScramjetConfig;
|
||||
private store: IDBMap;
|
||||
codec: Codec;
|
||||
|
||||
constructor(config: ScramjetConfig) {
|
||||
const defaultConfig = {
|
||||
prefix: "/scramjet/",
|
||||
codec: "plain",
|
||||
wrapfn: "$scramjet$wrap",
|
||||
trysetfn: "$scramjet$tryset",
|
||||
importfn: "$scramjet$import",
|
||||
rewritefn: "$scramjet$rewrite",
|
||||
shared: "/scramjet.shared.js",
|
||||
worker: "/scramjet.worker.js",
|
||||
thread: "/scramjet.thread.js",
|
||||
client: "/scramjet.client.js",
|
||||
codecs: "/scramjet.codecs.js",
|
||||
}
|
||||
constructor(config: ScramjetConfig) {
|
||||
const defaultConfig = {
|
||||
prefix: "/scramjet/",
|
||||
codec: "plain",
|
||||
wrapfn: "$scramjet$wrap",
|
||||
trysetfn: "$scramjet$tryset",
|
||||
importfn: "$scramjet$import",
|
||||
rewritefn: "$scramjet$rewrite",
|
||||
shared: "/scramjet.shared.js",
|
||||
worker: "/scramjet.worker.js",
|
||||
thread: "/scramjet.thread.js",
|
||||
client: "/scramjet.client.js",
|
||||
codecs: "/scramjet.codecs.js",
|
||||
};
|
||||
|
||||
this.config = Object.assign({}, defaultConfig, config);
|
||||
this.config = Object.assign({}, defaultConfig, config);
|
||||
|
||||
// rspack won't let me use a dynamic import
|
||||
fetch(config.codecs).then(async (response) => {
|
||||
eval(await response.text());
|
||||
// rspack won't let me use a dynamic import
|
||||
fetch(config.codecs).then(async (response) => {
|
||||
eval(await response.text());
|
||||
|
||||
self.$scramjet.codec = self.$scramjet.codecs[this.config.codec];
|
||||
self.$scramjet.config = this.config;
|
||||
});
|
||||
self.$scramjet.codec = self.$scramjet.codecs[this.config.codec];
|
||||
self.$scramjet.config = this.config;
|
||||
});
|
||||
|
||||
console.log(this.config);
|
||||
this.store = new IDBMap("config", {
|
||||
prefix: "scramjet"
|
||||
});
|
||||
this.saveConfig();
|
||||
}
|
||||
console.log(this.config);
|
||||
this.store = new IDBMap("config", {
|
||||
prefix: "scramjet",
|
||||
});
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
registerSw(serviceWorkerPath: string) {
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register(serviceWorkerPath, {
|
||||
scope: this.config.prefix
|
||||
})
|
||||
.then((registration) => {
|
||||
console.log("ServiceWorker registration successful with scope: ", registration.scope);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("ServiceWorker registration failed: ", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
registerSw(serviceWorkerPath: string) {
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register(serviceWorkerPath, {
|
||||
scope: this.config.prefix,
|
||||
})
|
||||
.then((registration) => {
|
||||
console.log(
|
||||
"ServiceWorker registration successful with scope: ",
|
||||
registration.scope
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("ServiceWorker registration failed: ", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
saveConfig() {
|
||||
this.store.set("config", this.config).then(() => {
|
||||
console.log("scramjet config saved");
|
||||
});
|
||||
}
|
||||
saveConfig() {
|
||||
this.store.set("config", this.config).then(() => {
|
||||
console.log("scramjet config saved");
|
||||
});
|
||||
}
|
||||
|
||||
modifyConfig(config: ScramjetConfig) {
|
||||
this.config = Object.assign({}, this.config, config);
|
||||
modifyConfig(config: ScramjetConfig) {
|
||||
this.config = Object.assign({}, this.config, config);
|
||||
|
||||
this.saveConfig();
|
||||
}
|
||||
this.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
window.ScramjetBootstrapper = ScramjetBootstrapper;
|
||||
window.ScramjetBootstrapper = ScramjetBootstrapper;
|
||||
|
|
|
@ -102,10 +102,7 @@ async function handleResponse(
|
|||
}
|
||||
break;
|
||||
case "script":
|
||||
responseBody = rewriteJs(
|
||||
await response.arrayBuffer(),
|
||||
url
|
||||
);
|
||||
responseBody = rewriteJs(await response.arrayBuffer(), url);
|
||||
// Disable threading for now, it's causing issues.
|
||||
// responseBody = await this.threadpool.rewriteJs(await responseBody.arrayBuffer(), url.toString());
|
||||
break;
|
||||
|
@ -165,7 +162,7 @@ async function handleCookies(url: URL, headers: string[]) {
|
|||
|
||||
let [key, value] = cookieParsed.shift();
|
||||
if (!value) continue;
|
||||
value = value.replace("\"", "");
|
||||
value = value.replace('"', "");
|
||||
|
||||
const hostArg = cookieParsed.find((x) => x[0] === "Domain");
|
||||
cookieParsed = cookieParsed.filter((x) => x[0] !== "Domain");
|
||||
|
|
|
@ -48,14 +48,14 @@ export class ScramjetServiceWorker {
|
|||
|
||||
loadConfig() {
|
||||
const store = new IDBMap("config", {
|
||||
prefix: "scramjet"
|
||||
prefix: "scramjet",
|
||||
});
|
||||
|
||||
if (store.has("config")) {
|
||||
store.get("config").then((config) => {
|
||||
this.config = config;
|
||||
self.$scramjet.config = config;
|
||||
self.$scramjet.codec = self.$scramjet.codecs[config.codec]
|
||||
self.$scramjet.codec = self.$scramjet.codecs[config.codec];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
10
static/ui.js
10
static/ui.js
|
@ -1,9 +1,9 @@
|
|||
const bootstrapper = new ScramjetBootstrapper({
|
||||
codecs: "/scram/scramjet.codecs.js",
|
||||
worker: "/scram/scramjet.worker.js",
|
||||
thread: "/scram/scramjet.thread.js",
|
||||
client: "/scram/scramjet.client.js",
|
||||
shared: "/scram/scramjet.shared.js",
|
||||
codecs: "/scram/scramjet.codecs.js",
|
||||
worker: "/scram/scramjet.worker.js",
|
||||
thread: "/scram/scramjet.thread.js",
|
||||
client: "/scram/scramjet.client.js",
|
||||
shared: "/scram/scramjet.shared.js",
|
||||
});
|
||||
|
||||
bootstrapper.registerSw("./sw.js");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue