diff --git a/public/index.html b/public/index.html index 9fb7f1099..2a4040673 100644 --- a/public/index.html +++ b/public/index.html @@ -2220,6 +2220,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 1f1804d36..f1efd1288 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1647,6 +1647,7 @@ function calculateStats() { // } let chars = countChars(); // let testNow = Date.now(); + let wpm = roundTo2( ((chars.correctWordChars + chars.correctSpaces) * (60 / testSeconds)) / 5 ); @@ -1738,8 +1739,24 @@ 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 .top").text("wpm"); + $("#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 .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( + "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"; @@ -1747,10 +1764,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( @@ -1758,13 +1772,27 @@ 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 .top").text("wpm"); + $("#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 .top").text("cpm"); + $("#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"; @@ -3115,6 +3143,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 7751dd85f..dbf07fb8e 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; @@ -213,6 +214,7 @@ function applyConfig(configObj) { setNumbers(configObj.numbers, true); setPunctuation(configObj.punctuation, true); setHighlightMode(configObj.highlightMode, true); + setAlwaysShowCPM(config.alwaysShowCPM, true); changeMode(configObj.mode, true); config.startGraphsAtZero = configObj.startGraphsAtZero; // if ( @@ -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;