From d27c7dbb50828ee919c03efa40d21d2613cdfa68 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 6 Aug 2022 13:53:58 -0700 Subject: [PATCH] Add SRS --- nicolator.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nicolator.js b/nicolator.js index add50c8..6176704 100644 --- a/nicolator.js +++ b/nicolator.js @@ -187,16 +187,29 @@ let timerTimeout = null; let word = null; let repeats = 0; let failed = false; +let problemWords = []; +let problemTimes = []; const reset = () => { + failed = false; input.value = ""; hint.innerHTML = ""; timer.value = 1; if (repeats == 0) { - word = words[Math.round(Math.random() * words.length)]; + if (problemTimes.length > 0 && new Date() - problemTimes[0] > 60000) { + word = problemWords[0]; + problemWords.shift(); + problemTimes.shift(); + } else { + word = words[Math.round(Math.random() * words.length)]; + } } wordDisplay.innerHTML = word; const typeTime = typeTimePerKana * word.length; incorrectTimeout = setTimeout(() => { + if (!problemWords.includes(word)) { + problemWords.push(word); + problemTimes.push(new Date()); + } repeats += repeats == 0 ? 3 : 1; failed = true; wordDisplay.innerHTML = `${word} ❌`;