aboutsummaryrefslogtreecommitdiff
path: root/static/js/manage.js
blob: 475361d26891561ff954a069c0e6268fd81a2f5c (plain) (blame)
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
43
44
function addtime(e) {
  e.preventDefault();
  document.getElementById("seconds").value = this.dataset.secs;
}

function pvw(e) {
  prev = document.getElementById("prev_desc");
  prev.innerHTML = desc.value;
  prev.style.display = "block";
  prev.addEventListener("input", function() { desc.value = prev.innerHTML; });
}

function timeAgo(timestamp) {
  var time = Math.round(Date.now() / 1000);
  var el = time - timestamp;
  if (el == 0) return "un instante";
  else if (el == 1) return "un segundo";
  else if (el < 60) return el + " segundos";
  else if (el < 120) return "un minuto";
  else if (el < 3600) return Math.round(el / 60) + " minutos";
  else if (el < 7200) return "una hora";
  else if (el < 86400) return Math.round(el / 3600) + " horas";
  else if (el < 172800) return "un día";
  else if (el < 2628000) return Math.round(el / 86400) + " días";
  else if (el < 5256000) return "un mes";
  else if (el < 31536000) return Math.round(el / 2628000) + " meses";
  else if (el > 31535999) return "más de un año";
}

document.addEventListener("DOMContentLoaded", function(e) {
  var list = document.getElementById("timelist");
  if (list) {
    var secs = document.getElementById("timelist").getElementsByTagName("a");
    for(var i=0;i<secs.length;i++) secs[i].addEventListener("click", addtime);
  }
  var tss = document.getElementsByName("timestamp");
  for (var i = 0; i < tss.length; i++){
    tss[i].title = tss[i].textContent;
    tss[i].textContent = timeAgo(tss[i].dataset.ts);
  }

  desc = document.getElementById("brd_desc");
  if (desc) desc.addEventListener("input", pvw);
});