-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
77 lines (70 loc) · 2.63 KB
/
index.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html>
<html lang="en">
<head>
<title>Kef’s Old English Dictionary</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Uncial+Antiqua&display=swap">
<style>
h1 {
font-family: "Uncial Antiqua", serif;
}
</style>
</head>
<body>
<h1>Kef’s Old English Dictionary</h1>
<p>
Copyright © 2021–2024 Kef Schecter.
<a href="https://github.com/furrykef/oedict">Check us out on github!</a>
</p>
<p><input id="search_terms" autofocus> <button id="search" onclick="search()" type="button">🔍</button></p>
<input type="radio" id="oe" name="search_type" value="oe" checked>
<label for="oe">Old → Modern</label>
<br>
<input type="radio" id="reverse" name="search_type" value="reverse">
<label for="reverse">Modern → Old</label>
<div id="definitions">
</div>
<script>
"use strict";
// Make pressing enter click the search button
document.getElementById("search_terms").addEventListener("keyup", event => {
if(event.key !== "Enter") return;
document.getElementById("search").click();
event.preventDefault();
});
function search() {
const search_terms = document.getElementById("search_terms").value;
const search_type = document.querySelector("input[name=search_type]:checked").value;
search_impl(search_terms, search_type);
history.pushState({}, "", `/dict/${search_type}/${encodeURIComponent(search_terms)}`);
}
function search_impl(search_terms, search_type) {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
document.getElementById("definitions").innerHTML = xhr.responseText;
};
xhr.open("GET", `/api/search/${search_type}/${encodeURIComponent(search_terms)}`);
xhr.send();
}
function loadFromUrl(url) {
const result = decodeURI(url).match(/\/dict\/(oe|reverse)\/(.*)/);
if (result) {
const search_type = result[1];
const search_terms = result[2];
document.getElementById("search_terms").value = search_terms;
if (search_type == "reverse") {
document.getElementById("reverse").checked = true;
} else {
document.getElementById("oe").checked = true;
}
search_impl(search_terms, search_type);
}
}
addEventListener("popstate", (event) => {
loadFromUrl(location.pathname)
});
// If the URL has a search in it when we first load,
// conduct the search
loadFromUrl(location.pathname);
</script>
</body>
</html>