Files: 164ff0f5cab3f959bf2612a84138a9f46df599ee / modules_basic / timestamp.js
1020 bytesRaw
1 | const fs = require('fs') |
2 | const h = require('../h') |
3 | const human = require('human-time') |
4 | |
5 | exports.needs = {} |
6 | |
7 | exports.gives = { |
8 | timestamp: true, |
9 | mcss: true |
10 | } |
11 | |
12 | exports.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