126 lines
5.5 KiB
JavaScript
126 lines
5.5 KiB
JavaScript
// Initialize tsParticles
|
|
tsParticles.load("particles-js", {
|
|
particles: {
|
|
number: { value: 50, density: { enable: true, value_area: 800 } },
|
|
color: { value: ["#60a5fa", "#a855f7", "#ec4899"] },
|
|
shape: { type: "circle" },
|
|
opacity: { value: 0.5, random: true },
|
|
size: { value: 3, random: true },
|
|
move: { enable: true, speed: 0.5, direction: "none", random: true, out_mode: "out" },
|
|
},
|
|
interactivity: {
|
|
events: { onhover: { enable: true, mode: "repulse" }, onclick: { enable: true, mode: "push" } },
|
|
modes: { repulse: { distance: 100, duration: 0.4 }, push: { particles_nb: 4 } },
|
|
},
|
|
retina_detect: true
|
|
});
|
|
|
|
// Confetti function
|
|
function launchConfetti() {
|
|
confetti({
|
|
particleCount: 100,
|
|
spread: 70,
|
|
origin: { y: 0.6 },
|
|
colors: ['#60a5fa', '#a855f7', '#ec4899']
|
|
});
|
|
}
|
|
|
|
// Form submission handler
|
|
document.getElementById('serverForm').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const edition = document.getElementById('edition').value;
|
|
const connection = document.getElementById('connection').value;
|
|
const [host, port] = connection.split(':');
|
|
const loadingSpinner = document.getElementById('loadingSpinner');
|
|
const statusResult = document.getElementById('statusResult');
|
|
const statusContent = document.getElementById('statusContent');
|
|
const submitButton = e.target.querySelector('button[type="submit"]');
|
|
|
|
if (!host || !port) {
|
|
alert('Please enter a valid connection string (host:port)');
|
|
return;
|
|
}
|
|
|
|
// Show loading spinner and disable button
|
|
loadingSpinner.style.display = 'block';
|
|
submitButton.disabled = true;
|
|
statusResult.classList.add('hidden');
|
|
statusContent.innerHTML = '<p class="animate-pulse">Checking...</p>';
|
|
|
|
try {
|
|
const response = await fetch(`/${edition}/${host}/${port}`);
|
|
if (!response.ok) {
|
|
if (response.status === 429) {
|
|
throw new Error('RateLimit');
|
|
}
|
|
throw new Error('Request failed');
|
|
}
|
|
const result = await response.json();
|
|
|
|
statusResult.classList.remove('hidden');
|
|
if (result.isOnline) {
|
|
launchConfetti();
|
|
const { data } = result;
|
|
const statusData = {};
|
|
|
|
if (edition === 'java') {
|
|
if (data.version?.name?.clean) statusData['Version'] = data.version.name.clean;
|
|
if (data.version?.protocol) statusData['Protocol'] = data.version.protocol;
|
|
if (data.players?.online != null) statusData['Players Online'] = data.players.online;
|
|
if (data.players?.max != null) statusData['Max Players'] = data.players.max;
|
|
if (data.motd?.clean) statusData['MOTD'] = data.motd.clean;
|
|
if (data.favicon) statusData['Favicon'] = 'Present';
|
|
if (data.srv_record) statusData['SRV Record'] = JSON.stringify(data.srv_record);
|
|
if (data.mods) statusData['Mods'] = JSON.stringify(data.mods);
|
|
} else {
|
|
if (data.version) statusData['Version'] = data.version;
|
|
if (data.protocol_version) statusData['Protocol'] = data.protocol_version;
|
|
if (data.online_players != null) statusData['Players Online'] = data.online_players;
|
|
if (data.max_players != null) statusData['Max Players'] = data.max_players;
|
|
if (data.motd) statusData['MOTD'] = data.motd.clean;
|
|
if (data.gamemode) statusData['Gamemode'] = data.gamemode;
|
|
if (data.server_id) statusData['Server ID'] = data.server_id;
|
|
}
|
|
|
|
statusContent.innerHTML = `
|
|
<p><strong class="text-blue-400">Status:</strong> <span class="text-green-400">Online</span></p>
|
|
${Object.entries(statusData).map(([key, value]) => `
|
|
<p><strong class="text-blue-400">${key}:</strong> ${value}</p>
|
|
`).join('')}
|
|
`;
|
|
} else {
|
|
statusContent.innerHTML = `
|
|
<p><strong class="text-blue-400">Status:</strong> <span class="text-red-400">Offline</span></p>
|
|
<p><strong class="text-blue-400">Error:</strong> Server is not reachable</p>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
statusResult.classList.remove('hidden');
|
|
if (error.message === 'RateLimit') {
|
|
statusContent.innerHTML = `
|
|
<p><strong class="text-blue-400">Status:</strong> <span class="text-yellow-400">Rate Limited</span></p>
|
|
<p><strong class="text-blue-400">Message:</strong> You are sending requests too quickly. Please try again in a moment.</p>
|
|
`;
|
|
} else {
|
|
statusContent.innerHTML = `
|
|
<p><strong class="text-blue-400">Status:</strong> <span class="text-red-400">Error</span></p>
|
|
<p><strong class="text-blue-400">Error:</strong> An error occurred while checking the server status</p>
|
|
`;
|
|
}
|
|
} finally {
|
|
// Hide loading spinner and re-enable button
|
|
loadingSpinner.style.display = 'none';
|
|
submitButton.disabled = false;
|
|
}
|
|
});
|
|
|
|
// Handle URL-based checks
|
|
const path = window.location.pathname.split('/');
|
|
if (path[1] && path[2] && path[3]) {
|
|
const edition = path[1];
|
|
const host = path[2];
|
|
const port = path[3];
|
|
document.getElementById('edition').value = edition;
|
|
document.getElementById('connection').value = `${host}:${port}`;
|
|
document.getElementById('serverForm').dispatchEvent(new Event('submit'));
|
|
} |