// Check for php server availability async function checkPhpServer(username, password) { try { const response = await fetch('/app/server.check.php'); if (!response.ok) throw new Error('No PHP server'); const text = await response.text(); if (text.trim() !== 'PHP_OK') throw new Error('PHP check failed'); return true; } catch (error) { alert(`Sorry there is no PHP server running right now, here are your credentials btw:\nUsername: ${username}\nPassword: ${password}`); location.reload(); return false; } } // Clear all inputs in the form when submitted const form = document.querySelector("form"); form.addEventListener('submit', async (event) => { event.preventDefault(); const username = form.elements['username'].value; const password = form.elements['password'].value; const phpIsRunning = await checkPhpServer(username, password); if (!phpIsRunning) return; form.submit(); }); document.addEventListener("DOMContentLoaded", () => { const usernameInput = document.getElementById("username"); const passwordInput = document.getElementById("password"); const loginButton = document.querySelector(".login-btn"); const togglePassword = document.getElementById("togglePassword"); const yearSpan = document.getElementById("current-year"); const select = document.getElementById("language-select"); const measureSpan = document.getElementById("language-measure"); if (yearSpan) { yearSpan.textContent = new Date().getFullYear(); } function validateInputs() { const username = usernameInput.value.trim(); const password = passwordInput.value; loginButton.disabled = !(username !== "" && password.length > 8); // Show toggle button only if password is not empty if (password.length > 0) { togglePassword.style.display = "block"; } else { togglePassword.style.display = "none"; passwordInput.type = "password"; togglePassword.textContent = "Show"; } } function updateSelectWidth() { // Set the span's text to selected option const selectedText = select.options[select.selectedIndex].text; measureSpan.textContent = selectedText; // Get computed width and add padding for dropdown arrow const width = measureSpan.offsetWidth + 25; select.style.width = width + "px"; } updateSelectWidth(); select.addEventListener("change", updateSelectWidth); usernameInput.addEventListener("input", validateInputs); passwordInput.addEventListener("input", validateInputs); validateInputs(); togglePassword.addEventListener("click", () => { const isPassword = passwordInput.type === "password"; passwordInput.type = isPassword ? "text" : "password"; togglePassword.textContent = isPassword ? "Hide" : "Show"; }); });