add status js
This commit is contained in:
parent
77a41124bb
commit
82eb9825bd
64
src/js/status.js
Normal file
64
src/js/status.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
async function ping(url) {
|
||||||
|
const start = performance.now();
|
||||||
|
try {
|
||||||
|
await fetch(url);
|
||||||
|
const end = performance.now();
|
||||||
|
return end - start;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error pinging ${url}:`, error);
|
||||||
|
return Infinity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testPing() {
|
||||||
|
const urls = [
|
||||||
|
'https://aidxn.fun/ping',
|
||||||
|
'https://kantor.aidxn.fun/ping',
|
||||||
|
'https://api.aidxn.fun/ping'
|
||||||
|
];
|
||||||
|
|
||||||
|
const pingResults = await Promise.all(
|
||||||
|
urls.map(async (url) => {
|
||||||
|
const time = await ping(url);
|
||||||
|
if (url === 'https://aidxn.fun/ping') {
|
||||||
|
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.class = 'text-green-500 font-bold';
|
||||||
|
}
|
||||||
|
if (url === 'https://api.aidxn.fun/ping') {
|
||||||
|
const api = document.getElementById("api");
|
||||||
|
api.textContent = `[ONLINE - ${time} ms]`
|
||||||
|
api.class = 'text-green-500 font-bold';
|
||||||
|
}
|
||||||
|
return { url, time };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
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`);
|
||||||
|
});
|
||||||
|
const fastestServer = pingResults[0].url;
|
||||||
|
if (fastestServer === 'https://aidxn.fun/ping') {
|
||||||
|
oldText = website.textContent;
|
||||||
|
website.textContent = oldText + ' [FASTEST]';
|
||||||
|
}
|
||||||
|
if (fastestServer === 'https://kantor.aidxn.fun/ping') {
|
||||||
|
oldText = status1.textContent;
|
||||||
|
status1.textContent = oldText + ' [FASTEST]';
|
||||||
|
}
|
||||||
|
if (fastestServer === 'https://api.aidxn.fun/ping') {
|
||||||
|
oldText = api.textContent;
|
||||||
|
api.textContent = oldText + ' [FASTEST]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = () => {
|
||||||
|
testPing();
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user