export function alert(message) { return new Promise(next => { if (document.getElementById("popup-container")) throw new Error("Popup already exist !") document.querySelector("body").insertAdjacentHTML("afterend", `
`); document.getElementById("popup-ok").addEventListener("click", () => { document.getElementById("popup-container").remove(); next(); }); }); } export function confirm(message) { return new Promise(next => { if (document.getElementById("popup-container")) throw new Error("Popup already exist !") document.querySelector("body").insertAdjacentHTML("afterend", ``); document.getElementById("popup-ok").addEventListener("click", () => { document.getElementById("popup-container").remove(); next(true); }); document.getElementById("popup-cancel").addEventListener("click", () => { document.getElementById("popup-container").remove(); next(false); }); }); } export function prompt(message, inputArgs) { return new Promise(next => { if (document.getElementById("popup-container")) throw new Error("Popup already exist !") document.querySelector("body").insertAdjacentHTML("afterend", ``); document.getElementById("popup-ok").addEventListener("click", () => { let val = document.querySelector("#popup input").value document.getElementById("popup-container").remove(); next(val); }); document.getElementById("popup-cancel").addEventListener("click", () => { document.getElementById("popup-container").remove(); next(null); }); }); } export function createUserPopup(username) { return new Promise(next => { if (document.getElementById("popup-container")) throw new Error("Popup already exist !") document.querySelector("body").insertAdjacentHTML("afterend", ``); let ok = document.getElementById("popup-ok"); document.getElementById("lastName").addEventListener("keyup", ev => { if (ev.key === "Enter") ok.click() }); ok.addEventListener("click", () => { let firstName = document.getElementById("firstName").value; let lastName = document.getElementById("lastName").value; document.getElementById("popup-container").remove(); next([firstName, lastName]); }); document.getElementById("popup-cancel").addEventListener("click", () => { document.getElementById("popup-container").remove(); next(null, null); }); }); }