-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute.js
42 lines (34 loc) · 1 KB
/
route.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
35
36
37
38
39
40
41
42
import { h } from './lib/misc.js'
import { home } from './routes/home.js'
import { query } from './routes/query.js'
import { keyroute } from './routes/key.js'
import { keys } from './keys.js'
import { plainTextName } from './avatar.js'
export function route (container) {
const screen = h('div', {id: 'screen'})
const scroller = h('div', {id: 'scroller'})
container.appendChild(screen)
screen.appendChild(scroller)
const src = window.location.hash.substring(1)
if (src.length == 43) {
window.location.hash = src + '='
}
const id = location.hash.substring(1)
if (id.length == 44) {
document.title = location.host + ' | ' + plainTextName(id) + ' | ' + id
}
if (location.hash.substring(1) === '') {
document.title = location.host + ' | Home'
}
if (src === '') {
home(scroller)
} else if (src === 'key') {
keyroute(scroller)
} else {
query(scroller, src)
}
window.onhashchange = function () {
screen.parentNode.removeChild(screen)
route(container)
}
}