Add blob cloaking
This commit is contained in:
parent
d3f6c0ab06
commit
b0ddd8eb08
3 changed files with 59 additions and 11 deletions
|
|
@ -127,6 +127,9 @@ const link = Astro.url.searchParams.get("redir");
|
|||
|
||||
customElements.define('link-element', CustomComponent);
|
||||
document.addEventListener("astro:page-load", async () => {
|
||||
try {
|
||||
await init();
|
||||
}
|
||||
catch (_) {}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
try {
|
||||
await handleAb(settings, sw, storageManager);
|
||||
await handleBlob(settings, sw, storageManager);
|
||||
}
|
||||
catch (_) {}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -80,14 +80,46 @@ class Settings {
|
|||
this.#storageManager.setVal("searchEngine", engine || SearchEngines.DuckDuckGo);
|
||||
}
|
||||
|
||||
aboutBlank(location: string) {
|
||||
window.location.replace(location);
|
||||
cloak(location: string) {
|
||||
return {
|
||||
aboutBlank: () => {
|
||||
const win = window.open();
|
||||
const iframe = win!.document.createElement("iframe") as HTMLIFrameElement;
|
||||
win!.document.body.setAttribute('style', 'margin: 0; height: 100vh; width: 100%;');
|
||||
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);
|
||||
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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue