Add blob cloaking

This commit is contained in:
MotorTruck1221 2025-06-08 21:46:53 -06:00
parent d3f6c0ab06
commit b0ddd8eb08
No known key found for this signature in database
GPG key ID: 08F417E2B8B61EA4
3 changed files with 59 additions and 11 deletions

View file

@ -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 (_) {}
});
</script>

View file

@ -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 (_) {}
});
</script>

View file

@ -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 = `
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body, html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<iframe style="border: none; width: 100%; height: 100%;" src="${window.location.href}"></iframe>
</body>
</html>
`;
const blob = new Blob([content], { type: 'text/html' });
const url = URL.createObjectURL(blob);
win.location.href = url;
}
}
}
async *#init() {