Search Engine switching
This commit is contained in:
parent
4ea7ab5e11
commit
ab6f588fb1
3 changed files with 20 additions and 1 deletions
|
|
@ -46,6 +46,12 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
|
||||||
import { Settings } from "@utils/settings.ts";
|
import { Settings } from "@utils/settings.ts";
|
||||||
import { SW } from "@utils/proxy.ts";
|
import { SW } from "@utils/proxy.ts";
|
||||||
import { StoreManager } from "@utils/storage";
|
import { StoreManager } from "@utils/storage";
|
||||||
|
import { SearchEngines, type DropdownOptions } from "@utils/types";
|
||||||
|
const SearchEngineOptions: DropdownOptions[] = [];
|
||||||
|
Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
|
||||||
|
{ name: k, value: SearchEngines[k] }
|
||||||
|
));
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
sw: SW,
|
sw: SW,
|
||||||
|
|
@ -68,6 +74,14 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchEngine = async (opts: Options) => {
|
||||||
|
const seEl = document.getElementById("dropdownBox-sSwitcher") as HTMLSelectElement;
|
||||||
|
seEl.value = opts.storageManager.getVal("searchEngine") || "ddg";
|
||||||
|
seEl.addEventListener("change", async () => {
|
||||||
|
opts.settings.searchEngine(seEl.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("astro:page-load", async () => {
|
document.addEventListener("astro:page-load", async () => {
|
||||||
try {
|
try {
|
||||||
const settings = await Settings.getInstance();
|
const settings = await Settings.getInstance();
|
||||||
|
|
@ -75,6 +89,7 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
|
||||||
const storageManager = new StoreManager<"radius||settings">("radius||settings");
|
const storageManager = new StoreManager<"radius||settings">("radius||settings");
|
||||||
await transport({settings, sw, storageManager});
|
await transport({settings, sw, storageManager});
|
||||||
await proxy({settings, sw, storageManager});
|
await proxy({settings, sw, storageManager});
|
||||||
|
await searchEngine({settings, sw, storageManager});
|
||||||
} catch (err) { console.log(err) }
|
} catch (err) { console.log(err) }
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class SW {
|
||||||
|
|
||||||
encodeURL(string: string): string {
|
encodeURL(string: string): string {
|
||||||
const proxy = this.#storageManager.getVal("proxy") as 'uv' | 'sj';
|
const proxy = this.#storageManager.getVal("proxy") as 'uv' | 'sj';
|
||||||
const input = this.#search(string, "https://google.com/search?q=%s");
|
const input = this.#search(string, this.#storageManager.getVal('searchEngine'));
|
||||||
return proxy === 'uv' ? `${__uv$config.prefix}${__uv$config.encodeUrl!(input)}` : this.#scramjetController!.encodeUrl(input)
|
return proxy === 'uv' ? `${__uv$config.prefix}${__uv$config.encodeUrl!(input)}` : this.#scramjetController!.encodeUrl(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,10 @@ class Settings {
|
||||||
proxy(prox: 'uv' | 'sj') {
|
proxy(prox: 'uv' | 'sj') {
|
||||||
this.#storageManager.setVal('proxy', prox);
|
this.#storageManager.setVal('proxy', prox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchEngine(engine: string) {
|
||||||
|
this.#storageManager.setVal('searchEngine', engine);
|
||||||
|
}
|
||||||
|
|
||||||
async *#init() {
|
async *#init() {
|
||||||
yield this.theme(this.#storageManager.getVal('theme') || 'default');
|
yield this.theme(this.#storageManager.getVal('theme') || 'default');
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue