first commit
This commit is contained in:
105
public/js/app.js
Normal file
105
public/js/app.js
Normal file
@ -0,0 +1,105 @@
|
||||
// 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(':');
|
||||
|
||||
if (!host || !port) {
|
||||
alert('Please enter a valid connection string (host:port)');
|
||||
return;
|
||||
}
|
||||
|
||||
const statusResult = document.getElementById('statusResult');
|
||||
const statusContent = document.getElementById('statusContent');
|
||||
statusResult.classList.add('hidden');
|
||||
statusContent.innerHTML = '<p class="animate-pulse">Checking...</p>';
|
||||
|
||||
try {
|
||||
const response = await fetch(`/${edition}/${host}/${port}`);
|
||||
if (!response.ok) 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');
|
||||
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>
|
||||
`;
|
||||
}
|
||||
});
|
||||
|
||||
// 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'));
|
||||
}
|
Reference in New Issue
Block a user