-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (35 loc) · 1.42 KB
/
app.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
43
44
45
import { h } from './lib/h.js'
import { human } from './lib/human.js'
import { open } from './sbog.js'
const renderer = new marked.Renderer()
renderer.link = function (href, title, text) {
if (href.length == 44 && !href.startsWith('http')) {
href = 'https://bogbook.com/#' + href
return marked.Renderer.prototype.link.call(this, href, title, text);
} else {
return marked.Renderer.prototype.link.call(this, href, title, text);
}
}
marked.setOptions({
renderer: renderer
})
const pubkey = 'EVs6toXH1DdpDpHEA5qm1eXS6xtg7+dkNH2t0GjoUH0='
const div = h('a', {href: 'https://bogbook.com/#' + pubkey}, [pubkey])
const container = document.getElementById('container')
container.appendChild(div)
const ws = new WebSocket('wss://bogbook.com')
ws.onopen = async () => {
ws.send(pubkey)
}
ws.onmessage = async (m) => {
const obj = JSON.parse(m.data)
console.log(obj)
const opened = await open(obj.payload)
if (opened && obj.payload.substring(0, 44) === pubkey && !document.getElementById('message')) {
div.textContent = obj.name
const messageDiv = h('article', {id: 'message', innerHTML: marked(obj.text)})
container.insertBefore(h('a', {style: 'float: right', href: 'https://bogbook.com/#' + opened.hash}, [human(new Date(opened.timestamp))]), div)
container.appendChild(messageDiv)
container.after(h('div', ['More on ↳ ', h('a', {href: 'https://bogbook.com/#' + pubkey}, ['Bogbook'])]))
}
}