1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// human-time by Dave Eddy https://github.com/bahamas10/human
function human(seconds) {
if (seconds instanceof Date)
seconds = Math.round((Date.now() - seconds) / 1000);
var prefix = seconds < 0 ? 'post' : 'antaŭ';
seconds = Math.abs(seconds);
var times = [
seconds / 60 / 60 / 24 / 365, // years
seconds / 60 / 60 / 24 / 30, // months
seconds / 60 / 60 / 24 / 7, // weeks
seconds / 60 / 60 / 24, // days
seconds / 60 / 60, // hours
seconds / 60, // minutes
seconds // seconds
];
var names = ['jaro', 'monato', 'semajno', 'tago', 'horo', 'minuto', 'sekundo'];
for (var i = 0; i < names.length; i++) {
var time = Math.floor(times[i]);
var name = names[i];
if (time > 1)
name += 'j';
if (time >= 1)
return prefix + ' ' + time + ' ' + name;
}
return 'ĝuste nun';
}
// hscrpt by Dominic Tarr https://github.com/dominictarr/hscrpt/blob/master/LICENSE
function h (tag, attrs, content) {
if(Array.isArray(attrs)) content = attrs, attrs = {}
var el = document.createElement(tag)
for(var k in attrs) el[k] = attrs[k]
if(content) content.forEach(function (e) {
if(e) el.appendChild('string' == typeof e ? document.createTextNode(e) : e)
})
return el
}
|