From 46d5cef377090d3d44e6046b19cb1e7ca724257c Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Wed, 27 Mar 2024 10:06:46 -0500 Subject: [PATCH] Run prettier on codebase, and make iframe favicon and title grabbing much better. --- .vscode/extensions.json | 4 -- .vscode/launch.json | 11 ----- package-lock.json | 16 +++--- package.json | 2 +- public/games | 2 +- public/sw.js | 2 +- src/components/ProxyRegistrar.astro | 70 +++++---------------------- src/components/ts/TransportManager.ts | 5 +- src/pages/[lang]/index.astro | 10 +++- 9 files changed, 34 insertions(+), 88 deletions(-) delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/launch.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 22a1505..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "recommendations": ["astro-build.astro-vscode"], - "unwantedRecommendations": [] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index d642209..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "command": "./node_modules/.bin/astro dev", - "name": "Development server", - "request": "launch", - "type": "node-terminal" - } - ] -} diff --git a/package-lock.json b/package-lock.json index a591ef2..e37af89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@astrojs/node": "^8.2.0", "@mercuryworkshop/bare-mux": "^1.0.5", "@mercuryworkshop/epoxy-transport": "^1.1.0", - "@mercuryworkshop/libcurl-transport": "^1.2.4", + "@mercuryworkshop/libcurl-transport": "^1.3.1", "@titaniumnetwork-dev/ultraviolet": "^3.0.0", "@tomphttp/bare-client": "^2.2.0-alpha", "@tomphttp/bare-server-node": "^2.0.3", @@ -1143,12 +1143,12 @@ } }, "node_modules/@mercuryworkshop/libcurl-transport": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/@mercuryworkshop/libcurl-transport/-/libcurl-transport-1.2.4.tgz", - "integrity": "sha512-BiqTOcHzjNYy0AHCxw3IAfe81+xX07Gjig9cZkEJ7eRLcuEwkLPwTnf36RopxFQh4yShbk1lMjmU4SjMIi6/uQ==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@mercuryworkshop/libcurl-transport/-/libcurl-transport-1.3.1.tgz", + "integrity": "sha512-yGt8K7D1j8WLn7LgH6YPnxmHc+JUCB0x/QPIStuRftl0tq3D8uHskRFeOJ8ksTrru7mTAjk5Cpmvix8jNJ+Lug==", "dependencies": { "esbuild-plugin-umd-wrapper": "^2.0.0", - "libcurl.js": "^0.5.3", + "libcurl.js": "^0.6.6", "rollup": "^4.12.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-typescript2": "^0.36.0", @@ -5352,9 +5352,9 @@ } }, "node_modules/libcurl.js": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/libcurl.js/-/libcurl.js-0.5.3.tgz", - "integrity": "sha512-tHa5c18irBGzafPKwGMBU7c9RMxAQfuf3BHTLgAHToNvJaFXUYRAsKXDqV2SWKLMm5OaW2b1XGu8MsfMh1b08A==" + "version": "0.6.7", + "resolved": "https://registry.npmjs.org/libcurl.js/-/libcurl.js-0.6.7.tgz", + "integrity": "sha512-dYFrLYBGjTUMzBk1ePcyS2trxc04DwdMuvj88NRSxddRg+AnwHlCp3YH6NnP6kufBCPnEBF3Vjz1OMQGF5Q/DQ==" }, "node_modules/load-yaml-file": { "version": "0.2.0", diff --git a/package.json b/package.json index 20f033f..3182cba 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@astrojs/node": "^8.2.0", "@mercuryworkshop/bare-mux": "^1.0.5", "@mercuryworkshop/epoxy-transport": "^1.1.0", - "@mercuryworkshop/libcurl-transport": "^1.2.4", + "@mercuryworkshop/libcurl-transport": "^1.3.1", "@titaniumnetwork-dev/ultraviolet": "^3.0.0", "@tomphttp/bare-client": "^2.2.0-alpha", "@tomphttp/bare-server-node": "^2.0.3", diff --git a/public/games b/public/games index 06285f2..8793db1 160000 --- a/public/games +++ b/public/games @@ -1 +1 @@ -Subproject commit 06285f2a5abb58ef55e5127424be59cd46a66ae9 +Subproject commit 8793db1e2fe64cae8936c00bcd4f333f158f6ebd diff --git a/public/sw.js b/public/sw.js index 5f4f3d4..e8b36e1 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,5 +1,5 @@ -importScripts("/epoxy/index.js"); importScripts("/libcurl/index.js"); +importScripts("/epoxy/index.js"); importScripts("/uv/uv.bundle.js"); importScripts("/uv.config.js"); importScripts(__uv$config.sw); diff --git a/src/components/ProxyRegistrar.astro b/src/components/ProxyRegistrar.astro index 6c48811..fac39e3 100644 --- a/src/components/ProxyRegistrar.astro +++ b/src/components/ProxyRegistrar.astro @@ -14,6 +14,14 @@ form.addEventListener("submit", formEventListener); } + setInterval(() => { + let iframe = document.getElementById("proxy-frame"); + if (iframe && iframe.src != "") { + updateProxiedFavicon(iframe); + updateTopbarTitle(iframe); + } + }, 500); + async function getProxyURL() { let preference = getProxyPreference(); let url = input.value.trim(); @@ -97,7 +105,6 @@ iframe.style.pointerEvents = "auto"; iframe.classList.add("proxy-frame"); document.body.appendChild(iframe); - iframeURLChange(iframe, (newURL) => updateTopbarURL(preference, newURL)); const boundIFrameLoad = iframeLoad.bind(null, iframe, loadingContent, topbar, closeButton); iframe.addEventListener("load", boundIFrameLoad); @@ -106,8 +113,6 @@ iframe.style.opacity = 1; topbar.style.opacity = 1; topbar.style.pointerEvents = "auto"; - - updateProxiedFavicon(); closeButton.onclick = () => { iframe.style.opacity = 0; topbar.style.opacity = 0; @@ -204,61 +209,12 @@ return; } } - setTimeout(() => updateProxiedFavicon(iframe), 400); } - - function iframeURLChange(iframe, callback) { - var lastDispatched = null; - - var dispatchChange = function () { - var newHref = iframe.contentWindow.location.href; - - if (newHref !== lastDispatched) { - callback(newHref); - - lastDispatched = newHref; - } - }; - - var unloadHandler = function () { - // Timeout needed because the URL changes immediately after - // the `unload` event is dispatched. - setTimeout(dispatchChange, 0); - }; - - function attachUnload() { - // Remove the unloadHandler in case it was already attached. - // Otherwise, there will be two handlers, which is unnecessary. - iframe.contentWindow.removeEventListener("unload", unloadHandler); - iframe.contentWindow.addEventListener("unload", unloadHandler); - } - - iframe.addEventListener("load", function () { - attachUnload(); - updateProxiedFavicon(iframe); - - // Just in case the change wasn't dispatched during the unload event... - dispatchChange(); - }); - - attachUnload(); - } - function updateTopbarURL(preference, newURL) { - if (newURL === "about:blank") return; - let urlText = document.getElementById("url-text"); - if (urlText) { - if (preference === "rammerhead") { - let newurl = newURL.slice( - newURL.indexOf("/" + getCookie("rammerhead-session")) + - getCookie("rammerhead-session").length + - 2 - ); - if (newurl.length > 30) newurl = newurl.slice(0, 50) + "..."; - urlText.innerText = newurl; - } else - urlText.innerText = window.__uv$config.decodeUrl( - newURL.split(window.__uv$config.prefix)[1] - ); + function updateTopbarTitle(iframe) { + let topbarTitle = document.getElementById("url-text"); + if (iframe.contentDocument.title == "") { + iframe.contentDocument.title = "Loading..."; } + topbarTitle.innerText = iframe.contentDocument.title; } diff --git a/src/components/ts/TransportManager.ts b/src/components/ts/TransportManager.ts index 49e8d72..a2fe203 100644 --- a/src/components/ts/TransportManager.ts +++ b/src/components/ts/TransportManager.ts @@ -39,14 +39,11 @@ export default class TransportManager { setTransport(transport: string, wispURL = wispURLDefault) { this.transport = transport; let transportConfig: transportConfig = { wisp: wispURL }; - if (this.transport == "CurlMod.LibcurlClient") { - transportConfig.wasm = "https://cdn.jsdelivr.net/npm/libcurl.js@latest/libcurl.wasm"; - } SetTransport(this.transport, transportConfig); } } -const TransportMgr = new TransportManager(); +export const TransportMgr = new TransportManager(); export function initTransport() { registerRemoteListener(navigator.serviceWorker.controller!); navigator.serviceWorker diff --git a/src/pages/[lang]/index.astro b/src/pages/[lang]/index.astro index b53efb5..d55a3ae 100644 --- a/src/pages/[lang]/index.astro +++ b/src/pages/[lang]/index.astro @@ -65,8 +65,16 @@ export function getStaticPaths() {