forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
34 lines (29 loc) Β· 774 Bytes
/
index.js
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
for (let time of document.body.getElementsByTagName('time')) {
time.setAttribute('title', new Date(time.textContent));
}
let next = document.querySelector('a.next');
let prev = document.querySelector('a.prev');
window.addEventListener('keydown', e => {
if (document.activeElement.tagName == 'INPUT') {
return;
}
switch (e.key) {
case 'ArrowRight':
if (next) {
window.location = next.href;
}
return;
case 'ArrowLeft':
if (prev) {
window.location = prev.href;
}
return;
}
});
const search = document.querySelector('form[action="/search"]');
const query = search.querySelector('input[name="query"]');
search.addEventListener('submit', (e) => {
if (!query.value) {
e.preventDefault();
}
});