Run prettier on codebase, and make iframe favicon and title grabbing much better.

This commit is contained in:
wearrrrr 2024-03-27 10:06:46 -05:00
parent f3e347c1cd
commit 46d5cef377
9 changed files with 34 additions and 88 deletions

View file

@ -1,4 +0,0 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}

11
.vscode/launch.json vendored
View file

@ -1,11 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}

16
package-lock.json generated
View file

@ -11,7 +11,7 @@
"@astrojs/node": "^8.2.0", "@astrojs/node": "^8.2.0",
"@mercuryworkshop/bare-mux": "^1.0.5", "@mercuryworkshop/bare-mux": "^1.0.5",
"@mercuryworkshop/epoxy-transport": "^1.1.0", "@mercuryworkshop/epoxy-transport": "^1.1.0",
"@mercuryworkshop/libcurl-transport": "^1.2.4", "@mercuryworkshop/libcurl-transport": "^1.3.1",
"@titaniumnetwork-dev/ultraviolet": "^3.0.0", "@titaniumnetwork-dev/ultraviolet": "^3.0.0",
"@tomphttp/bare-client": "^2.2.0-alpha", "@tomphttp/bare-client": "^2.2.0-alpha",
"@tomphttp/bare-server-node": "^2.0.3", "@tomphttp/bare-server-node": "^2.0.3",
@ -1143,12 +1143,12 @@
} }
}, },
"node_modules/@mercuryworkshop/libcurl-transport": { "node_modules/@mercuryworkshop/libcurl-transport": {
"version": "1.2.4", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@mercuryworkshop/libcurl-transport/-/libcurl-transport-1.2.4.tgz", "resolved": "https://registry.npmjs.org/@mercuryworkshop/libcurl-transport/-/libcurl-transport-1.3.1.tgz",
"integrity": "sha512-BiqTOcHzjNYy0AHCxw3IAfe81+xX07Gjig9cZkEJ7eRLcuEwkLPwTnf36RopxFQh4yShbk1lMjmU4SjMIi6/uQ==", "integrity": "sha512-yGt8K7D1j8WLn7LgH6YPnxmHc+JUCB0x/QPIStuRftl0tq3D8uHskRFeOJ8ksTrru7mTAjk5Cpmvix8jNJ+Lug==",
"dependencies": { "dependencies": {
"esbuild-plugin-umd-wrapper": "^2.0.0", "esbuild-plugin-umd-wrapper": "^2.0.0",
"libcurl.js": "^0.5.3", "libcurl.js": "^0.6.6",
"rollup": "^4.12.0", "rollup": "^4.12.0",
"rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-typescript2": "^0.36.0", "rollup-plugin-typescript2": "^0.36.0",
@ -5352,9 +5352,9 @@
} }
}, },
"node_modules/libcurl.js": { "node_modules/libcurl.js": {
"version": "0.5.3", "version": "0.6.7",
"resolved": "https://registry.npmjs.org/libcurl.js/-/libcurl.js-0.5.3.tgz", "resolved": "https://registry.npmjs.org/libcurl.js/-/libcurl.js-0.6.7.tgz",
"integrity": "sha512-tHa5c18irBGzafPKwGMBU7c9RMxAQfuf3BHTLgAHToNvJaFXUYRAsKXDqV2SWKLMm5OaW2b1XGu8MsfMh1b08A==" "integrity": "sha512-dYFrLYBGjTUMzBk1ePcyS2trxc04DwdMuvj88NRSxddRg+AnwHlCp3YH6NnP6kufBCPnEBF3Vjz1OMQGF5Q/DQ=="
}, },
"node_modules/load-yaml-file": { "node_modules/load-yaml-file": {
"version": "0.2.0", "version": "0.2.0",

View file

@ -14,7 +14,7 @@
"@astrojs/node": "^8.2.0", "@astrojs/node": "^8.2.0",
"@mercuryworkshop/bare-mux": "^1.0.5", "@mercuryworkshop/bare-mux": "^1.0.5",
"@mercuryworkshop/epoxy-transport": "^1.1.0", "@mercuryworkshop/epoxy-transport": "^1.1.0",
"@mercuryworkshop/libcurl-transport": "^1.2.4", "@mercuryworkshop/libcurl-transport": "^1.3.1",
"@titaniumnetwork-dev/ultraviolet": "^3.0.0", "@titaniumnetwork-dev/ultraviolet": "^3.0.0",
"@tomphttp/bare-client": "^2.2.0-alpha", "@tomphttp/bare-client": "^2.2.0-alpha",
"@tomphttp/bare-server-node": "^2.0.3", "@tomphttp/bare-server-node": "^2.0.3",

@ -1 +1 @@
Subproject commit 06285f2a5abb58ef55e5127424be59cd46a66ae9 Subproject commit 8793db1e2fe64cae8936c00bcd4f333f158f6ebd

View file

@ -1,5 +1,5 @@
importScripts("/epoxy/index.js");
importScripts("/libcurl/index.js"); importScripts("/libcurl/index.js");
importScripts("/epoxy/index.js");
importScripts("/uv/uv.bundle.js"); importScripts("/uv/uv.bundle.js");
importScripts("/uv.config.js"); importScripts("/uv.config.js");
importScripts(__uv$config.sw); importScripts(__uv$config.sw);

View file

@ -14,6 +14,14 @@
form.addEventListener("submit", formEventListener); form.addEventListener("submit", formEventListener);
} }
setInterval(() => {
let iframe = document.getElementById("proxy-frame");
if (iframe && iframe.src != "") {
updateProxiedFavicon(iframe);
updateTopbarTitle(iframe);
}
}, 500);
async function getProxyURL() { async function getProxyURL() {
let preference = getProxyPreference(); let preference = getProxyPreference();
let url = input.value.trim(); let url = input.value.trim();
@ -97,7 +105,6 @@
iframe.style.pointerEvents = "auto"; iframe.style.pointerEvents = "auto";
iframe.classList.add("proxy-frame"); iframe.classList.add("proxy-frame");
document.body.appendChild(iframe); document.body.appendChild(iframe);
iframeURLChange(iframe, (newURL) => updateTopbarURL(preference, newURL));
const boundIFrameLoad = iframeLoad.bind(null, iframe, loadingContent, topbar, closeButton); const boundIFrameLoad = iframeLoad.bind(null, iframe, loadingContent, topbar, closeButton);
iframe.addEventListener("load", boundIFrameLoad); iframe.addEventListener("load", boundIFrameLoad);
@ -106,8 +113,6 @@
iframe.style.opacity = 1; iframe.style.opacity = 1;
topbar.style.opacity = 1; topbar.style.opacity = 1;
topbar.style.pointerEvents = "auto"; topbar.style.pointerEvents = "auto";
updateProxiedFavicon();
closeButton.onclick = () => { closeButton.onclick = () => {
iframe.style.opacity = 0; iframe.style.opacity = 0;
topbar.style.opacity = 0; topbar.style.opacity = 0;
@ -204,61 +209,12 @@
return; return;
} }
} }
setTimeout(() => updateProxiedFavicon(iframe), 400);
} }
function updateTopbarTitle(iframe) {
function iframeURLChange(iframe, callback) { let topbarTitle = document.getElementById("url-text");
var lastDispatched = null; if (iframe.contentDocument.title == "") {
iframe.contentDocument.title = "Loading...";
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]
);
} }
topbarTitle.innerText = iframe.contentDocument.title;
} }
</script> </script>

