From 5acb70a706a6f847ee14a31c1785fdd1d5c16e8f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 25 Jul 2023 15:20:23 +0200 Subject: clear page onhashchange and add link via dom --- frontend/main.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'frontend/main.ts') diff --git a/frontend/main.ts b/frontend/main.ts index ad77f6f..b74f539 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -8,7 +8,7 @@ globalThis.addEventListener("hashchange", () => process_url()) globalThis.addEventListener("load", async () => { status_el = document.createElement("p") document.body.append(status_el) - + const bangs_res = await fetch("/bangs.json") if (!bangs_res.ok) document.writeln("error: could not download bangs.json") bangs = await bangs_res.json() @@ -16,10 +16,22 @@ globalThis.addEventListener("load", async () => { }) function setup_page(engine?: string) { + document.getElementById("content")?.remove() const section = document.createElement("section") + section.id = "content" if (engine) { - document.head.innerHTML += `` + if (document.getElementById("search-link")) { + // is already present, we need reload because browser wont notice otherwise + window.location.reload() + } + const link = document.createElement("link") + link.rel = "search" + link.id = "search-link" + link.type = "application/opensearchdescription+xml" + link.href = `/search.xml?default=${encodeURIComponent(engine)}` + link.title = `Laufente (defaults engine: ${engine})` + document.head.append(link) const heading = document.createElement("h1") heading.textContent = engine -- cgit v1.2.3-70-g09d2