-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
113 lines (90 loc) · 2.53 KB
/
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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
let typeBox = document.getElementById("typeBox");
let finishBox = document.getElementById("finishBox");
let input = document.getElementById("input");
const newPbModalElement = document.getElementById('newPbModal');
const newPbModal = new bootstrap.Modal('#newPbModal', {});
// const signInModal = doc
let onFinishScreen = false;
let timerStartTime = 0;
let personalBest = 0;
window.onload = () => {
openTypeBox();
input.focus();
input.addEventListener("input", handleChangeInInput);
window.addEventListener("keypress", handleGlobalKeypress);
window.addEventListener("click", handleGlobalClick);
}
function handleGlobalClick() {
input.focus();
}
function openTypeBox() {
typeBox.classList.remove("d-none");
finishBox.classList.add("d-none");
onFinishScreen = false;
}
function openFinishBox() {
typeBox.classList.add("d-none");
finishBox.classList.remove("d-none");
onFinishScreen = true;
}
function getPBinSeconds() {
return localStorage.getItem("personalBest") ? localStorage.getItem("personalBest") / 1000 : null;
}
function getPBinMillseconds() {
return localStorage.getItem("personalBest");
}
function setPBinMillseconds(ms) {
localStorage.setItem("personalBest", ms);
}
function updateTimeWithNewTime(time) {
document.getElementById("seconds").innerText = time / 1000;
if (document.getElementById("pb").innerText == "") {
if (getPBinMillseconds() == null) {
document.getElementById("pb").innerText = time / 1000;
setPBinMillseconds(time);
} else {
document.getElementById("pb").innerText = getPBinSeconds();
}
}
console.log(getPBinMillseconds());
console.log(time);
if (getPBinMillseconds() > time) {
setPBinMillseconds(time);
openNewPbModal();
document.getElementById("pb").innerText = getPBinSeconds();
}
}
function handleChangeInInput(e) {
console.log(input.value.length);
if (input.value.toLowerCase().trim() == "abcdefghijklmnopqrstuvwxyz") {
openFinishBox();
updateTimeWithNewTime(Date.now() - timerStartTime)
}
if (input.value.length == 1) {
timerStartTime = Date.now();
}
}
function handleGlobalKeypress(e) {
if (e.key == "Enter") {
resetTypeBox();
if (onFinishScreen) {
openTypeBox();
input.focus();
}
}
}
function resetTypeBox() {
input.value = "";
}
function openNewPbModal() {
console.log("me");
newPbModal.show();
// newPbModal.addEventListener('shown.bs.modal', () => {
// myInput.focus()
// })
}
function openSignInModal() {
}
document.addEventListener("load", () => {
openSignInModal();
});