diff --git a/src/js/script.js b/src/js/script.js index 0fac733b3..487407b78 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -1554,6 +1554,8 @@ function showResult(difficultyFailed = false) { correctedHistory.push(currentCorrected); } + TestStats.recordKeypressSpacing(); + resultCalculating = true; resultVisible = true; TestStats.setEnd(performance.now()); @@ -4600,14 +4602,7 @@ $(document).keydown(function (event) { if (!(event.key == " ") && !event.originalEvent.isTrusted) return; if (!resultVisible) { - let now = performance.now(); - let diff = Math.abs(TestStats.keypressTimings.spacing.current - now); - if (TestStats.keypressTimings.spacing.current !== -1) { - TestStats.pushKeypressSpacing(diff); - // keypressStats.spacing.array.push(diff); - } - TestStats.setKeypressSpacing(now); - // keypressStats.spacing.current = now; + TestStats.recordKeypressSpacing(); } Monkey.type(); diff --git a/src/js/test/test-stats.js b/src/js/test/test-stats.js index f0a68d707..a67ee7159 100644 --- a/src/js/test/test-stats.js +++ b/src/js/test/test-stats.js @@ -176,6 +176,15 @@ export function pushKeypressSpacing(val) { keypressTimings.spacing.array.push(val); } +export function recordKeypressSpacing() { + let now = performance.now(); + let diff = Math.abs(keypressTimings.spacing.current - now); + if (keypressTimings.spacing.current !== -1) { + pushKeypressSpacing(diff); + } + setKeypressSpacing(now); +} + export function setKeypressSpacing(val) { keypressTimings.spacing.current = val; } @@ -183,11 +192,11 @@ export function setKeypressSpacing(val) { export function resetKeypressTimings() { keypressTimings = { spacing: { - current: -1, + current: performance.now(), array: [], }, duration: { - current: -1, + current: performance.now(), array: [], }, };