Merge pull request #75 from RadiusProxy/adBlocking
Feat: Add Adblocking functionality
This commit is contained in:
commit
975050c76e
7 changed files with 62 additions and 9 deletions
|
|
@ -18,7 +18,7 @@ const viteWispServer = (): Plugin => {
|
|||
name: "vite-wisp-server",
|
||||
configureServer(server) {
|
||||
server.httpServer?.on("upgrade", (req, socket, head) => {
|
||||
req.url.startsWith("/wisp") ? wisp.routeRequest(req, socket, head) : undefined;
|
||||
req.url.startsWith("/wisp") || req.url.startsWith("/adblock") ? wisp.routeRequest(req, socket, head) : undefined;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ const serverFactory: FastifyServerFactory = (
|
|||
handler(req, res);
|
||||
})
|
||||
.on("upgrade", (req, socket, head) => {
|
||||
if (req.url?.endsWith("/wisp/")) {
|
||||
if (req.url?.endsWith("/wisp/") || req.url?.endsWith("/adblock/")) {
|
||||
console.log(req.url);
|
||||
wisp.routeRequest(req, socket as Socket, head);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
const init = async () => {
|
||||
settings.searchEngine();
|
||||
settings.proxy();
|
||||
settings.adBlock();
|
||||
await sw.wispServer();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@
|
|||
import type { DropdownOptions } from "@utils/types";
|
||||
interface Props {
|
||||
id: string;
|
||||
classes?: string;
|
||||
options: DropdownOptions[];
|
||||
}
|
||||
|
||||
const { id, options } = Astro.props;
|
||||
const { id, options, classes } = Astro.props;
|
||||
---
|
||||
<select id=`dropdownBox-${id}` class="cursor-pointer flex h-10 w-[180px] items-center justify-between text-(--foreground) background-(--background) rounded-lg border border-(--border) px-3 py-2">
|
||||
<select id=`dropdownBox-${id}` class=`${classes} cursor-pointer flex h-10 w-[180px] items-center justify-between text-(--foreground) background-(--background) rounded-lg border border-(--border) px-3 py-2`>
|
||||
{options.map((el) =>
|
||||
<option class="w-full bg-(--accent) rounded-sm p-1" value={el.value}>{el.name}</option>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ Object.keys(SearchEngines).forEach((k) =>
|
|||
<div>
|
||||
<p> Wisp Server </p>
|
||||
<Input id="wispServerSwitcher" placeholder="Wisp server URL (EX: wss://radiusproxy.app/wisp/" />
|
||||
<div class="mt-2 hidden" id="adBlocking">
|
||||
<p> Ad Blocking </p>
|
||||
<Dropdown id="adBlocking" options={
|
||||
[
|
||||
{ name: 'Enabled', value: 'enabled', default: true },
|
||||
{ name: 'Disabled', value: 'disabled' }
|
||||
]
|
||||
} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2 mb-2 hidden" id="wispServerInfo">
|
||||
<p class="text-blue-500" id="wispServerInfo-inner"> Checking URL... </p>
|
||||
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,15 @@ class Settings {
|
|||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue