2023-10-31 15:28:28 +01:00
|
|
|
const mine = {
|
|
|
|
'colorful-shadow': '194.32.107.224',
|
|
|
|
'hidden-ocean': '89.105.197.88',
|
2024-04-25 01:18:24 +02:00
|
|
|
'moonlit-surf': '91.190.155.20',
|
|
|
|
'gorgeous-sunset': '188.93.140.100',
|
2023-10-31 15:28:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function humanByteSize(input) {
|
|
|
|
if (input <= 0) {
|
|
|
|
return '0 B';
|
|
|
|
}
|
|
|
|
|
2023-10-31 15:38:06 +01:00
|
|
|
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];
|
2023-10-31 15:28:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
2024-06-02 22:32:10 +02:00
|
|
|
const response = await fetch('https://relays.syncthing.net/endpoint/full');
|
2023-10-31 15:28:28 +01:00
|
|
|
|
|
|
|
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) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const text = `${humanTime(stats.uptimeSeconds)} / ${humanByteSize(stats.bytesProxied)}`;
|
|
|
|
element.textContent = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('DOMContentLoaded', getRelayData);
|