git ssb

16+

Dominic / patchbay



Tree: 80807add560dfbbd3fe40aa17eac62b859624063

Files: 80807add560dfbbd3fe40aa17eac62b859624063 / modules_basic / timestamp.js

1020 bytesRaw
1const fs = require('fs')
2const h = require('../h')
3const human = require('human-time')
4
5exports.needs = {}
6
7exports.gives = {
8 timestamp: true,
9 mcss: true
10}
11
12exports.create = function () {
13 setInterval(function () {
14 var els = [].slice.call(document.querySelectorAll('.Timestamp'))
15 els.forEach(updateTimestampEl)
16 }, 60e3)
17
18 return {
19 timestamp,
20 mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
21 }
22
23 function updateTimestampEl (el) {
24 var timestamp = Number(el.getAttribute('data-timestamp'))
25 var display = human(new Date(timestamp)).replace(/minutes/, 'mins')
26 el.querySelector('a').firstChild.nodeValue = display
27 return el
28 }
29
30 function timestamp (msg) {
31 var { key, value } = msg
32 var { timestamp } = value
33 var el = h('Timestamp', {
34 attributes: {
35 'data-timestamp': timestamp
36 }
37 }, [
38 h('a', {
39 href: `#${key}`,
40 title: new Date(timestamp)
41 }, '')
42 ])
43 updateTimestampEl(el)
44 return el
45 }
46}
47

Built with git-ssb-web