const mine = { 'colorful-shadow': '194.32.107.224', 'moonlit-surf': '91.190.155.20', 'gorgeous-sunset': '188.93.140.100', 'precious-leaf': '185.236.11.24', 'icy-grove': '86.106.182.4', }; function humanByteSize(input) { if (input <= 0) { return '0 B'; } const i = Math.floor(Math.log(input) / Math.log(1000)); return (input / Math.pow(1000, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i]; } // Convert seconds to human friendly time, with days function humanTime(input) { const days = Math.floor(input / 86400); const hours = Math.floor(input % 86400 / 3600); const minutes = Math.floor(input % 3600 / 60); return `${days}d ${hours}h ${minutes}m`; } async function getRelayData() { const response = await fetch('https://relays.syncthing.net/endpoint/full'); if (!response.ok) { return; } const data = await response.json(); const relays = data.relays; for (const mineName in mine) { const ip = mine[mineName]; const relay = relays.find(current => current.url.includes(ip)); if (!relay) { console.log(mineName, 'not found'); continue; } const { stats } = relay; const element = document.querySelector(`#${mineName} .stats`); if (!element || !stats) { continue; } const text = `${humanTime(stats.uptimeSeconds)} / ${humanByteSize(stats.bytesProxied)}`; element.textContent = text; } } window.addEventListener('DOMContentLoaded', getRelayData);