-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
24 lines (20 loc) · 792 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function $_(selector) {
return document.querySelector(selector);
}
const alertButton = $_(".alert-button"),
promptButton = $_(".prompt-button"),
confirmButton = $_(".confirm-button");
[alertButton, promptButton, confirmButton].forEach(btn => {
btn.addEventListener("click", async () => {
const splittedClass = btn.classList[0]?.split("-");
const functionName = splittedClass[0] + "s"; // e.g. alerts ("alert" + "s")
const input = $_("." + splittedClass[0] + "-input");
functionName !== "alerts" ? await alerts({
modalMessage: await window[functionName]({
modalMessage: input.value
})
}) : await window[functionName]({
modalMessage: input.value
});
});
});