From d173258fd892414b12b2be50daecdc32fceff5c9 Mon Sep 17 00:00:00 2001 From: Corey Bergeron Date: Thu, 29 Oct 2020 23:32:22 -0400 Subject: [PATCH 1/2] added always show cpm --- public/index.html | 15 ++++++++++++ public/js/commandline.js | 27 ++++++++++++++++++++ public/js/script.js | 53 ++++++++++++++++++++++++++++++---------- public/js/settings.js | 4 +++ public/js/userconfig.js | 17 ++++++++++++- 5 files changed, 102 insertions(+), 14 deletions(-) diff --git a/public/index.html b/public/index.html index 84fb1cc9b..e31fab4d7 100644 --- a/public/index.html +++ b/public/index.html @@ -2234,6 +2234,21 @@ +
+

always show cpm

+
+ Always shows characters per minute calculation instead of the + default words per minute calculation. +
+
+
+ off +
+
+ on +
+
+

start graphs at zero

diff --git a/public/js/commandline.js b/public/js/commandline.js index 99ad85cd7..8d7ea78ff 100644 --- a/public/js/commandline.js +++ b/public/js/commandline.js @@ -274,6 +274,13 @@ let commands = { toggleAlwaysShowDecimalPlaces(); }, }, + { + id: "toggleAlwaysShowCPM", + display: "Toggle always show CPM", + exec: () => { + toggleAlwaysShowCPM(); + }, + }, { id: "toggleSwapEscAndTab", display: "Toggle swap esc and tab", @@ -954,6 +961,26 @@ let commandsHighlightMode = { ], }; +let commandsAlwaysShowCPM = { + title: "Toggle always show cpm...", + list: [ + { + id: "setAlwaysShowCPMTrue", + display: true, + exec: () => { + setAlwaysShowCPM(true); + }, + }, + { + id: "setAlwaysShowCPMFalse", + display: false, + exec: () => { + setHighlightMode(false); + }, + }, + ], +}; + let commandsTimerStyle = { title: "Change timer/progress style...", list: [ diff --git a/public/js/script.js b/public/js/script.js index ef0cd7a72..ff4d3c458 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1650,6 +1650,7 @@ function calculateStats() { // } let chars = countChars(); // let testNow = Date.now(); + let wpm = roundTo2( ((chars.correctWordChars + chars.correctSpaces) * (60 / testSeconds)) / 5 ); @@ -1741,8 +1742,22 @@ function showResult(difficultyFailed = false) { $("#result #resultWordsHistory").addClass("hidden"); if (config.alwaysShowDecimalPlaces) { - $("#result .stats .wpm .bottom").text(roundTo2(stats.wpm)); - $("#result .stats .raw .bottom").text(roundTo2(stats.wpmRaw)); + if (config.alwaysShowCPM == false) { + $("#result .stats .wpm .bottom").text(roundTo2(stats.wpm)); + $("#result .stats .raw .bottom").text(roundTo2(stats.wpmRaw)); + $("#result .stats .wpm .bottom").attr( + "aria-label", + roundTo2(stats.wpm * 5) + " cpm" + ); + } else { + $("#result .stats .wpm .bottom").text(roundTo2(stats.wpm * 5)); + $("#result .stats .raw .bottom").text(roundTo2(stats.wpmRaw * 5)); + $("#result .stats .wpm .bottom").attr( + "aria-label", + roundTo2(stats.wpm) + " wpm" + ); + } + $("#result .stats .acc .bottom").text(roundTo2(stats.acc) + "%"); // $("#result .stats .time .bottom").text(roundTo2(testtime) + "s"); let time = roundTo2(testtime) + "s"; @@ -1750,10 +1765,7 @@ function showResult(difficultyFailed = false) { time = secondsToString(roundTo2(testtime)); } $("#result .stats .time .bottom .text").text(time); - $("#result .stats .wpm .bottom").attr( - "aria-label", - roundTo2(stats.wpm * 5) + " cpm" - ); + $("#result .stats .raw .bottom").removeAttr("aria-label"); $("#result .stats .acc .bottom").removeAttr("aria-label"); $("#result .stats .time .bottom").attr( @@ -1761,13 +1773,25 @@ function showResult(difficultyFailed = false) { `${afkseconds}s afk ${afkSecondsPercent}%` ); } else { - $("#result .stats .wpm .bottom").text(Math.round(stats.wpm)); - $("#result .stats .wpm .bottom").attr( - "aria-label", - stats.wpm + ` (${roundTo2(stats.wpm * 5)} cpm)` - ); - $("#result .stats .raw .bottom").text(Math.round(stats.wpmRaw)); - $("#result .stats .raw .bottom").attr("aria-label", stats.wpmRaw); + //not showing decimal places + if (config.alwaysShowCPM == false) { + $("#result .stats .wpm .bottom").attr( + "aria-label", + stats.wpm + ` (${roundTo2(stats.wpm * 5)} cpm)` + ); + $("#result .stats .wpm .bottom").text(Math.round(stats.wpm)); + $("#result .stats .raw .bottom").text(Math.round(stats.wpmRaw)); + $("#result .stats .raw .bottom").attr("aria-label", stats.wpmRaw); + } else { + $("#result .stats .wpm .bottom").attr( + "aria-label", + stats.wpm + ` (${roundTo2(stats.wpm)} wpm)` + ); + $("#result .stats .wpm .bottom").text(Math.round(stats.wpm * 5)); + $("#result .stats .raw .bottom").text(Math.round(stats.wpmRaw * 5)); + $("#result .stats .raw .bottom").attr("aria-label", stats.wpmRaw * 5); + } + $("#result .stats .acc .bottom").text(Math.floor(stats.acc) + "%"); $("#result .stats .acc .bottom").attr("aria-label", stats.acc + "%"); let time = Math.round(testtime) + "s"; @@ -3118,6 +3142,9 @@ function updateLiveWpm(wpm, raw) { if (config.blindMode) { number = raw; } + if (config.alwaysShowCPM) { + number = Math.round(number * 5); + } document.querySelector("#miniTimerAndLiveWpm .wpm").innerHTML = number; document.querySelector("#liveWpm").innerHTML = number; // $("#liveWpm").html(wpm); diff --git a/public/js/settings.js b/public/js/settings.js index 8da6a25df..eba9b2036 100644 --- a/public/js/settings.js +++ b/public/js/settings.js @@ -253,6 +253,10 @@ settingsGroups.alwaysShowDecimalPlaces = new SettingsGroup( "alwaysShowDecimalPlaces", setAlwaysShowDecimalPlaces ); +settingsGroups.alwaysShowCPM = new SettingsGroup( + "alwaysShowCPM", + setAlwaysShowCPM +); fillSettingsPage(); diff --git a/public/js/userconfig.js b/public/js/userconfig.js index 27ef06a6e..9e7ab8833 100644 --- a/public/js/userconfig.js +++ b/public/js/userconfig.js @@ -68,6 +68,7 @@ let defaultConfig = { minWpm: "off", minWpmCustomSpeed: 100, highlightMode: "letter", + alwaysShowCPM: false, }; let cookieConfig = null; @@ -212,8 +213,9 @@ function applyConfig(configObj) { setMinWpmCustomSpeed(configObj.minWpmCustomSpeed, true); setNumbers(configObj.numbers, true); setPunctuation(configObj.punctuation, true); - changeMode(configObj.mode, true); setHighlightMode(configObj.highlightMode, true); + setAlwaysShowCPM(config.alwaysShowCPM, true); + changeMode(configObj.mode, true); config.startGraphsAtZero = configObj.startGraphsAtZero; // if ( // configObj.resultFilters !== null && @@ -428,6 +430,19 @@ function setAlwaysShowDecimalPlaces(val, nosave) { if (!nosave) saveConfigToCookie(); } +function toggleAlwaysShowCPM() { + config.alwaysShowCPM = !config.alwaysShowCPM; + saveConfigToCookie(); +} + +function setAlwaysShowCPM(val, nosave) { + if (val == undefined) { + val = false; + } + config.alwaysShowCPM = val; + if (!nosave) saveConfigToCookie(); +} + //show out of focus warning function toggleShowOutOfFocusWarning() { config.showOutOfFocusWarning = !config.showOutOfFocusWarning; From 88253bd8f94fe94a0c49392fac7ce21aa415edba Mon Sep 17 00:00:00 2001 From: corey Date: Fri, 30 Oct 2020 11:02:11 -0400 Subject: [PATCH 2/2] result page now shows cpm when enabled --- public/js/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/js/script.js b/public/js/script.js index 93f40f5af..b3083398a 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1740,6 +1740,7 @@ function showResult(difficultyFailed = false) { if (config.alwaysShowDecimalPlaces) { if (config.alwaysShowCPM == false) { + $("#result .stats .wpm .top").text("wpm"); $("#result .stats .wpm .bottom").text(roundTo2(stats.wpm)); $("#result .stats .raw .bottom").text(roundTo2(stats.wpmRaw)); $("#result .stats .wpm .bottom").attr( @@ -1747,6 +1748,7 @@ function showResult(difficultyFailed = false) { roundTo2(stats.wpm * 5) + " cpm" ); } else { + $("#result .stats .wpm .top").text("cpm"); $("#result .stats .wpm .bottom").text(roundTo2(stats.wpm * 5)); $("#result .stats .raw .bottom").text(roundTo2(stats.wpmRaw * 5)); $("#result .stats .wpm .bottom").attr( @@ -1772,6 +1774,7 @@ function showResult(difficultyFailed = false) { } else { //not showing decimal places if (config.alwaysShowCPM == false) { + $("#result .stats .wpm .top").text("wpm"); $("#result .stats .wpm .bottom").attr( "aria-label", stats.wpm + ` (${roundTo2(stats.wpm * 5)} cpm)` @@ -1780,6 +1783,7 @@ function showResult(difficultyFailed = false) { $("#result .stats .raw .bottom").text(Math.round(stats.wpmRaw)); $("#result .stats .raw .bottom").attr("aria-label", stats.wpmRaw); } else { + $("#result .stats .wpm .top").text("cpm"); $("#result .stats .wpm .bottom").attr( "aria-label", stats.wpm + ` (${roundTo2(stats.wpm)} wpm)`