Add adblocking
This commit is contained in:
parent
411813aa4c
commit
d2bc8b748d
6 changed files with 34 additions and 5 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,11 +111,21 @@ Object.keys(SearchEngines).forEach((k) =>
|
|||
};
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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