aboutsummaryrefslogtreecommitdiff
path: root/frontend/main.ts
blob: 85de64e8b2117363e7253f6275b2110fda957c17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/// <reference lib="dom" />
import { bangs, load_bangs, process_query } from "./query.ts";
import { add_page_content, status } from "./ui.ts"

load_bangs()

globalThis.addEventListener("hashchange", () => process_url())
globalThis.addEventListener("load", () => process_url())

function process_url() {
    if (document.location.hash.length != 0) {
        const input = document.location.hash.substring(1)
        const [engine, query_encoded] = input.split("#")
        if (query_encoded) {
            const query = decodeURIComponent(query_encoded.replaceAll("+", " "))
            process_query(engine, query)
        } else {
            add_page_content(engine)
        }
        bangs.then(bangs => {
            console.log("bop");

            if (!bangs[engine]) {
                status("error", "Engine does not exist")
                window.location.hash = "#"
            }
        })
    } else {
        add_page_content()
    }
}