-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
47 lines (40 loc) · 1.14 KB
/
index.ts
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
import aaia from './aaia';
const resetBtn = document.getElementById('reset-btn')!;
const submitBtn = document.getElementById('submit-btn')!;
const el = document.getElementById('ainput')!;
const output = document.getElementById('output')!;
const params = new URLSearchParams(document.location.search.slice(1));
const query = params.get('q');
const draw = function (data: string) {
output.innerHTML = '';
const d = aaia(data);
let o = '';
for (let index = 0; index < d.length; index += 1) {
const element = d[index];
if (element !== null) {
o += `${element} `;
}
}
output.innerHTML = o.trim();
};
if (query) {
el.value = query;
document.title = `aaia - ${query}`;
draw(query);
}
el.oninput = () => {
params.set('q', el.value);
document.title = `aaia - ${el.value}`;
window.history.replaceState({}, '', `/?${params}`);
draw(el.value);
if (el.value.length === 0) {
document.title = 'aaia - a as in alfa';
}
};
resetBtn.onclick = () => {
output.innerHTML = '';
el.value = '';
document.title = 'aaia - a as in alfa';
window.history.replaceState({}, '', '/');
};
submitBtn.onclick = () => draw(el.value);