From 740e68847925d47b2c35fdfe161d5c50c5f691dd Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 24 Oct 2020 02:58:55 +0100 Subject: [PATCH] added memory funbox --- public/funbox/list.json | 5 +++++ public/js/script.js | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/public/funbox/list.json b/public/funbox/list.json index 664f68051..14e756647 100644 --- a/public/funbox/list.json +++ b/public/funbox/list.json @@ -78,5 +78,10 @@ "name": "read_ahead", "type": "style", "info": "Current and the next word is invisible!" + }, + { + "name": "memory", + "type": "script", + "info": "Test your memory. Remember the words and type them blind." } ] diff --git a/public/js/script.js b/public/js/script.js index cb38dcbac..42f4ab6bd 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -43,6 +43,9 @@ let paceCaret = null; let missedWords = []; let verifyUserWhenLoggedIn = null; let modeBeforePractise = null; +let memoryFunboxTimer = null; +let memoryFunboxInterval = null; + let themeColors = { bg: "#323437", @@ -331,6 +334,10 @@ function activateFunbox(funbox, mode) { changeKeymapLayout("qwerty"); settingsGroups.keymapLayout.updateButton(); restartTest(); + } else if (funbox === "memory") { + changeMode('words'); + setShowAllLines(true, true); + restartTest(false, true); } activeFunBox = funbox; } @@ -828,6 +835,20 @@ function showWords() { updateHighlightedKeymapKey(); } + if (activeFunBox === "memory") { + memoryFunboxInterval = clearInterval(memoryFunboxInterval); + memoryFunboxTimer = Math.round(Math.pow(wordsList.length, 1.2)); + memoryFunboxInterval = setInterval(fn => { + memoryFunboxTimer-= 1; + showNotification(memoryFunboxTimer); + if (memoryFunboxTimer < 0) { + memoryFunboxInterval = clearInterval(memoryFunboxInterval); + memoryFunboxTimer = null; + $('#wordsWrapper').addClass('hidden'); + } + }, 1000); + } + updateActiveElement(); updateCaretPosition(); } @@ -2888,6 +2909,12 @@ function changePage(page) { } function changeMode(mode, nosave) { + + if (mode !== "words" && activeFunBox === "memory") { + showNotification("Memory funbox can only be used with words mode."); + return; + } + config.mode = mode; $("#top .config .mode .text-button").removeClass("active"); $("#top .config .mode .text-button[mode='" + mode + "']").addClass("active");