function problem_id() { const url_params = new URLSearchParams(window.location.search); return parseInt(url_params.get("problem_id")); } async function submit() { const language = document.getElementById("submission-language").value; const details = document.getElementById("submission-details").value; const code = document.getElementById("submission-code").value; const submission = { problem_id: problem_id(), // TODO validate language and problem id in server language: language, details: details, code: code, }; const response = await fetch("/submission", { method: "post", headers: { "Content-Type": "application/json" }, credentials: "include", body: JSON.stringify(submission) }); if (response.ok) { const result = await response.json(); window.location.href = "index.html"; } else { document.getElementById("error-message").innerHTML = "error submitting solution, try again"; document.getElementById("error").hidden = false; } } async function init() { const response = await fetch(`/problem/${problem_id()}`); const problem = await response.json(); const problem_div = document.getElementById("submission-problem"); const title = document.createElement("h2"); title.innerHTML = `Problem: ${problem.title}`; problem_div.appendChild(title); const description = document.createElement("p"); description.innerHTML = problem.description; problem_div.appendChild(description); }