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