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;
|
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";
|
import { Notyf } from "notyf";
|
||||||
|
|
||||||
const form = document.querySelector("form");
|
const form = document.querySelector("form");
|
||||||
let input = document.querySelector("input");
|
let input = document.querySelector("input")!;
|
||||||
document.addEventListener("astro:after-swap", initForm);
|
document.addEventListener("astro:after-swap", initForm);
|
||||||
function initForm() {
|
function initForm() {
|
||||||
const formEle = document.querySelector("form");
|
const formEle = document.querySelector("form") as HTMLFormElement;
|
||||||
input = document.querySelector("input");
|
input = document.querySelector("input") as HTMLInputElement;
|
||||||
if (formEle) formEle.addEventListener("submit", formEventListener);
|
if (formEle) formEle.addEventListener("submit", formEventListener);
|
||||||
}
|
}
|
||||||
if (form) {
|
if (form) {
|
||||||
|
|
@ -24,10 +24,9 @@
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
async function getProxyURL() {
|
async function getProxyURL() {
|
||||||
const preference = getProxyPreference();
|
const preference = Alu.store.get("proxy").value;
|
||||||
let url = input!.value.trim();
|
let url = input.value.trim();
|
||||||
if (!isUrl(url)) url = getSearchEngine() + url;
|
if (!isUrl(url)) url = getSearchEngine() + url;
|
||||||
else if (!(url.startsWith("https://") || url.startsWith("http://"))) url = "http://" + url;
|
|
||||||
if (preference === "ultraviolet") {
|
if (preference === "ultraviolet") {
|
||||||
return window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
return window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
||||||
} else if (preference == "rammerhead") {
|
} else if (preference == "rammerhead") {
|
||||||
|
|
@ -89,7 +88,7 @@
|
||||||
const backwardsButton = document.getElementById("nav-backwards") as HTMLImageElement;
|
const backwardsButton = document.getElementById("nav-backwards") as HTMLImageElement;
|
||||||
const forwardsButton = document.getElementById("nav-forwards") as HTMLImageElement;
|
const forwardsButton = document.getElementById("nav-forwards") as HTMLImageElement;
|
||||||
const shareButton = document.getElementById("nav-share") as HTMLImageElement;
|
const shareButton = document.getElementById("nav-share") as HTMLImageElement;
|
||||||
const preference = getProxyPreference();
|
const preference = Alu.store.get("proxy").value;
|
||||||
if (preference === "ultraviolet") {
|
if (preference === "ultraviolet") {
|
||||||
iframe.src = window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
iframe.src = window.__uv$config.prefix + window.__uv$config.encodeUrl(url);
|
||||||
} else if (preference == "rammerhead") {
|
} else if (preference == "rammerhead") {
|
||||||
|
|
@ -196,43 +195,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSearchEngine() {
|
function getSearchEngine() {
|
||||||
const searchEngine = Alu.store.get("search");
|
return Alu.store.get("search").value;
|
||||||
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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProxiedFavicon(iframe: HTMLIFrameElement) {
|
function updateProxiedFavicon(iframe: HTMLIFrameElement) {
|
||||||
if (!iframe) return;
|
|
||||||
const proxiedFavicon = document.getElementById("proxied-favicon") as HTMLImageElement;
|
const proxiedFavicon = document.getElementById("proxied-favicon") as HTMLImageElement;
|
||||||
if (iframe) {
|
if (iframe) {
|
||||||
if (iframe.contentDocument) {
|
if (iframe.contentDocument) {
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ const proxyList = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const searchEngineList = [
|
const searchEngineList = [
|
||||||
{ name: "Google", value: "google" },
|
{ name: "Google", value: "https://google.com/search?q=" },
|
||||||
{ name: "Bing", value: "bing" },
|
{ name: "Bing", value: "https://bing.com/search?q=" },
|
||||||
{ name: "Brave", value: "brave" },
|
{ name: "Brave", value: "https://search.brave.com/search?q=" },
|
||||||
{ name: "Searx", value: "searx" },
|
{ name: "Searx", value: "https://searxng.site/?q=" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const openPageWith = [
|
const openPageWith = [
|
||||||
|
|
@ -64,5 +64,5 @@ const wispURLList = [
|
||||||
</div>
|
</div>
|
||||||
<div class="setting__searxng-url">
|
<div class="setting__searxng-url">
|
||||||
<label aria-label="SearXNG URL" for="searxng-url-input" class="setting-label">{t("settings.proxy.searxngURL")}</label>
|
<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>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ const KEYSTORE: Alu.DefaultKeys = {
|
||||||
},
|
},
|
||||||
search: {
|
search: {
|
||||||
name: "Google",
|
name: "Google",
|
||||||
value: "google",
|
value: "https://google.com/search?q=",
|
||||||
},
|
},
|
||||||
openpage: {
|
openpage: {
|
||||||
name: "Embed",
|
name: "Embed",
|
||||||
|
|
@ -22,9 +22,6 @@ const KEYSTORE: Alu.DefaultKeys = {
|
||||||
name: "Epoxy",
|
name: "Epoxy",
|
||||||
value: "/epoxy/index.mjs",
|
value: "/epoxy/index.mjs",
|
||||||
},
|
},
|
||||||
searxng: {
|
|
||||||
value: "https://searxng.site",
|
|
||||||
},
|
|
||||||
theme: {
|
theme: {
|
||||||
name: "Alu",
|
name: "Alu",
|
||||||
value: "alu",
|
value: "alu",
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ function setupProxySettings() {
|
||||||
applyDropdownEventListeners(searchEngineDropdown!, checkSearxng);
|
applyDropdownEventListeners(searchEngineDropdown!, checkSearxng);
|
||||||
checkSearxng();
|
checkSearxng();
|
||||||
|
|
||||||
applyInputListeners(searxngUrlInput, "searxng");
|
applyInputListeners(searxngUrlInput, "search");
|
||||||
applyInputListeners(bareURLInput, "bareUrl");
|
applyInputListeners(bareURLInput, "bareUrl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,7 +299,7 @@ function checkSearxng() {
|
||||||
// Callback for search engine dropdown
|
// Callback for search engine dropdown
|
||||||
const searchEngine = Alu.store.get("search");
|
const searchEngine = Alu.store.get("search");
|
||||||
const searxInput = document.getElementsByClassName("setting__searxng-url")[0] as HTMLElement;
|
const searxInput = document.getElementsByClassName("setting__searxng-url")[0] as HTMLElement;
|
||||||
if (searchEngine.value == "searx") {
|
if (searchEngine.name == "Searx") {
|
||||||
searxInput.style.opacity = "1";
|
searxInput.style.opacity = "1";
|
||||||
} else {
|
} else {
|
||||||
searxInput.style.opacity = "0";
|
searxInput.style.opacity = "0";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue