2024-10-11 17:38:29 -04:00
|
|
|
async function ping(url) {
|
2024-11-13 16:25:02 -05:00
|
|
|
const start = performance.now();
|
|
|
|
try {
|
2024-10-11 17:38:29 -04:00
|
|
|
await fetch(url);
|
|
|
|
const end = performance.now();
|
|
|
|
return end - start;
|
2024-11-13 16:25:02 -05:00
|
|
|
} catch (error) {
|
2024-10-11 17:38:29 -04:00
|
|
|
console.error(`Error pinging ${url}:`, error);
|
|
|
|
return Infinity;
|
2024-11-13 16:25:02 -05:00
|
|
|
}
|
2024-10-11 17:38:29 -04:00
|
|
|
}
|
2024-11-13 16:25:02 -05:00
|
|
|
|
2024-10-11 17:38:29 -04:00
|
|
|
async function testPing() {
|
2024-11-13 16:25:02 -05:00
|
|
|
const urls = [
|
|
|
|
'https://old.aidxn.fun/ping.html',
|
2024-10-11 17:38:29 -04:00
|
|
|
'https://kantor.aidxn.fun/ping',
|
2024-11-13 16:25:02 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
const pingResults = await Promise.all(
|
2024-10-11 17:38:29 -04:00
|
|
|
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-10-11 17:38:29 -04:00
|
|
|
})
|
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 => {
|
2024-10-11 17:38:29 -04:00
|
|
|
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]';
|
|
|
|
}
|
2024-10-11 17:38:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = () => {
|
2024-11-13 16:25:02 -05:00
|
|
|
testPing();
|
2024-10-11 17:38:29 -04:00
|
|
|
};
|