aboutsummaryrefslogtreecommitdiff
path: root/frontend/start.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-08-01 17:25:45 +0200
committermetamuffin <metamuffin@disroot.org>2023-08-01 17:25:45 +0200
commit7b1cb4e58347758cab25b73dc6486f5f90efa6df (patch)
treeaec1c130bdbf576394aeb3b488d8888f31eaa2f2 /frontend/start.ts
parent7c933642730dd5b935281f2cc938f2998e3a4114 (diff)
downloadfastbangs-7b1cb4e58347758cab25b73dc6486f5f90efa6df.tar
fastbangs-7b1cb4e58347758cab25b73dc6486f5f90efa6df.tar.bz2
fastbangs-7b1cb4e58347758cab25b73dc6486f5f90efa6df.tar.zst
refactor dom interaction with helper function
Diffstat (limited to 'frontend/start.ts')
-rw-r--r--frontend/start.ts56
1 files changed, 56 insertions, 0 deletions
diff --git a/frontend/start.ts b/frontend/start.ts
new file mode 100644
index 0000000..1bb1cbb
--- /dev/null
+++ b/frontend/start.ts
@@ -0,0 +1,56 @@
+import { e } from "./helper.ts";
+import { bangs } from "./query.ts";
+import { status } from "./ui.ts"
+
+export function section_info_start() {
+ return e("section", { class: "info" },
+ e("h1", {}, "Fastbangs"),
+ e("p", {}, `
+ This application provides a way to (mostly) locally handle search bangs.
+ First select a default engine to use, then register this page as a search in your browser
+ `)
+ )
+}
+
+export function section_engine_select() {
+ const section = document.createElement("section")
+ section.classList.add("engine-select")
+
+ const select = async (e: string) => {
+ const engine = e.toLowerCase();
+ if (!(await bangs)[engine]) return status("error", `Engine ${JSON.stringify(e)} does not exist.`)
+ window.location.hash = `#${e}`
+ }
+
+ const heading = document.createElement("h2")
+ heading.textContent = "Select a search engine"
+
+ const listing = document.createElement("ul")
+ bangs.then(bangs => {
+ for (const key in bangs) if (bangs[key]!.pinned) {
+ listing.prepend(e("li", { class: "pinned", onclick: () => select(key) }, bangs[key]!.name ?? key))
+ }
+ })
+
+ const input = document.createElement("input")
+ input.type = "input"
+ input.addEventListener("keydown", ev => {
+ if (ev.code == "Enter") select(input.value)
+ })
+
+ const submit = document.createElement("button")
+ submit.textContent = "Select"
+ submit.addEventListener("click", () => select(input.value))
+
+ listing.append(e("li", {},
+ e("label", {}, "Select other engine by bang:"),
+ input,
+ submit
+ ))
+
+ section.append(heading, listing)
+ return e("section", { class: "engine-select" },
+ e("h2", {}, "Select a search engine"),
+ listing
+ )
+}