Misc. improvements, require incorrect repeats

main
Elnu 2 years ago
parent c92f3e82ac
commit ed98005f9f

@ -137,9 +137,10 @@ addEventListener("keyup", event => {
}); });
const check = () => { const check = () => {
if (input.value == word) { if (input.value == word) {
clearTimeout(timeout); clearTimeout(incorrectTimeout);
clearTimeout(timerTimeout);
wordDisplay.style.color = "green"; wordDisplay.style.color = "green";
wordDisplay.innerHTML += " ✅"; wordDisplay.innerHTML = `${word}`;
setTimeout(() => { setTimeout(() => {
wordDisplay.style.color = ""; wordDisplay.style.color = "";
reset(); reset();
@ -172,17 +173,22 @@ typeTimePerKanaInput.addEventListener("change", (e) => {
typeTimePerKana = typeTimePerKanaInput.value; typeTimePerKana = typeTimePerKanaInput.value;
}); });
const timerFPS = 60; const timerFPS = 60;
let incorrectTimeout = null;
let timerTimeout = null; let timerTimeout = null;
let timeout = null;
let word = null; let word = null;
let wrong = false;
const reset = () => { const reset = () => {
input.value = ""; input.value = "";
hint.innerHTML = ""; hint.innerHTML = "";
timer.value = 1; timer.value = 1;
word = words[Math.round(Math.random() * words.length)]; if (!wrong) {
timeout = wordDisplay.innerHTML = word; word = words[Math.round(Math.random() * words.length)];
}
wordDisplay.innerHTML = word;
const typeTime = typeTimePerKana * word.length; const typeTime = typeTimePerKana * word.length;
setTimeout(() => { incorrectTimeout = setTimeout(() => {
wrong = true;
wordDisplay.innerHTML = `${word}`;
for (let i = 0; i < word.length; i++) { for (let i = 0; i < word.length; i++) {
const letter = word[i]; const letter = word[i];
let key = null; let key = null;
@ -195,19 +201,19 @@ const reset = () => {
} }
} }
} }
let t = `<h3>${letter.toUpperCase()}`; let t = `<h3>${letter.toUpperCase()}<kbd`;
if (index > 0) { if (index > 0) {
t += "<kbd>"; t += ' style="background: ';
if (index == 1) { if (index == 1) {
t += "&larr;"; t += "yellow";
} else if (index == 2) { } else if (index == 2) {
t += "&rarr;"; t += "cyan";
} else if (index == 3) { } else if (index == 3) {
t += "&uarr;"; t += "magenta";
} }
t += "</kbd> + "; t += '"';
} }
t += `<kbd>${key}</kbd></h3>`; t += `>${key}</kbd></h3>`;
hint.innerHTML += t; hint.innerHTML += t;
} }
}, typeTime * 1000); }, typeTime * 1000);
@ -215,5 +221,6 @@ const reset = () => {
timerTimeout = setInterval(() => { timerTimeout = setInterval(() => {
timer.value -= (1 / timerFPS) / typeTime; timer.value -= (1 / timerFPS) / typeTime;
}, 1000 / timerFPS); }, 1000 / timerFPS);
wrong = false;
}; };
reset(); reset();