From b0ddd8eb08b2e50ba275e1f3abdf5ecf68018afe Mon Sep 17 00:00:00 2001 From: MotorTruck1221 Date: Sun, 8 Jun 2025 21:46:53 -0600 Subject: [PATCH] Add blob cloaking --- src/pages/index.astro | 5 +++- src/pages/settings/cloaking.astro | 17 +++++++++-- src/utils/settings.ts | 48 +++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index 2394a1c..2acc52e 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -127,6 +127,9 @@ const link = Astro.url.searchParams.get("redir"); customElements.define('link-element', CustomComponent); document.addEventListener("astro:page-load", async () => { - await init(); + try { + await init(); + } + catch (_) {} }); diff --git a/src/pages/settings/cloaking.astro b/src/pages/settings/cloaking.astro index 7b25934..a98f475 100644 --- a/src/pages/settings/cloaking.astro +++ b/src/pages/settings/cloaking.astro @@ -37,7 +37,16 @@ import Button from "@components/ui/Button.astro"; const button = document.getElementById("aboutBlankLaunch") as HTMLButtonElement; button.addEventListener("click", () => { const url = sw.search(input.value, storage.getVal('searchEngine')); - settings.aboutBlank(url); + settings.cloak(url).aboutBlank(); + }); + }; + + const handleBlob = async (settings: Settings, sw: SW, storage: StoreManager<"radius||settings">) => { + const input = document.getElementById("blobCloaker") as HTMLInputElement; + const button = document.getElementById("blobLaunch") as HTMLButtonElement; + button.addEventListener("click", () => { + const url = sw.search(input.value, storage.getVal('searchEngine')); + settings.cloak(url).blob(); }); }; @@ -45,6 +54,10 @@ import Button from "@components/ui/Button.astro"; const settings = await Settings.getInstance(); const sw = SW.getInstance().next().value!; const storageManager = new StoreManager<"radius||settings">("radius||settings"); - await handleAb(settings, sw, storageManager); + try { + await handleAb(settings, sw, storageManager); + await handleBlob(settings, sw, storageManager); + } + catch (_) {} }); diff --git a/src/utils/settings.ts b/src/utils/settings.ts index 7bedef1..a3bddcf 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -80,14 +80,46 @@ class Settings { this.#storageManager.setVal("searchEngine", engine || SearchEngines.DuckDuckGo); } - aboutBlank(location: string) { - window.location.replace(location); - const win = window.open(); - const iframe = win!.document.createElement("iframe") as HTMLIFrameElement; - win!.document.body.setAttribute('style', 'margin: 0; height: 100vh; width: 100%;'); - iframe.setAttribute('style', 'border: none; width: 100%; height: 100%; margin: 0;'); - iframe.src = window.location.href; - win!.document.body.appendChild(iframe); + cloak(location: string) { + return { + aboutBlank: () => { + const win = window.open(); + if (!win) return; + window.location.replace(location); + const iframe = win.document.createElement("iframe") as HTMLIFrameElement; + win.document.body.setAttribute('style', 'margin: 0; height: 100vh; width: 100%;'); + iframe.setAttribute('style', 'border: none; width: 100%; height: 100%; margin: 0;'); + iframe.src = window.location.href; + win.document.body.appendChild(iframe); + }, + blob: () => { + const win = window.open(); + if (!win) return; + window.location.replace(location); + const content = ` + + + + + + + + + + `; + const blob = new Blob([content], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + win.location.href = url; + } + } } async *#init() {