summaryrefslogtreecommitdiff
path: root/public/my_uptime.js
blob: b5f3ca2e27aef82c7045078e42f5b9c2aec555d3 (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("htmx:load", () => {
  updateUptime();
  setInterval(updateUptime, 5 * 1000); // in ms
});