From 1bf16c65b8281e5a88ccdd3bb34ed66ac30f15d8 Mon Sep 17 00:00:00 2001 From: Zak Date: Fri, 5 Jun 2020 14:00:07 +0100 Subject: [PATCH 1/2] Added workman layout --- public/js/layouts.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/public/js/layouts.js b/public/js/layouts.js index 608eddd0c..c41de53a4 100644 --- a/public/js/layouts.js +++ b/public/js/layouts.js @@ -20,5 +20,12 @@ const layouts = { "aA","rR","sS","tT","dD","hH","nN","eE","iI","oO","'\"", "zZ","xX","cC","vV","bB","kK","mM",",<",".>","/?", " " + ], + workman:[ + "`~","1!","2@","3#","4$","5%","6^","7&","8*","9(","0)","-_","=+", + "qQ","dD","rR","wW","bB","jJ","fF","uU","pP",";:","[{","]}","\\|", + "aA","sS","hH","tT","gG","yY","nN","eE","oO","iI","'\"", + "zZ","xX","mM","cC","vV","kK","lL",",<",".>","/?", + " " ] } \ No newline at end of file From b476614c1876a27c1b447bd729a88cc9a21475ae Mon Sep 17 00:00:00 2001 From: Zak Date: Sat, 6 Jun 2020 11:46:21 +0100 Subject: [PATCH 2/2] Added word highlight mode --- public/index.html | 9 +++++++++ public/js/commandline.js | 10 ++++++++++ public/js/script.js | 39 ++++++++++++++++++++++++++++++++++++--- public/js/settings.js | 13 +++++++++++++ public/js/userconfig.js | 25 ++++++++++++++++++++++++- 5 files changed, 92 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 3b1f4903b..a01714459 100644 --- a/public/index.html +++ b/public/index.html @@ -298,6 +298,15 @@
off
+
+

word highlight mode

+
When this option is enabled the caret will be hidden and words will be highlighted individually rather than per character. +
+
+
on
+
off
+
+

layout

