// public/js/join.js import { getParam, fetchJson } from "./utils.js"; const username = getParam("username"); document.getElementById("joinForm").addEventListener("submit", async e => { e.preventDefault(); const gameId = document.getElementById("gameId").value; if (!username) { alert("Kein Username gefunden!"); return; } try { await fetchJson("/api/join-game", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ gameId, username }) }); window.location.href = `/game.html?gameId=${gameId}&username=${encodeURIComponent(username)}`; } catch (err) { alert(`Fehler: ${err.message}`); } });