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 { SW } from "@utils/proxy.ts";
|
||||
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 = {
|
||||
settings: Settings,
|
||||
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 () => {
|
||||
try {
|
||||
const settings = await Settings.getInstance();
|
||||
|
|
@ -75,6 +89,7 @@ Object.keys(SearchEngines).forEach((k) => SearchEngineOptions.push(
|
|||
const storageManager = new StoreManager<"radius||settings">("radius||settings");
|
||||
await transport({settings, sw, storageManager});
|
||||
await proxy({settings, sw, storageManager});
|
||||
await searchEngine({settings, sw, storageManager});
|
||||
} catch (err) { console.log(err) }
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class SW {
|
|||
|
||||
encodeURL(string: string): string {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,10 @@ class Settings {
|
|||
this.#storageManager.setVal('proxy', prox);
|
||||
}
|
||||
|
||||
searchEngine(engine: string) {
|
||||
this.#storageManager.setVal('searchEngine', engine);
|
||||
}
|
||||
|
||||
async *#init() {
|
||||
yield this.theme(this.#storageManager.getVal('theme') || 'default');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue