Refactor how AluStore handles the search parameter, and refactor settings.ts
This commit is contained in:
parent
26797b6ee6
commit
2f5a65cc3e
5 changed files with 16 additions and 53 deletions
2
src/alu.d.ts
vendored
2
src/alu.d.ts
vendored
|
|
@ -14,6 +14,6 @@ export declare global {
|
|||
isCustom: boolean;
|
||||
}
|
||||
>;
|
||||
type ValidStoreKeys = "proxy" | "search" | "openpage" | "wisp" | "bareUrl" | "transport" | "searxng" | "theme" | "lang" | "cloak";
|
||||
type ValidStoreKeys = "proxy" | "search" | "openpage" | "wisp" | "bareUrl" | "transport" | "theme" | "lang" | "cloak";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
import { Notyf } from "notyf";
|
||||
|
||||
const form = document.querySelector("form");
|
||||
let input = document.querySelector("input");
|
||||
let input = document.querySelector("input")!;
|
||||
document.addEventListener("astro:after-swap", initForm);
|
||||
function initForm() {
|
||||
const formEle = document.querySelector("form");
|
||||
input = document.querySelector("input");
|
||||
const formEle = document.querySelector("form") as HTMLFormElement;
|
||||
input = document.querySelector("input") as HTMLInputElement;
|
||||
if (formEle) formEle.addEventListener("submit", formEventListener);
|
||||
}
|
||||
if (form) {
|
||||
|
|
@ -24,10 +24,9 @@
|
|||
}, 500);
|
||||
|
||||
async function getProxyURL() {
|
||||
const preference = getProxyPreference();
|
||||
let url = input!.value.trim();
|
||||
const preference = Alu.store.get("proxy").value;
|
||||
let url = input.value.trim();
|
||||
if (!isUrl(url)) url = getSearchEngine() + url;
|
||||
else if (!(url.startsWith("https://") || url.startsWith("http://"))) url = "http://" + url;
|
||||
if (preference === "ultraviolet") {
|
||||
return window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
||||
} else if (preference == "rammerhead") {
|
||||
|
|
@ -89,7 +88,7 @@
|
|||
const backwardsButton = document.getElementById("nav-backwards") as HTMLImageElement;
|
||||
const forwardsButton = document.getElementById("nav-forwards") as HTMLImageElement;
|
||||
const shareButton = document.getElementById("nav-share") as HTMLImageElement;
|
||||
const preference = getProxyPreference();
|
||||
const preference = Alu.store.get("proxy").value;
|
||||
if (preference === "ultraviolet") {
|
||||
iframe.src = window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
||||
} else if (preference == "rammerhead") {
|
||||
|
|
@ -196,43 +195,10 @@
|
|||
}
|
||||
|
||||
function getSearchEngine() {
|
||||
const searchEngine = Alu.store.get("search");
|
||||
switch (searchEngine.value.toLowerCase()) {
|
||||
case "google": {
|
||||
return "https://google.com/search?q=";
|
||||
}
|
||||
case "bing": {
|
||||
return "https://bing.com/search?q=d";
|
||||
}
|
||||
case "brave": {
|
||||
return "https://search.brave.com/search?q=";
|
||||
}
|
||||
case "searx": {
|
||||
const searxngURL = Alu.store.get("searxng");
|
||||
// Ugly hack to remove the trailing slash :)
|
||||
if (searxngURL.value.endsWith("/")) searxngURL.value = searxngURL.value.slice(0, -1);
|
||||
return searxngURL.value + "/search?q=";
|
||||
}
|
||||
default: {
|
||||
return "https://google.com/search?q=";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getProxyPreference() {
|
||||
const proxy = Alu.store.get("proxy");
|
||||
switch (proxy.value) {
|
||||
case "ultraviolet":
|
||||
return "ultraviolet";
|
||||
case "rammerhead":
|
||||
return "rammerhead";
|
||||
default:
|
||||
return "ultraviolet";
|
||||
}
|
||||
return Alu.store.get("search").value;
|
||||
}
|
||||
|
||||
function updateProxiedFavicon(iframe: HTMLIFrameElement) {
|
||||
if (!iframe) return;
|
||||
const proxiedFavicon = document.getElementById("proxied-favicon") as HTMLImageElement;
|
||||
if (iframe) {
|
||||
if (iframe.contentDocument) {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ const proxyList = [
|
|||
];
|
||||
|
||||
const searchEngineList = [
|
||||
{ name: "Google", value: "google" },
|
||||
{ name: "Bing", value: "bing" },
|
||||
{ name: "Brave", value: "brave" },
|
||||
{ name: "Searx", value: "searx" },
|
||||
{ name: "Google", value: "https://google.com/search?q=" },
|
||||
{ name: "Bing", value: "https://bing.com/search?q=" },
|
||||
{ name: "Brave", value: "https://search.brave.com/search?q=" },
|
||||
{ name: "Searx", value: "https://searxng.site/?q=" },
|
||||
];
|
||||
|
||||
const openPageWith = [
|
||||
|
|
@ -64,5 +64,5 @@ const wispURLList = [
|
|||
</div>
|
||||
<div class="setting__searxng-url">
|
||||
<label aria-label="SearXNG URL" for="searxng-url-input" class="setting-label">{t("settings.proxy.searxngURL")}</label>
|
||||
<Input height="50px" inputName="searxng-url" defaultTextContent="https://searxng.site/" />
|
||||
<Input height="50px" inputName="searxng-url" defaultTextContent="https://searxng.site/?q=" />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const KEYSTORE: Alu.DefaultKeys = {
|
|||
},
|
||||
search: {
|
||||
name: "Google",
|
||||
value: "google",
|
||||
value: "https://google.com/search?q=",
|
||||
},
|
||||
openpage: {
|
||||
name: "Embed",
|
||||
|
|
@ -22,9 +22,6 @@ const KEYSTORE: Alu.DefaultKeys = {
|
|||
name: "Epoxy",
|
||||
value: "/epoxy/index.mjs",
|
||||
},
|
||||
searxng: {
|
||||
value: "https://searxng.site",
|
||||
},
|
||||
theme: {
|
||||
name: "Alu",
|
||||
value: "alu",
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ function setupProxySettings() {
|
|||
applyDropdownEventListeners(searchEngineDropdown!, checkSearxng);
|
||||
checkSearxng();
|
||||
|
||||
applyInputListeners(searxngUrlInput, "searxng");
|
||||
applyInputListeners(searxngUrlInput, "search");
|
||||
applyInputListeners(bareURLInput, "bareUrl");
|
||||
}
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ function checkSearxng() {
|
|||
// Callback for search engine dropdown
|
||||
const searchEngine = Alu.store.get("search");
|
||||
const searxInput = document.getElementsByClassName("setting__searxng-url")[0] as HTMLElement;
|
||||
if (searchEngine.value == "searx") {
|
||||
if (searchEngine.name == "Searx") {
|
||||
searxInput.style.opacity = "1";
|
||||
} else {
|
||||
searxInput.style.opacity = "0";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue