From 3dc4689653ad2dddf895687b120091d8a2b20cd7 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 13 Jul 2020 00:44:03 +0100 Subject: [PATCH] fixed a bug that would not allow for tests to end --- public/js/script.js | 93 ++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/public/js/script.js b/public/js/script.js index 1df391f7b..ae0f9117d 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -596,10 +596,15 @@ function compareInput(wrdIndex, input, showError) { wordAtIndex.innerHTML = ret; + let lastindex = currentWordIndex; + if (wrdIndex !== null) { + lastindex = wrdIndex; + } + if ( (currentWord == input || (config.quickEnd && currentWord.length == input.length)) && - wrdIndex == wordsList.length - 1 + lastindex == wordsList.length - 1 ) { inputHistory.push(input); currentInput = ""; @@ -797,54 +802,56 @@ function updateCaretPosition() { currentLetterIndex = 0; } // let currentLetter = $("#words .word.active letter")[currentLetterIndex]; - let currentLetter = document - .querySelector("#words .active") - .querySelectorAll("letter")[currentLetterIndex]; + try { + let currentLetter = document + .querySelector("#words .active") + .querySelectorAll("letter")[currentLetterIndex]; - if ($(currentLetter).length == 0) return; - let currentLetterPosLeft = currentLetter.offsetLeft; - let currentLetterPosTop = currentLetter.offsetTop; - let letterHeight = $(currentLetter).height(); - let newTop = 0; - let newLeft = 0; + if ($(currentLetter).length == 0) return; + let currentLetterPosLeft = currentLetter.offsetLeft; + let currentLetterPosTop = currentLetter.offsetTop; + let letterHeight = $(currentLetter).height(); + let newTop = 0; + let newLeft = 0; - newTop = currentLetterPosTop - letterHeight / 4; - if (inputLen == 0) { - newLeft = currentLetterPosLeft - caret.width() / 2; - } else { - newLeft = - currentLetterPosLeft + $(currentLetter).width() - caret.width() / 2; - } + newTop = currentLetterPosTop - letterHeight / 4; + if (inputLen == 0) { + newLeft = currentLetterPosLeft - caret.width() / 2; + } else { + newLeft = + currentLetterPosLeft + $(currentLetter).width() - caret.width() / 2; + } - let duration = 0; + let duration = 0; - if (config.smoothCaret) { - duration = 100; - // if (Math.round(caret[0].offsetTop) != Math.round(newTop)) { - // caret.css("top", newTop); - // duration = 10; - // } - } + if (config.smoothCaret) { + duration = 100; + // if (Math.round(caret[0].offsetTop) != Math.round(newTop)) { + // caret.css("top", newTop); + // duration = 10; + // } + } - caret.stop(true, true).animate( - { - top: newTop, - left: newLeft, - }, - duration - ); + caret.stop(true, true).animate( + { + top: newTop, + left: newLeft, + }, + duration + ); - let browserHeight = window.innerHeight; - let middlePos = browserHeight / 2 - $("#caret").outerHeight() / 2; - let contentHeight = document.body.scrollHeight; + let browserHeight = window.innerHeight; + let middlePos = browserHeight / 2 - $("#caret").outerHeight() / 2; + let contentHeight = document.body.scrollHeight; - if (newTop >= middlePos && contentHeight > browserHeight) { - window.scrollTo({ - left: 0, - top: newTop - middlePos, - behavior: "smooth", - }); - } + if (newTop >= middlePos && contentHeight > browserHeight) { + window.scrollTo({ + left: 0, + top: newTop - middlePos, + behavior: "smooth", + }); + } + } catch (e) {} } function countChars() { @@ -2451,8 +2458,6 @@ $(document).keypress(function (event) { // console.time("offcheck1"); let newActiveTop = document.querySelector("#words .word.active").offsetTop; - console.timeEnd("offcheck1"); - console.time("offcheck2"); if (activeWordTopBeforeJump != newActiveTop) { activeWordJumped = true; }