-
Notifications
You must be signed in to change notification settings - Fork 0
/
d2lobby.js
44 lines (36 loc) · 1.46 KB
/
d2lobby.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
window.onload = function () {
const prefixIn = document.getElementById("prefixIn");
const numberIn = document.getElementById("numberIn");
const copyBtn = document.getElementById("copyBtn");
const copyBtnText = document.getElementById("copyBtnText");
const alertBox = document.getElementById("alertBox");
const alertBoxText = document.getElementById("alertBoxText");
const getGameName = () => `${prefixIn.value}${numberIn.value}`;
const renderCopyBtn = function() {
copyBtnText.innerText = getGameName();
};
const prefixFocused = function() {
prefixIn.value = "";
numberIn.value = "1";
renderCopyBtn();
};
const copyBtnPressed = function() {
navigator.clipboard.writeText(getGameName());
// animate alert box showing text was copied to clipboard
alertBoxText.innerText = getGameName();
alertBox.classList.add("show");
setTimeout(() => alertBox.classList.remove("show"), 3000);
// handle leading zeroes
const nextNumber = numberIn.valueAsNumber + 1
numberIn.value = `${nextNumber}`.padStart(numberIn.value.trim().length, "0")
renderCopyBtn();
};
const alertBoxClicked = function() {
alertBox.classList.remove("show")
}
prefixIn.onfocus = prefixFocused;
prefixIn.oninput = renderCopyBtn;
numberIn.oninput = renderCopyBtn;
copyBtn.onclick = copyBtnPressed;
alertBox.onclick = alertBoxClicked;
};