/* === Live ISS crew mission‑time counter ================================ */ (() => { const elems = document.querySelectorAll('.time-in-space'); if (!elems.length) return; const format = (totalSec, withSec) => { const d = Math.floor(totalSec / 86400); const h = Math.floor((totalSec % 86400) / 3600); const m = Math.floor((totalSec % 3600) / 60); const s = totalSec % 60; return withSec ? `${d}d ${h}h ${m}m ${s}s` : `${d}d ${h}h ${m}m`; }; const update = () => { const nowUtcSec = Math.floor(Date.now() / 1000); const showSecs = window.innerWidth >= 768; elems.forEach(el => { const launched = Number(el.dataset.launched); if (!launched || isNaN(launched)) { el.textContent = '—'; return; } if (launched > nowUtcSec) { el.textContent = 'Not yet launched'; return; } const diff = nowUtcSec - launched; el.textContent = format(diff, showSecs); }); }; update(); setInterval(update, 1000); })();