diff --git a/public/js/commandline.js b/public/js/commandline.js index db9bfb6f0..574aa048c 100644 --- a/public/js/commandline.js +++ b/public/js/commandline.js @@ -71,6 +71,16 @@ let commands = { toggleQuickEnd(); } }, + { + id: "toggleHighlightMode", + display: "Toggle word highlight mode", + exec: () => { + hideCaret(); + highlightWord(currentWordIndex,currentInput,config.showError); + restartTest(); + toggleHighlightMode(); + } + }, { id: "toggleFlipTestColors", display: "Toggle flip test colors", diff --git a/public/js/script.js b/public/js/script.js index af52362f5..b9b4e2f21 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -297,10 +297,39 @@ function updateActiveElement() { activeWordTop = $("#words .word.active").position().top; } -function compareInput(wrdIndex,input,showError) { +function highlightWord(wrdIndex, input, showError){ $($('#words .word')[wrdIndex]).empty(); + let currentWord = wordsList[wrdIndex]; + let ret = ""; + for (let i = 0; i < currentWord.length; i++) { + ret += '' + currentWord[i] + ""; + } + $($('#words .word')[wrdIndex]).html(ret); + if ((currentWord == input || (config.quickEnd && currentWord.length == input.length)) && wrdIndex == wordsList.length - 1) { + inputHistory.push(input); + currentInput = ""; + if(!resultVisible) showResult(); + } +} + +function compareInput(wrdIndex,input,showError) { let ret = ""; let currentWord = wordsList[wrdIndex]; + if (config.highlightMode){ + for (let i = 0; i < input.length; i++) { + if (currentWord[i] != input[i]){ + if(config.difficulty == "master"){ + if(!resultVisible) showResult(true); + restartCount++; + } + if (showError) + highlightBadWord(wrdIndex, showError); + } + } + return; + } + $($('#words .word')[wrdIndex]).empty(); + for (let i = 0; i < input.length; i++) { if (currentWord[i] == input[i]) { ret += '' + currentWord[i] + ""; @@ -854,7 +883,8 @@ function restartTest() { }, 250); wpmOverTimeChart.options.annotation.annotations[0].value = "-20"; wpmOverTimeChart.update(); - + if (config.highlightMode) + highlightWord(currentWordIndex, currentInput, config.showError); // let oldHeight = $("#words").height(); // let newHeight = $("#words") @@ -1251,7 +1281,8 @@ $("#wordsInput").keypress((event) => { }); $("#wordsInput").on("focus", (event) => { - showCaret(); + if (!config.highlightMode) + showCaret(); }); $("#wordsInput").on("focusout", (event) => { @@ -1399,6 +1430,8 @@ $(document).keydown((event) => { if (currentInput == "") return; event.preventDefault(); let currentWord = wordsList[currentWordIndex]; + if (config.highlightMode) + highlightWord(currentWordIndex+1, currentInput, config.showError); if (config.mode == "time") { let currentTop = $($("#words .word")[currentWordIndex]).position().top; let nextTop = $($("#words .word")[currentWordIndex + 1]).position().top; diff --git a/public/js/settings.js b/public/js/settings.js index 9aeab1cd3..c7931e2d5 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -25,6 +25,7 @@ function updateSettingsPage(){ setSettingsButton('blindMode', config.blindMode); setSettingsButton('quickEnd', config.quickEnd); setSettingsButton('flipTestColors', config.flipTestColors); + setSettingsButton('highlightMode', config.highlightMode); setActiveThemeButton(); @@ -255,6 +256,18 @@ $(".pageSettings .section.quickEnd .buttons .button.off").click(e => { setSettingsButton('quickEnd', config.quickEnd); }) +$(".pageSettings .section.highlightMode .buttons .button.on").click(e => { + setHighlightMode(true); + showNotification('Quick end on', 1000); + setSettingsButton('highlightMode', config.highlightMode); +}) +$(".pageSettings .section.highlightMode .buttons .button.off").click(e => { + setHighlightMode(false); + showNotification('Quick end off', 1000); + setSettingsButton('highlightMode', config.highlightMode); +}) + + //flip test $(".pageSettings .section.flipTestColors .buttons .button.on").click(e => { setFlipTestColors(true); diff --git a/public/js/userconfig.js b/public/js/userconfig.js index b719fef9a..a7f0d7c3f 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -18,7 +18,8 @@ let config = { quickEnd: false, caretStyle: "default", flipTestColors: false, - layout:"default" + layout:"default", + highlightMode:false } //cookies @@ -52,6 +53,7 @@ function loadConfigFromCookie() { setDifficulty(newConfig.difficulty,true); setBlindMode(newConfig.blindMode,true); setQuickEnd(newConfig.quickEnd,true); + setHighlightMode(newConfig.highlightMode, true); setFlipTestColors(newConfig.flipTestColors,true); if(newConfig.resultFilters == null || newConfig.resultFilters == undefined){ newConfig.resultFilters = ["all"]; @@ -70,6 +72,10 @@ function loadConfigFromCookie() { config.layout = "default"; saveConfigToCookie(); } + if (config.highlightMode == undefined){ + config.highlightMode = false; + saveConfigToCookie(); + } } function showTestConfig() { @@ -126,6 +132,23 @@ function setQuickEnd(qe, nosave){ if(!nosave) saveConfigToCookie(); } +function toggleHighlightMode(){ + hm = !config.highlightMode; + if(hm == undefined){ + hm = false; + } + config.highlightMode = hm; + saveConfigToCookie(); +} + +function setHighlightMode(hm, nosave){ + if(hm == undefined){ + hm = false; + } + config.highlightMode = hm; + saveConfigToCookie(); +} + //flip colors function setFlipTestColors(flip,nosave){