Merge pull request #501 from corey-b/master

added always show cpm
This commit is contained in:
Jack 2020-10-30 16:03:21 +00:00 committed by GitHub
commit bea1cdead7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 13 deletions

View file

@ -2220,6 +2220,21 @@
</div>
</div>
</div>
<div class="section alwaysShowCPM">
<h1>always show cpm</h1>
<div class="text">
Always shows characters per minute calculation instead of the
default words per minute calculation.
</div>
<div class="buttons">
<div class="button off" tabindex="0" onclick="this.blur();">
off
</div>
<div class="button on" tabindex="0" onclick="this.blur();">
on
</div>
</div>
</div>
<div class="section startGraphsAtZero">
<h1>start graphs at zero</h1>
<div class="text">

View file

@ -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: [

View file

@ -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);

View file

@ -253,6 +253,10 @@ settingsGroups.alwaysShowDecimalPlaces = new SettingsGroup(
"alwaysShowDecimalPlaces",
setAlwaysShowDecimalPlaces
);
settingsGroups.alwaysShowCPM = new SettingsGroup(
"alwaysShowCPM",
setAlwaysShowCPM
);
fillSettingsPage();

View file

@ -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;