diff options
author | Lia Lenckowski <lialenck@protonmail.com> | 2023-08-21 02:12:12 +0200 |
---|---|---|
committer | Lia Lenckowski <lialenck@protonmail.com> | 2023-08-21 02:12:30 +0200 |
commit | 49f8a190a5de848a834e82749799295fe9a4bc50 (patch) | |
tree | 2068a4d71d67b2d75c23d8940e77385ba60beb27 /frontend | |
parent | 11bc80ddb4c5fabdd199b03f35c8977380a0c618 (diff) | |
download | fastbangs-49f8a190a5de848a834e82749799295fe9a4bc50.tar fastbangs-49f8a190a5de848a834e82749799295fe9a4bc50.tar.bz2 fastbangs-49f8a190a5de848a834e82749799295fe9a4bc50.tar.zst |
fix chrome opensearch autodiscover
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/main.ts | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/frontend/main.ts b/frontend/main.ts index 7f1041a..3c301a1 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -4,10 +4,10 @@ import { add_page_content } from "./ui.ts" load_bangs() -globalThis.addEventListener("hashchange", () => process_url()) -globalThis.addEventListener("load", () => process_url()) +globalThis.addEventListener("hashchange", () => process_url(true)) +globalThis.addEventListener("load", () => process_url(false)) -function process_url() { +function process_url(is_hashchange: boolean) { if (document.location.hash.length != 0) { const input = document.location.hash.substring(1) const [engine, query_encoded] = input.split("#") @@ -15,6 +15,11 @@ function process_url() { const query = decodeURIComponent(query_encoded.replaceAll("+", " ")) process_query(engine, query) } else { + if (is_hashchange) + // chromium won't autodiscover the search engine if we add the link tag + // after a hashchange, so we reload the page, such that we are immediately + // on the page where we will put the link. + window.location.reload() add_page_content(engine) } } else { |