Search Engine switching
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user