summaryrefslogtreecommitdiff
path: root/public/my_uptime.js
blob: 1fdb45728d86fc33c58323de81564809ab154d1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
async function updateUptime() {
  try {
    const res = await fetch("/api/my-uptime");
    if (!res.ok) return;
    const data = await res.json();

    const text = document.getElementById("Uptime");

    if (text && text.textContent !== data.uptime) {
      text.textContent = data.uptime;
    }
  } catch (e) {}
}

// Run on page load after all DOM elements loaded
document.addEventListener("DOMContentLoaded", () => {
  updateUptime();
  setInterval(updateUptime, 5 * 1000); // in ms
});