Feat: automatic proxy detection
Docs on how to add more later
This commit is contained in:
parent
70bff6156a
commit
c4d2c5b408
3 changed files with 62 additions and 32 deletions
|
|
@ -51,6 +51,7 @@ const t = useTranslations(lang);
|
||||||
<script>
|
<script>
|
||||||
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
|
import { initSw, setTransport } from "@utils/registerSW.ts"; //../../utils/registerSW.ts
|
||||||
import { RammerheadEncode } from "@rubynetwork/rammerhead-browser";
|
import { RammerheadEncode } from "@rubynetwork/rammerhead-browser";
|
||||||
|
import { SupportedSites } from "@utils/siteSupport";
|
||||||
import {
|
import {
|
||||||
WispServerURLS,
|
WispServerURLS,
|
||||||
SearchEngines,
|
SearchEngines,
|
||||||
|
|
@ -64,25 +65,41 @@ const t = useTranslations(lang);
|
||||||
type Suggestion = {
|
type Suggestion = {
|
||||||
phrase: string;
|
phrase: string;
|
||||||
};
|
};
|
||||||
async function proxy(term: string) {
|
async function proxy(term: string, rh: boolean) {
|
||||||
const searchEngine = localStorage.getItem(
|
const searchEngine = localStorage.getItem(Settings.ProxySettings.searchEngine);
|
||||||
Settings.ProxySettings.searchEngine
|
|
||||||
);
|
|
||||||
const proxySelection = localStorage.getItem(Settings.ProxySettings.proxy);
|
|
||||||
const openIn = localStorage.getItem(Settings.ProxySettings.openIn);
|
const openIn = localStorage.getItem(Settings.ProxySettings.openIn);
|
||||||
const proxyUrl = proxySelection === "uv" ? __uv$config!.prefix + __uv$config.encodeUrl!(search(term, searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg)) : await RammerheadEncode(search(term, searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg));
|
let proxyUrl: any = __uv$config!.prefix + __uv$config.encodeUrl!(search(term, searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg));
|
||||||
|
if (rh) {
|
||||||
|
proxyUrl = await RammerheadEncode(search(term, searchEngine ? SearchEngines[searchEngine] : SearchEngines.ddg));
|
||||||
|
}
|
||||||
if (openIn === "a:b" || openIn === "blob") {
|
if (openIn === "a:b" || openIn === "blob") {
|
||||||
return cloak(
|
return cloak(openIn as string, "https://google.com", `${window.location.origin}${proxyUrl}`);
|
||||||
openIn as string,
|
}
|
||||||
"https://google.com",
|
else if (openIn === "direct") {
|
||||||
`${window.location.origin}${proxyUrl}`
|
|
||||||
);
|
|
||||||
} else if (openIn === "direct") {
|
|
||||||
return (window.location.href = proxyUrl as string);
|
return (window.location.href = proxyUrl as string);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return proxyUrl;
|
return proxyUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function uv(iframe: HTMLIFrameElement, term: string) {
|
||||||
|
initSw().then(() => {
|
||||||
|
setTransport(localStorage.getItem(Settings.ProxySettings.transport) as string).then(async () => {
|
||||||
|
iframe.classList.remove("hidden");
|
||||||
|
const url = await proxy(term, false);
|
||||||
|
if (url) {
|
||||||
|
iframe.src = url as string;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async function rh(iframe: HTMLIFrameElement, term: string) {
|
||||||
|
iframe.classList.remove("hidden");
|
||||||
|
const url = await proxy(term, true);
|
||||||
|
if (url) {
|
||||||
|
iframe.src = "/" + url as string;
|
||||||
|
}
|
||||||
|
}
|
||||||
//we need to rerun this on every page load
|
//we need to rerun this on every page load
|
||||||
document.addEventListener("astro:page-load", async function () {
|
document.addEventListener("astro:page-load", async function () {
|
||||||
//wrap this in a try catch as sometimes this element will not be available on the page
|
//wrap this in a try catch as sometimes this element will not be available on the page
|
||||||
|
|
@ -92,25 +109,25 @@ const t = useTranslations(lang);
|
||||||
const omnibox = document.getElementById("omnibox") as HTMLDivElement;
|
const omnibox = document.getElementById("omnibox") as HTMLDivElement;
|
||||||
input?.addEventListener("keypress", async function (event: any) {
|
input?.addEventListener("keypress", async function (event: any) {
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
if (localStorage.getItem(Settings.ProxySettings.proxy) === "uv" || localStorage.getItem(Settings.ProxySettings.proxy) === "automatic") {
|
if (localStorage.getItem(Settings.ProxySettings.proxy) === "automatic") {
|
||||||
initSw().then(() => {
|
const key = SupportedSites[input?.value];
|
||||||
setTransport(
|
switch(key) {
|
||||||
localStorage.getItem(Settings.ProxySettings.transport) as string
|
case "uv":
|
||||||
).then(async () => {
|
uv(iframe, input?.value);
|
||||||
iframe.classList.remove("hidden");
|
break;
|
||||||
const url = await proxy(input?.value);
|
case "rh":
|
||||||
if (url) {
|
rh(iframe, input?.value);
|
||||||
iframe.src = url as string;
|
break;
|
||||||
|
default:
|
||||||
|
uv(iframe, input?.value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else if (localStorage.getItem(Settings.ProxySettings.proxy) === "uv") {
|
||||||
iframe.classList.remove("hidden");
|
uv(iframe, input?.value);
|
||||||
const url = await proxy(input?.value);
|
|
||||||
if (url) {
|
|
||||||
iframe.src = "/" + url as string;
|
|
||||||
}
|
}
|
||||||
|
else if (localStorage.getItem(Settings.ProxySettings.proxy) === "rh") {
|
||||||
|
rh(iframe, input?.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -125,4 +125,4 @@ const proxySettings = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { tabSettings, proxySettings, Settings, WispServerURLS, SearchEngines, cloak };
|
export { tabSettings, proxySettings, Settings, WispServerURLS, SearchEngines, cloak, type Proxy };
|
||||||
|
|
|
||||||
13
src/utils/siteSupport.ts
Normal file
13
src/utils/siteSupport.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import type { Proxy } from "./settings";
|
||||||
|
type ProxyChoices = Exclude<Proxy, "automatic">
|
||||||
|
|
||||||
|
const SupportedSites: Record<string, ProxyChoices> = {
|
||||||
|
"discord.gg": "uv",
|
||||||
|
"discord.com": "uv",
|
||||||
|
"spotify.com": "rh",
|
||||||
|
"spotify.link": "rh",
|
||||||
|
"youtube.com": "uv",
|
||||||
|
"youtu.be": "uv"
|
||||||
|
}
|
||||||
|
|
||||||
|
export { SupportedSites }
|
||||||
Loading…
Add table
Reference in a new issue