Checking URL...
@@ -82,7 +91,7 @@ Object.keys(SearchEngines).forEach((k) =>
seEl.addEventListener("change", async () => {
opts.settings.searchEngine(seEl.value);
});
- }
+ }
const wispServer = async (opts: Options) => {
const wispServerSwitcher = document.getElementById("wispServerSwitcher") as HTMLInputElement;
@@ -90,9 +99,10 @@ Object.keys(SearchEngines).forEach((k) =>
const wispServerInfoInner = document.getElementById("wispServerInfo-inner") as HTMLParagraphElement;
const wispServerSave = document.getElementById("wispServerSave") as HTMLButtonElement;
const wispServerReset = document.getElementById("wispServerReset") as HTMLButtonElement;
+ const adBlocking = document.getElementById("adBlocking") as HTMLDivElement;
wispServerSwitcher.value = opts.storageManager.getVal("wispServer");
-
+ const resetVal = `${(location.protocol === "https:" ? "wss://" : "ws://")}${location.host}/wisp/`
const reset = (hide: boolean = true) => {
if (hide) wispServerInfo.classList.add("hidden");
wispServerInfoInner.innerText = "Checking URL..."
@@ -100,6 +110,26 @@ Object.keys(SearchEngines).forEach((k) =>
wispServerInfoInner.classList.remove("text-green-500");
};
+ const adBlockingFunc = () => {
+ const adBlockingDropdown = document.getElementById("dropdownBox-adBlocking") as HTMLSelectElement;
+ adBlockingDropdown.addEventListener("change", () => {
+ opts.settings.adBlock(adBlockingDropdown.value === "enabled" ? true : false);
+ });
+
+ adBlockingDropdown.value = opts.storageManager.getVal("adBlock") === "true" ? "enabled" : "disabled";
+
+ if (wispServerSwitcher.value === resetVal) {
+ adBlocking.classList.remove("hidden");
+ opts.settings.adBlock(true);
+ adBlockingDropdown.value = "enabled";
+ }
+ else {
+ adBlocking.classList.add("hidden");
+ opts.settings.adBlock(false);
+ }
+ }
+ adBlockingFunc();
+
wispServerSave.addEventListener("click", async () => {
const server = wispServerSwitcher.value;
wispServerInfo.classList.remove("hidden");
@@ -114,7 +144,9 @@ Object.keys(SearchEngines).forEach((k) =>
reset(false);
wispServerInfoInner.innerText = "Wisp Server Set!";
wispServerInfoInner.classList.add("text-green-500");
+ //adBlocking.classList.contains("hidden") ? "" : adBlocking.classList.add("hidden");
await opts.sw.wispServer(wispServerSwitcher.value, true);
+ adBlockingFunc();
}
// We reset this after 4 seconds (any errors OR success)
@@ -125,9 +157,10 @@ Object.keys(SearchEngines).forEach((k) =>
wispServerInfo.classList.remove("hidden");
wispServerInfoInner.innerText = "Wisp Server Reset!";
wispServerInfoInner.classList.add("text-green-500");
- await opts.sw.wispServer(`${(location.protocol === "https:" ? "wss://" : "ws://")}${location.host}/wisp/`, true);
+ await opts.sw.wispServer(resetVal, true);
wispServerSwitcher.value = opts.storageManager.getVal("wispServer");
setTimeout(reset, 4000);
+ adBlockingFunc();
});
}
diff --git a/src/utils/proxy.ts b/src/utils/proxy.ts
index 166e05c..aa3608c 100644
--- a/src/utils/proxy.ts
+++ b/src/utils/proxy.ts
@@ -37,7 +37,7 @@ class SW {
}
}
- #search(input: string, template: string) {
+ search(input: string, template: string) {
try {
return new URL(input).toString();
} catch (_) {}
@@ -52,7 +52,7 @@ class SW {
encodeURL(string: string): string {
const proxy = this.#storageManager.getVal("proxy") as "uv" | "sj";
- const input = this.#search(string, this.#storageManager.getVal("searchEngine"));
+ const input = this.search(string, this.#storageManager.getVal("searchEngine"));
return proxy === "uv"
? `${__uv$config.prefix}${__uv$config.encodeUrl!(input)}`
: this.#scramjetController!.encodeUrl(input);
@@ -60,6 +60,13 @@ class SW {
async setTransport(transport?: "epoxy" | "libcurl", get?: boolean) {
console.log("Setting transport");
+ const wispServer = (): string => {
+ const wispServerVal = this.#storageManager.getVal("wispServer");
+ if (this.#storageManager.getVal("adBlock") === "true") {
+ return wispServerVal.replace("/wisp/", "/adblock/");
+ }
+ return wispServerVal;
+ }
if (get) return this.#storageManager.getVal("transport");
this.#storageManager.setVal(
"transport",
@@ -68,23 +75,24 @@ class SW {
switch (transport) {
case "epoxy": {
await this.#baremuxConn!.setTransport("/epoxy/index.mjs", [
- { wisp: this.#storageManager.getVal("wispServer") }
+ { wisp: wispServer() }
]);
}
case "libcurl": {
await this.#baremuxConn!.setTransport("/libcurl/index.mjs", [
- { wisp: this.#storageManager.getVal("wispServer") }
+ { wisp: wispServer() }
]);
}
default: {
await this.#baremuxConn!.setTransport("/epoxy/index.mjs", [
- { wisp: this.#storageManager.getVal("wispServer") }
+ { wisp: wispServer() }
]);
}
}
}
async wispServer(wispServer?: string, set?: true) {
+ console.log(wispServer?.replace("/wisp/", "/adblock/"));
this.#storageManager.setVal(
"wispServer",
wispServer ||
diff --git a/src/utils/settings.ts b/src/utils/settings.ts
index e39b8b3..c55ba2c 100644
--- a/src/utils/settings.ts
+++ b/src/utils/settings.ts
@@ -80,6 +80,57 @@ class Settings {
this.#storageManager.setVal("searchEngine", engine || SearchEngines.DuckDuckGo);
}
+ 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;
+ }
+ }
+ }
+
+ adBlock(enabled?: boolean) {
+ if (enabled === true || enabled === false) {
+ this.#storageManager.setVal("adBlock", enabled.valueOf().toString());
+ }
+ else {
+ this.#storageManager.setVal("adBlock", "true");
+ }
+ }
+
async *#init() {
yield this.theme(this.#storageManager.getVal("theme") || "default");
}
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 2f5caf1..9a96394 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -1,7 +1,7 @@
import type { Props } from "astro";
interface SettingsProps extends Props {
- active: "appearance" | "credits" | "links" | "proxy";
+ active: "appearance" | "credits" | "links" | "proxy" | "cloaking";
title: string;
}