Files: 449d051990b8d8149dd2a3bb9078e269533e324e / 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