Allow SRV Lookups
This commit is contained in:
@@ -12,8 +12,30 @@ function launchConfetti() {
|
||||
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 connection = document.getElementById('connection').value.trim();
|
||||
let host, port;
|
||||
|
||||
// Check if connection includes a port
|
||||
if (connection.includes(':')) {
|
||||
[host, port] = connection.split(':');
|
||||
} else {
|
||||
host = connection;
|
||||
port = '25565'; // Default Minecraft port
|
||||
}
|
||||
|
||||
// Validate hostname (allow subdomains and IPs)
|
||||
const hostnameRegex = /^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}|(?:\d{1,3}\.){3}\d{1,3})$/;
|
||||
if (!hostnameRegex.test(host)) {
|
||||
alert('Please enter a valid hostname (e.g., raven.my-mc.link or 192.168.1.1)');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate port if provided
|
||||
if (port && (isNaN(port) || port < 1 || port > 65535)) {
|
||||
alert('Please enter a valid port number (1-65535)');
|
||||
return;
|
||||
}
|
||||
|
||||
const loadingSpinner = document.getElementById('loadingSpinner');
|
||||
const statusResult = document.getElementById('statusResult');
|
||||
const statusContent = document.getElementById('statusContent');
|
||||
@@ -21,11 +43,6 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
|
||||
const widgetCode = document.getElementById('widgetCode');
|
||||
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;
|
||||
@@ -75,9 +92,15 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
|
||||
`).join('')}
|
||||
`;
|
||||
|
||||
// Show widget section and set widget code
|
||||
// Determine port for widget: use SRV-resolved port if available, else user-provided or default
|
||||
let widgetPort = port;
|
||||
if (result.srvPort) {
|
||||
widgetPort = result.srvPort;
|
||||
}
|
||||
|
||||
// Show widget section and set widget code with static my-mc.link hostname
|
||||
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>`;
|
||||
const widgetIframe = `<iframe src="https://my-mc.link/widget/${edition}/my-mc.link/${widgetPort}" width="280" height="145" frameborder="0" scrolling="no"></iframe>`;
|
||||
widgetCode.textContent = widgetIframe;
|
||||
} else {
|
||||
statusContent.innerHTML = `
|
||||
@@ -105,7 +128,7 @@ document.getElementById('serverForm').addEventListener('submit', async (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Assuming the copy functionality is in js/app.js, add this to handle the banner alert
|
||||
// Handle copy widget code
|
||||
document.getElementById('copyWidgetCode').addEventListener('click', function () {
|
||||
const widgetCode = document.getElementById('widgetCode').textContent;
|
||||
navigator.clipboard.writeText(widgetCode).then(() => {
|
||||
@@ -118,6 +141,7 @@ document.getElementById('copyWidgetCode').addEventListener('click', function ()
|
||||
console.error('Failed to copy: ', err);
|
||||
});
|
||||
});
|
||||
|
||||
// Handle URL-based checks
|
||||
const path = window.location.pathname.split('/');
|
||||
if (path[1] && path[2] && path[3]) {
|
||||
|
Reference in New Issue
Block a user