update to add widget section

This commit is contained in:
MCHost
2025-07-03 02:51:10 -04:00
parent 827799b7cb
commit c464f3b3b5
5 changed files with 180 additions and 34 deletions

View File

@ -34,6 +34,8 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
const loadingSpinner = document.getElementById('loadingSpinner');
const statusResult = document.getElementById('statusResult');
const statusContent = document.getElementById('statusContent');
const widgetSection = document.getElementById('widgetSection');
const widgetCode = document.getElementById('widgetCode');
const submitButton = e.target.querySelector('button[type="submit"]');
if (!host || !port) {
@ -45,6 +47,7 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
loadingSpinner.style.display = 'block';
submitButton.disabled = true;
statusResult.classList.add('hidden');
widgetSection.classList.add('hidden');
statusContent.innerHTML = '<p class="animate-pulse">Checking...</p>';
try {
@ -88,6 +91,11 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
<p><strong class="text-blue-400">${key}:</strong> ${value}</p>
`).join('')}
`;
// Show widget section and set widget code
widgetSection.classList.remove('hidden');
const widgetIframe = `<iframe src="https://status.my-mc.link/widget/${edition}/${host}/${port}" width="280" height="145" frameborder="0" scrolling="no"></iframe>`;
widgetCode.textContent = widgetIframe;
} else {
statusContent.innerHTML = `
<p><strong class="text-blue-400">Status:</strong> <span class="text-red-400">Offline</span></p>
@ -114,6 +122,19 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
}
});
// Assuming the copy functionality is in js/app.js, add this to handle the banner alert
document.getElementById('copyWidgetCode').addEventListener('click', function () {
const widgetCode = document.getElementById('widgetCode').textContent;
navigator.clipboard.writeText(widgetCode).then(() => {
const alert = document.getElementById('copyAlert');
alert.classList.remove('hidden');
setTimeout(() => {
alert.classList.add('hidden');
}, 3000);
}).catch(err => {
console.error('Failed to copy: ', err);
});
});
// Handle URL-based checks
const path = window.location.pathname.split('/');
if (path[1] && path[2] && path[3]) {