21 lines
707 B
HTML
21 lines
707 B
HTML
{{define "foot"}}<script>
|
|
// live relative-time counters (#46): tick any [data-ts] (epoch seconds) every second
|
|
(function () {
|
|
function fmt(ts) {
|
|
const s = Math.max(0, Math.floor(Date.now() / 1000) - ts);
|
|
if (s < 60) return s + 's ago';
|
|
if (s < 3600) return Math.floor(s / 60) + 'm ago';
|
|
if (s < 86400) return Math.floor(s / 3600) + 'h ago';
|
|
return Math.floor(s / 86400) + 'd ago';
|
|
}
|
|
function tick() {
|
|
document.querySelectorAll('[data-ts]').forEach(el => {
|
|
const ts = parseInt(el.dataset.ts, 10);
|
|
if (!isNaN(ts)) el.textContent = fmt(ts);
|
|
});
|
|
}
|
|
setInterval(tick, 1000);
|
|
document.addEventListener('DOMContentLoaded', tick);
|
|
tick();
|
|
})();
|
|
</script>{{end}} |