diff --git a/frontend/src/ts/account/pb-tables.ts b/frontend/src/ts/account/pb-tables.ts index 85e16b137..b5c4c3b39 100644 --- a/frontend/src/ts/account/pb-tables.ts +++ b/frontend/src/ts/account/pb-tables.ts @@ -1,5 +1,6 @@ import Config from "../config"; import format from "date-fns/format"; +import * as Misc from "../utils/misc"; function clearTables(isProfile: boolean): void { const source = isProfile ? "Profile" : "Account"; @@ -127,6 +128,7 @@ function buildPbHtml( let dateText = ""; const multiplier = Config.alwaysShowCPM ? 5 : 1; const modeString = `${mode2} ${mode === "time" ? "seconds" : "words"}`; + const wpmCpm = Config.alwaysShowCPM ? "cpm" : "wpm"; try { pbData = pbs[mode][mode2].sort((a, b) => b.wpm - a.wpm)[0]; const date = new Date(pbData.timestamp); @@ -134,6 +136,46 @@ function buildPbHtml( dateText = format(date, "dd MMM yyyy"); } + let wpmString: number | string = pbData.wpm * multiplier; + if (Config.alwaysShowDecimalPlaces) { + wpmString = Misc.roundTo2(wpmString).toFixed(2); + } else { + wpmString = Math.round(wpmString); + } + wpmString += ` ${wpmCpm}`; + + let rawString: number | string = pbData.raw * multiplier; + if (Config.alwaysShowDecimalPlaces) { + rawString = Misc.roundTo2(rawString).toFixed(2); + } else { + rawString = Math.round(rawString); + } + rawString += ` raw`; + + let accString: number | string = pbData.acc; + if (accString === undefined) { + accString = "-"; + } else { + if (Config.alwaysShowDecimalPlaces) { + accString = Misc.roundTo2(accString).toFixed(2); + } else { + accString = Math.round(accString); + } + } + accString += ` acc`; + + let conString: number | string = pbData.consistency; + if (conString === undefined) { + conString = "-"; + } else { + if (Config.alwaysShowDecimalPlaces) { + conString = Misc.roundTo2(conString).toFixed(2); + } else { + conString = Math.round(conString); + } + } + conString += ` con`; + retval = `
${modeString}
${Math.round(pbData.wpm * multiplier)}
@@ -143,14 +185,10 @@ function buildPbHtml(
${modeString}
-
${Math.round(pbData.wpm * multiplier)} ${ - Config.alwaysShowCPM ? "cpm" : "wpm" - }
-
${Math.round(pbData.raw * multiplier)} raw
-
${pbData.acc === undefined ? "-" : Math.floor(pbData.acc)} acc
-
${ - pbData.consistency === undefined ? "-" : Math.floor(pbData.consistency) - } con
+
${wpmString}
+
${rawString}
+
${accString}
+
${conString}
${dateText}
`; } catch (e) {