mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
Add format script to package.json and format with prettier.
This commit is contained in:
parent
61bd33845b
commit
be3b87e795
39 changed files with 1732 additions and 1734 deletions
|
@ -12,7 +12,8 @@
|
||||||
"build": "rspack build",
|
"build": "rspack build",
|
||||||
"dev": "node server.js",
|
"dev": "node server.js",
|
||||||
"prepublish": "pnpm build",
|
"prepublish": "pnpm build",
|
||||||
"pub": "pnpm publish --no-git-checks --access public"
|
"pub": "pnpm publish --no-git-checks --access public",
|
||||||
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
|
|
|
@ -22,5 +22,5 @@ CSSStyleDeclaration.prototype.setProperty = new Proxy(
|
||||||
|
|
||||||
return Reflect.apply(target, thisArg, argArray);
|
return Reflect.apply(target, thisArg, argArray);
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -105,14 +105,12 @@ Element.prototype.setAttribute = new Proxy(Element.prototype.setAttribute, {
|
||||||
|
|
||||||
const innerHTML = Object.getOwnPropertyDescriptor(
|
const innerHTML = Object.getOwnPropertyDescriptor(
|
||||||
Element.prototype,
|
Element.prototype,
|
||||||
"innerHTML"
|
"innerHTML",
|
||||||
);
|
);
|
||||||
|
|
||||||
Object.defineProperty(Element.prototype, "innerHTML", {
|
Object.defineProperty(Element.prototype, "innerHTML", {
|
||||||
set(value) {
|
set(value) {
|
||||||
if (
|
if (this instanceof HTMLScriptElement) {
|
||||||
this instanceof HTMLScriptElement
|
|
||||||
) {
|
|
||||||
value = rewriteJs(value);
|
value = rewriteJs(value);
|
||||||
} else if (this instanceof HTMLStyleElement) {
|
} else if (this instanceof HTMLStyleElement) {
|
||||||
value = rewriteCss(value);
|
value = rewriteCss(value);
|
||||||
|
|
|
@ -13,7 +13,7 @@ import "./css.ts";
|
||||||
import "./history.ts";
|
import "./history.ts";
|
||||||
import "./worker.ts";
|
import "./worker.ts";
|
||||||
import "./url.ts";
|
import "./url.ts";
|
||||||
import "./beacon.ts"
|
import "./beacon.ts";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|
|
@ -7,7 +7,7 @@ const FunctionProxy = new Proxy(Function, {
|
||||||
} else {
|
} else {
|
||||||
return Reflect.construct(
|
return Reflect.construct(
|
||||||
target,
|
target,
|
||||||
rewriteJs(argArray[argArray.length - 1])
|
rewriteJs(argArray[argArray.length - 1]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ WebSocket = new Proxy(WebSocket, {
|
||||||
{
|
{
|
||||||
"User-Agent": navigator.userAgent,
|
"User-Agent": navigator.userAgent,
|
||||||
},
|
},
|
||||||
ArrayBuffer.prototype
|
ArrayBuffer.prototype,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,5 +19,5 @@ XMLHttpRequest.prototype.setRequestHeader = new Proxy(
|
||||||
|
|
||||||
return Reflect.apply(target, thisArg, argArray);
|
return Reflect.apply(target, thisArg, argArray);
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,4 +37,3 @@ delete window.TrustedScriptURL;
|
||||||
delete window.TrustedTypePolicy;
|
delete window.TrustedTypePolicy;
|
||||||
delete window.TrustedTypePolicyFactory;
|
delete window.TrustedTypePolicyFactory;
|
||||||
delete window.trustedTypes;
|
delete window.trustedTypes;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ export const windowProxy = new Proxy(window, {
|
||||||
if (
|
if (
|
||||||
typeof prop === "string" &&
|
typeof prop === "string" &&
|
||||||
["window", "top", "parent", "self", "globalThis", "location"].includes(
|
["window", "top", "parent", "self", "globalThis", "location"].includes(
|
||||||
prop
|
prop,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -347,7 +347,7 @@ function expandKey(key) {
|
||||||
w[i * 4 + j][0],
|
w[i * 4 + j][0],
|
||||||
w[i * 4 + j][1],
|
w[i * 4 + j][1],
|
||||||
w[i * 4 + j][2],
|
w[i * 4 + j][2],
|
||||||
w[i * 4 + j][3]
|
w[i * 4 + j][3],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,12 +406,12 @@ function Gx(x) {
|
||||||
}
|
}
|
||||||
var SBox = strhex(
|
var SBox = strhex(
|
||||||
"637c777bf26b6fc53001672bfed7ab76ca82c97dfa5947f0add4a2af9ca472c0b7fd9326363ff7cc34a5e5f171d8311504c723c31896059a071280e2eb27b27509832c1a1b6e5aa0523bd6b329e32f8453d100ed20fcb15b6acbbe394a4c58cfd0efaafb434d338545f9027f503c9fa851a3408f929d38f5bcb6da2110fff3d2cd0c13ec5f974417c4a77e3d645d197360814fdc222a908846eeb814de5e0bdbe0323a0a4906245cc2d3ac629195e479e7c8376d8dd54ea96c56f4ea657aae08ba78252e1ca6b4c6e8dd741f4bbd8b8a703eb5664803f60e613557b986c11d9ee1f8981169d98e949b1e87e9ce5528df8ca1890dbfe6426841992d0fb054bb16",
|
"637c777bf26b6fc53001672bfed7ab76ca82c97dfa5947f0add4a2af9ca472c0b7fd9326363ff7cc34a5e5f171d8311504c723c31896059a071280e2eb27b27509832c1a1b6e5aa0523bd6b329e32f8453d100ed20fcb15b6acbbe394a4c58cfd0efaafb434d338545f9027f503c9fa851a3408f929d38f5bcb6da2110fff3d2cd0c13ec5f974417c4a77e3d645d197360814fdc222a908846eeb814de5e0bdbe0323a0a4906245cc2d3ac629195e479e7c8376d8dd54ea96c56f4ea657aae08ba78252e1ca6b4c6e8dd741f4bbd8b8a703eb5664803f60e613557b986c11d9ee1f8981169d98e949b1e87e9ce5528df8ca1890dbfe6426841992d0fb054bb16",
|
||||||
2
|
2,
|
||||||
);
|
);
|
||||||
var SBoxInv = invertArr(SBox);
|
var SBoxInv = invertArr(SBox);
|
||||||
var Rcon = strhex(
|
var Rcon = strhex(
|
||||||
"01020408102040801b366cd8ab4d9a2f5ebc63c697356ad4b37dfaefc591",
|
"01020408102040801b366cd8ab4d9a2f5ebc63c697356ad4b37dfaefc591",
|
||||||
2
|
2,
|
||||||
);
|
);
|
||||||
var G2X = Gx(2);
|
var G2X = Gx(2);
|
||||||
var G3X = Gx(3);
|
var G3X = Gx(3);
|
||||||
|
@ -550,7 +550,7 @@ function MD5(numArr) {
|
||||||
d,
|
d,
|
||||||
rnd = strhex(
|
rnd = strhex(
|
||||||
"67452301efcdab8998badcfe10325476d76aa478e8c7b756242070dbc1bdceeef57c0faf4787c62aa8304613fd469501698098d88b44f7afffff5bb1895cd7be6b901122fd987193a679438e49b40821f61e2562c040b340265e5a51e9b6c7aad62f105d02441453d8a1e681e7d3fbc821e1cde6c33707d6f4d50d87455a14eda9e3e905fcefa3f8676f02d98d2a4c8afffa39428771f6816d9d6122fde5380ca4beea444bdecfa9f6bb4b60bebfbc70289b7ec6eaa127fad4ef308504881d05d9d4d039e6db99e51fa27cf8c4ac5665f4292244432aff97ab9423a7fc93a039655b59c38f0ccc92ffeff47d85845dd16fa87e4ffe2ce6e0a30143144e0811a1f7537e82bd3af2352ad7d2bbeb86d391",
|
"67452301efcdab8998badcfe10325476d76aa478e8c7b756242070dbc1bdceeef57c0faf4787c62aa8304613fd469501698098d88b44f7afffff5bb1895cd7be6b901122fd987193a679438e49b40821f61e2562c040b340265e5a51e9b6c7aad62f105d02441453d8a1e681e7d3fbc821e1cde6c33707d6f4d50d87455a14eda9e3e905fcefa3f8676f02d98d2a4c8afffa39428771f6816d9d6122fde5380ca4beea444bdecfa9f6bb4b60bebfbc70289b7ec6eaa127fad4ef308504881d05d9d4d039e6db99e51fa27cf8c4ac5665f4292244432aff97ab9423a7fc93a039655b59c38f0ccc92ffeff47d85845dd16fa87e4ffe2ce6e0a30143144e0811a1f7537e82bd3af2352ad7d2bbeb86d391",
|
||||||
8
|
8,
|
||||||
);
|
);
|
||||||
|
|
||||||
x = convertToWordArray(numArr);
|
x = convertToWordArray(numArr);
|
||||||
|
|
|
@ -16,9 +16,9 @@ const xor = {
|
||||||
str
|
str
|
||||||
.split("")
|
.split("")
|
||||||
.map((e, i) =>
|
.map((e, i) =>
|
||||||
i % key ? String.fromCharCode(e.charCodeAt(0) ^ key) : e
|
i % key ? String.fromCharCode(e.charCodeAt(0) ^ key) : e,
|
||||||
)
|
)
|
||||||
.join("")
|
.join(""),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
decode: (str: string | undefined, key: number = 2) => {
|
decode: (str: string | undefined, key: number = 2) => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ export function rewriteCss(css: string, origin?: URL) {
|
||||||
urlQuote,
|
urlQuote,
|
||||||
urlContent,
|
urlContent,
|
||||||
importQuote,
|
importQuote,
|
||||||
importContent
|
importContent,
|
||||||
) => {
|
) => {
|
||||||
const url = urlContent || importContent;
|
const url = urlContent || importContent;
|
||||||
const encodedUrl = encodeUrl(url.trim(), origin);
|
const encodedUrl = encodeUrl(url.trim(), origin);
|
||||||
|
@ -29,6 +29,6 @@ export function rewriteCss(css: string, origin?: URL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return `url(${urlQuote}${encodedUrl}${urlQuote})`;
|
return `url(${urlQuote}${encodedUrl}${urlQuote})`;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ export function rewriteHeaders(rawHeaders: BareHeaders, origin?: URL) {
|
||||||
|
|
||||||
if (headers["link"]) {
|
if (headers["link"]) {
|
||||||
headers["link"] = headers["link"].replace(/<(.*?)>/gi, (match) =>
|
headers["link"] = headers["link"].replace(/<(.*?)>/gi, (match) =>
|
||||||
encodeUrl(match, origin)
|
encodeUrl(match, origin),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,11 +64,11 @@ function traverseParsedHtml(node, origin?: URL) {
|
||||||
if (
|
if (
|
||||||
node.name === "script" &&
|
node.name === "script" &&
|
||||||
/(application|text)\/javascript|importmap|undefined/.test(
|
/(application|text)\/javascript|importmap|undefined/.test(
|
||||||
node.attribs.type
|
node.attribs.type,
|
||||||
) &&
|
) &&
|
||||||
node.children[0] !== undefined
|
node.children[0] !== undefined
|
||||||
) {
|
) {
|
||||||
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);
|
||||||
|
@ -93,7 +93,7 @@ function traverseParsedHtml(node, origin?: URL) {
|
||||||
new Element("script", {
|
new Element("script", {
|
||||||
src: self.$scramjet.config[script],
|
src: self.$scramjet.config[script],
|
||||||
"data-scramjet": "",
|
"data-scramjet": "",
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ function traverseParsedHtml(node, origin?: URL) {
|
||||||
for (const childNode in node.childNodes) {
|
for (const childNode in node.childNodes) {
|
||||||
node.childNodes[childNode] = traverseParsedHtml(
|
node.childNodes[childNode] = traverseParsedHtml(
|
||||||
node.childNodes[childNode],
|
node.childNodes[childNode],
|
||||||
origin
|
origin,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ export function encodeUrl(url: string | URL, origin?: URL) {
|
||||||
origin = new URL(
|
origin = new URL(
|
||||||
self.$scramjet.config.codec.decode(
|
self.$scramjet.config.codec.decode(
|
||||||
location.href.slice(
|
location.href.slice(
|
||||||
(location.origin + self.$scramjet.config.prefix).length
|
(location.origin + self.$scramjet.config.prefix).length,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export function decodeUrl(url: string | URL) {
|
||||||
return url;
|
return url;
|
||||||
} else if (canParseUrl(url)) {
|
} else if (canParseUrl(url)) {
|
||||||
return self.$scramjet.config.codec.decode(
|
return self.$scramjet.config.codec.decode(
|
||||||
url.slice((location.origin + self.$scramjet.config.prefix).length)
|
url.slice((location.origin + self.$scramjet.config.prefix).length),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return url;
|
return url;
|
||||||
|
|
|
@ -39,7 +39,7 @@ self.ScramjetServiceWorker = class ScramjetServiceWorker {
|
||||||
|
|
||||||
if (urlParam.has("url")) {
|
if (urlParam.has("url")) {
|
||||||
return Response.redirect(
|
return Response.redirect(
|
||||||
encodeUrl(urlParam.get("url"), new URL(urlParam.get("url")))
|
encodeUrl(urlParam.get("url"), new URL(urlParam.get("url"))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ function errorTemplate(trace: string, fetchedURL: string) {
|
||||||
errorTrace.value = ${JSON.stringify(trace)};
|
errorTrace.value = ${JSON.stringify(trace)};
|
||||||
fetchedURL.textContent = ${JSON.stringify(fetchedURL)};
|
fetchedURL.textContent = ${JSON.stringify(fetchedURL)};
|
||||||
for (const node of document.querySelectorAll("#hostname")) node.textContent = ${JSON.stringify(
|
for (const node of document.querySelectorAll("#hostname")) node.textContent = ${JSON.stringify(
|
||||||
location.hostname
|
location.hostname,
|
||||||
)};
|
)};
|
||||||
reload.addEventListener("click", () => location.reload());
|
reload.addEventListener("click", () => location.reload());
|
||||||
version.textContent = "0.0.1";
|
version.textContent = "0.0.1";
|
||||||
|
|
|
@ -2,7 +2,7 @@ importScripts(
|
||||||
"/scram/scramjet.codecs.js",
|
"/scram/scramjet.codecs.js",
|
||||||
"/scram/scramjet.config.js",
|
"/scram/scramjet.config.js",
|
||||||
"/scram/scramjet.shared.js",
|
"/scram/scramjet.shared.js",
|
||||||
"/scram/scramjet.worker.js"
|
"/scram/scramjet.worker.js",
|
||||||
);
|
);
|
||||||
|
|
||||||
const scramjet = new ScramjetServiceWorker();
|
const scramjet = new ScramjetServiceWorker();
|
||||||
|
|
|
@ -22,7 +22,7 @@ const store = $store(
|
||||||
location.host +
|
location.host +
|
||||||
"/bare/",
|
"/bare/",
|
||||||
},
|
},
|
||||||
{ ident: "settings", backing: "localstorage", autosave: "auto" }
|
{ ident: "settings", backing: "localstorage", autosave: "auto" },
|
||||||
);
|
);
|
||||||
connection.setTransport("/baremod/index.mjs", [store.bareurl]);
|
connection.setTransport("/baremod/index.mjs", [store.bareurl]);
|
||||||
function App() {
|
function App() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue