blob: 3c301a11fa33280166c9ff00bef039080489b7e0 (
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
|
/// <reference lib="dom" />
import { load_bangs, process_query } from "./query.ts"
import { add_page_content } from "./ui.ts"
load_bangs()
globalThis.addEventListener("hashchange", () => process_url(true))
globalThis.addEventListener("load", () => process_url(false))
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("#")
if (query_encoded) {
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 {
add_page_content()
}
}
|