mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 15:08:45 +08:00
Merge pull request #809 from Jonny-exe/patch-2
Added an personal average pace maker
This commit is contained in:
commit
af996d3e84
7 changed files with 68 additions and 4 deletions
|
@ -41,7 +41,7 @@ Montydrei for the name suggestion
|
|||
|
||||
Everyone who provided valuable feedback on the original reddit post for the prototype of this website
|
||||
|
||||
Contributors that have helped with implementing various features, adding themes and more.
|
||||
Contributors that have helped with implementing various features, adding themes and more
|
||||
|
||||
# support
|
||||
|
||||
|
|
|
@ -317,7 +317,7 @@ function getAccountDataAndInit() {
|
|||
} else {
|
||||
accountIconLoading(false);
|
||||
}
|
||||
if (config.paceCaret === "pb") {
|
||||
if (config.paceCaret === "pb" || config.paceCaret === "average") {
|
||||
if (!testActive) {
|
||||
initPaceCaret(true);
|
||||
}
|
||||
|
@ -2433,4 +2433,3 @@ $(".pageLogin #forgotPasswordButton").click((e) => {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1001,6 +1001,13 @@ let commandsPaceCaret = {
|
|||
setPaceCaret("pb");
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "setPaceCaretAverage",
|
||||
display: "average",
|
||||
exec: () => {
|
||||
setPaceCaret("average");
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "setPaceCaretCustom",
|
||||
display: "custom...",
|
||||
|
|
38
src/js/db.js
38
src/js/db.js
|
@ -162,6 +162,44 @@ export async function db_getUserHighestWpm(
|
|||
return retval;
|
||||
}
|
||||
|
||||
export async function db_getUserAverageWpm10(
|
||||
mode,
|
||||
punctuation,
|
||||
language,
|
||||
difficulty
|
||||
) {
|
||||
function cont() {
|
||||
let wpmSum = 0;
|
||||
let count = 0;
|
||||
// You have to use every so you can break out of the loop
|
||||
dbSnapshot.results.every((result) => {
|
||||
if (
|
||||
result.mode == mode &&
|
||||
result.punctuation == punctuation &&
|
||||
result.language == language &&
|
||||
result.difficulty == difficulty
|
||||
) {
|
||||
wpmSum += result.wpm;
|
||||
count++;
|
||||
if (count < 10) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return Math.round(wpmSum / count);
|
||||
}
|
||||
|
||||
let retval = 0;
|
||||
|
||||
if (dbSnapshot == null) return retval;
|
||||
var dbSnapshotValid = await db_getUserResults();
|
||||
if (dbSnapshotValid === false) {
|
||||
return retval;
|
||||
}
|
||||
retval = cont();
|
||||
return retval;
|
||||
}
|
||||
|
||||
export async function db_getLocalPB(
|
||||
mode,
|
||||
mode2,
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
db_getUserResults,
|
||||
db_getUserHighestWpm,
|
||||
db_getLocalPB,
|
||||
db_getUserAverageWpm10,
|
||||
db_saveLocalPB,
|
||||
db_getLocalTagPB,
|
||||
db_saveLocalTagPB,
|
||||
|
|
|
@ -3591,7 +3591,11 @@ function updateTestModesNotice() {
|
|||
if (config.paceCaret !== "off") {
|
||||
$(".pageTest #testModesNotice").append(
|
||||
`<div class="text-button" commands="commandsPaceCaret"><i class="fas fa-tachometer-alt"></i>${
|
||||
config.paceCaret === "pb" ? "pb" : config.paceCaretCustomSpeed + " wpm"
|
||||
config.paceCaret === "average"
|
||||
? "average"
|
||||
: config.paceCaret === "pb"
|
||||
? "pb"
|
||||
: config.paceCaretCustomSpeed + " wpm"
|
||||
} pace</div>`
|
||||
);
|
||||
}
|
||||
|
@ -3931,6 +3935,13 @@ async function initPaceCaret() {
|
|||
config.language,
|
||||
config.difficulty
|
||||
);
|
||||
} else if (config.paceCaret === "average") {
|
||||
wpm = await db_getUserAverageWpm10(
|
||||
config.mode,
|
||||
config.punctuation,
|
||||
config.language,
|
||||
config.difficulty
|
||||
);
|
||||
} else if (config.paceCaret === "custom") {
|
||||
wpm = config.paceCaretCustomSpeed;
|
||||
}
|
||||
|
|
|
@ -2211,6 +2211,14 @@
|
|||
>
|
||||
off
|
||||
</div>
|
||||
<div
|
||||
class="button"
|
||||
paceCaret="average"
|
||||
tabindex="0"
|
||||
onclick="this.blur();"
|
||||
>
|
||||
average
|
||||
</div>
|
||||
<div
|
||||
class="button"
|
||||
paceCaret="pb"
|
||||
|
|
Loading…
Reference in a new issue