View file

@ -39,14 +39,11 @@ export default class TransportManager {
setTransport(transport: string, wispURL = wispURLDefault) { setTransport(transport: string, wispURL = wispURLDefault) {
this.transport = transport; this.transport = transport;
let transportConfig: transportConfig = { wisp: wispURL }; 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); SetTransport(this.transport, transportConfig);
} }
} }
const TransportMgr = new TransportManager(); export const TransportMgr = new TransportManager();
export function initTransport() { export function initTransport() {
registerRemoteListener(navigator.serviceWorker.controller!); registerRemoteListener(navigator.serviceWorker.controller!);
navigator.serviceWorker navigator.serviceWorker

View file

@ -65,8 +65,16 @@ export function getStaticPaths() {
</div> </div>
</Layout> </Layout>
<script> <script>
import { initTransport } from "../../components/ts/TransportManager"; import { initTransport, TransportMgr } from "../../components/ts/TransportManager";
initTransport(); initTransport();
document.addEventListener("astro:after-swap", () => {
let savedTransport = localStorage.getItem("alu__selectedTransport");
if (savedTransport) {
let parsedTransport = JSON.parse(savedTransport);
TransportMgr.setTransport(parsedTransport.value);
}
initTransport();
});
type Suggestion = { type Suggestion = {
phrase: string; phrase: string;
}; };