Files: 706e99a769b070931c21d59e78030c60a37afc48 / modules_basic / timestamp.js
1022 bytesRaw
1 | const getStyleForModule = require('../get-style-for-module') |
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: getStyleForModule(__filename) |
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