-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions.js
48 lines (42 loc) · 1.6 KB
/
instructions.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
45
46
47
48
const instructions = document.querySelector("#instructions");
const currentDate = new Date().getTime();
const lastOpenedDate = localStorage.getItem(window.location.pathname);
// open instructions and set local storage if new
if (!lastOpenedDate) {
instructions.style.display = "block";
localStorage.setItem(window.location.pathname, currentDate);
}
// open instructions and set local storage if over a day old
if (currentDate - Number(lastOpenedDate) > 24 * 60 * 60 * 1000) {
instructions.style.display = "block";
localStorage.setItem(window.location.pathname, currentDate);
}
const instructionsOpenButton = document.createElement("div");
instructionsOpenButton.classList.add("open-instructions");
instructionsOpenButton.onclick = () => {
const isLoggerVisible = instructions.style.display === "block";
if (isLoggerVisible) {
// if logger up, close it
instructions.classList.add("logger-leave");
setTimeout(() => {
instructions.classList.remove("logger-leave");
instructions.style.display = "none";
}, 500);
} else {
// else change it to be visible
instructions.style.display = "block";
}
};
const scoreElement = document.querySelector("#score-wrapper");
scoreElement.appendChild(instructionsOpenButton);
// close button
const closeInstructions = document.createElement("div");
closeInstructions.classList.add("close-logger");
closeInstructions.onclick = () => {
instructions.classList.add("logger-leave");
setTimeout(() => {
instructions.classList.remove("logger-leave");
instructions.style.display = "none";
}, 500);
};
instructions.appendChild(closeInstructions);