document.addEventListener("DOMContentLoaded", async () => { let loginCode = "" let emails = await fetch("/api/email/list", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: localStorage.getItem("SECRET-token") }) }) if (emails.status !== 200) { window.location.href = "/signup"; } let address, username emails = await emails.json() emails.forEach(email => { if (email["isPrimary"]) { address = email["address"] username = email["username"] } }) document.getElementById("copyLoginCode").addEventListener("click", () => { navigator.clipboard.writeText(loginCode).then(() => { document.getElementById("copyLoginCode").innerText = "Copied!" setTimeout(() => { document.getElementById("copyLoginCode").innerText = "Copy login code" }, 2000) }) }) document.getElementById("closeLoginCode").addEventListener("click", () => { document.getElementById("loginCodeDisplay").style.display = "none"; }) document.getElementById("showLoginCode").addEventListener("click", () => { document.getElementById("loginCodeDisplay").style.display = "flex"; }) document.getElementById("resetLoginCode").addEventListener("click", async () => { await fetch("/api/email/resetLoginCode", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: localStorage.getItem("SECRET-token"), address: address, username: username }) }) }) document.getElementById("deleteAccount").addEventListener("click", async () => { await fetch("/api/email/delete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: localStorage.getItem("SECRET-token"), address: address, username: username }) }) localStorage.removeItem("SECRET-token") window.location.href = "/oauth"; }) })