aidxnFUNretro/js/status.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

async function ping(url) {
2024-11-13 16:25:02 -05:00
const start = performance.now();
try {
await fetch(url);
const end = performance.now();
return end - start;
2024-11-13 16:25:02 -05:00
} catch (error) {
console.error(`Error pinging ${url}:`, error);
return Infinity;
2024-11-13 16:25:02 -05:00
}
}
2024-11-13 16:25:02 -05:00
async function testPing() {
2024-11-13 16:25:02 -05:00
const urls = [
'https://old.aidxn.fun/ping.html',
'https://kantor.aidxn.fun/ping',
2024-11-13 16:25:02 -05:00
];
const pingResults = await Promise.all(
urls.map(async (url) => {
2024-11-13 16:25:02 -05:00
const time = await ping(url);
if (url === 'https://old.aidxn.fun/ping.html') {
const website = document.getElementById("website");
website.textContent = `[ONLINE - ${time} ms]`
}
if (url === 'https://kantor.aidxn.fun/ping') {
const status1 = document.getElementById("status1");
status1.textContent = `[ONLINE - ${time} ms]`
status1.className = 'text-green-500 font-bold';
}
return { url, time };
})
2024-11-13 16:25:02 -05:00
);
pingResults.sort((a, b) => a.time - b.time);
console.log('Fastest server:', pingResults[0].url);
pingResults.forEach(result => {
console.log(`${result.url}: ${result.time.toFixed(2)} ms`);
2024-11-13 16:25:02 -05:00
});
const fastestServer = pingResults[0].url;
if (fastestServer === 'https://old.aidxn.fun/ping.html') {
oldText = website.textContent;
website.textContent = oldText + ' [FASTEST]';
}
if (fastestServer === 'https://kantor.aidxn.fun/ping') {
oldText = status1.textContent;
status1.textContent = oldText + ' [FASTEST]';
}
}
window.onload = () => {
2024-11-13 16:25:02 -05:00
testPing();
};