mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 05:17:51 +08:00
added a live-wpm module #495
This commit is contained in:
parent
a6ea92ce22
commit
fd5ccb2f1d
5 changed files with 81 additions and 71 deletions
|
@ -113,6 +113,7 @@ const refactoredSrc = [
|
|||
"./src/js/test/practise-missed.js",
|
||||
"./src/js/test/test-ui.js",
|
||||
"./src/js/test/keymap.js",
|
||||
"./src/js/test/live-wpm.js",
|
||||
];
|
||||
|
||||
//legacy files
|
||||
|
|
|
@ -41,3 +41,4 @@ import * as AccountIcon from "./account-icon";
|
|||
import * as PractiseMissed from "./practise-missed";
|
||||
import * as TestUI from "./test-ui";
|
||||
import * as Keymap from "./keymap";
|
||||
import * as LiveWpm from "./live-wpm";
|
||||
|
|
|
@ -1260,7 +1260,7 @@ function showResult(difficultyFailed = false) {
|
|||
testActive = false;
|
||||
Focus.set(false);
|
||||
Caret.hide();
|
||||
hideLiveWpm();
|
||||
LiveWpm.hide();
|
||||
hideLiveAcc();
|
||||
hideTimer();
|
||||
Keymap.hide();
|
||||
|
@ -2252,7 +2252,7 @@ function startTest() {
|
|||
restartTimer();
|
||||
showTimer();
|
||||
$("#liveWpm").text("0");
|
||||
showLiveWpm();
|
||||
LiveWpm.show();
|
||||
showLiveAcc();
|
||||
updateTimer();
|
||||
clearTimeout(timer);
|
||||
|
@ -2281,7 +2281,7 @@ function startTest() {
|
|||
updateTimer();
|
||||
}
|
||||
let wpmAndRaw = liveWpmAndRaw();
|
||||
updateLiveWpm(wpmAndRaw.wpm, wpmAndRaw.raw);
|
||||
LiveWpm.update(wpmAndRaw.wpm, wpmAndRaw.raw);
|
||||
TestStats.pushToWpmHistory(wpmAndRaw.wpm);
|
||||
TestStats.pushToRawHistory(wpmAndRaw.raw);
|
||||
Monkey.updateFastOpacity(wpmAndRaw.wpm);
|
||||
|
@ -2462,7 +2462,7 @@ function restartTest(withSameWordset = false, nosave = false, event) {
|
|||
Focus.set(false);
|
||||
Caret.hide();
|
||||
testActive = false;
|
||||
hideLiveWpm();
|
||||
LiveWpm.hide();
|
||||
hideLiveAcc();
|
||||
hideTimer();
|
||||
bailout = false;
|
||||
|
@ -2808,23 +2808,6 @@ function liveWpmAndRaw() {
|
|||
};
|
||||
}
|
||||
|
||||
function updateLiveWpm(wpm, raw) {
|
||||
if (!testActive || !Config.showLiveWpm) {
|
||||
hideLiveWpm();
|
||||
} else {
|
||||
showLiveWpm();
|
||||
}
|
||||
let number = wpm;
|
||||
if (Config.blindMode) {
|
||||
number = raw;
|
||||
}
|
||||
if (Config.alwaysShowCPM) {
|
||||
number = Math.round(number * 5);
|
||||
}
|
||||
document.querySelector("#miniTimerAndLiveWpm .wpm").innerHTML = number;
|
||||
document.querySelector("#liveWpm").innerHTML = number;
|
||||
}
|
||||
|
||||
function updateLiveAcc(acc) {
|
||||
if (!testActive || !Config.showLiveAcc) {
|
||||
hideLiveAcc();
|
||||
|
@ -2839,56 +2822,6 @@ function updateLiveAcc(acc) {
|
|||
document.querySelector("#liveAcc").innerHTML = number + "%";
|
||||
}
|
||||
|
||||
function showLiveWpm() {
|
||||
if (!Config.showLiveWpm) return;
|
||||
if (!testActive) return;
|
||||
if (Config.timerStyle === "mini") {
|
||||
// $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity);
|
||||
if (!$("#miniTimerAndLiveWpm .wpm").hasClass("hidden")) return;
|
||||
$("#miniTimerAndLiveWpm .wpm")
|
||||
.removeClass("hidden")
|
||||
.css("opacity", 0)
|
||||
.animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125
|
||||
);
|
||||
} else {
|
||||
// $("#liveWpm").css("opacity", Config.timerOpacity);
|
||||
if (!$("#liveWpm").hasClass("hidden")) return;
|
||||
$("#liveWpm").removeClass("hidden").css("opacity", 0).animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function hideLiveWpm() {
|
||||
// $("#liveWpm").css("opacity", 0);
|
||||
// $("#miniTimerAndLiveWpm .wpm").css("opacity", 0);
|
||||
$("#liveWpm").animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125,
|
||||
() => {
|
||||
$("#liveWpm").addClass("hidden");
|
||||
}
|
||||
);
|
||||
$("#miniTimerAndLiveWpm .wpm").animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125,
|
||||
() => {
|
||||
$("#miniTimerAndLiveWpm .wpm").addClass("hidden");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function showLiveAcc() {
|
||||
if (!Config.showLiveAcc) return;
|
||||
if (!testActive) return;
|
||||
|
|
65
src/js/test/live-wpm.js
Normal file
65
src/js/test/live-wpm.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
import Config from "./config";
|
||||
|
||||
export function update(wpm, raw) {
|
||||
// if (!testActive || !Config.showLiveWpm) {
|
||||
// hideLiveWpm();
|
||||
// } else {
|
||||
// showLiveWpm();
|
||||
// }
|
||||
let number = wpm;
|
||||
if (Config.blindMode) {
|
||||
number = raw;
|
||||
}
|
||||
if (Config.alwaysShowCPM) {
|
||||
number = Math.round(number * 5);
|
||||
}
|
||||
document.querySelector("#miniTimerAndLiveWpm .wpm").innerHTML = number;
|
||||
document.querySelector("#liveWpm").innerHTML = number;
|
||||
}
|
||||
|
||||
export function show() {
|
||||
if (!Config.showLiveWpm) return;
|
||||
if (Config.timerStyle === "mini") {
|
||||
// $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity);
|
||||
if (!$("#miniTimerAndLiveWpm .wpm").hasClass("hidden")) return;
|
||||
$("#miniTimerAndLiveWpm .wpm")
|
||||
.removeClass("hidden")
|
||||
.css("opacity", 0)
|
||||
.animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125
|
||||
);
|
||||
} else {
|
||||
// $("#liveWpm").css("opacity", Config.timerOpacity);
|
||||
if (!$("#liveWpm").hasClass("hidden")) return;
|
||||
$("#liveWpm").removeClass("hidden").css("opacity", 0).animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function hide() {
|
||||
$("#liveWpm").animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125,
|
||||
() => {
|
||||
$("#liveWpm").addClass("hidden");
|
||||
}
|
||||
);
|
||||
$("#miniTimerAndLiveWpm .wpm").animate(
|
||||
{
|
||||
opacity: Config.timerOpacity,
|
||||
},
|
||||
125,
|
||||
() => {
|
||||
$("#miniTimerAndLiveWpm .wpm").addClass("hidden");
|
||||
}
|
||||
);
|
||||
}
|
|
@ -586,11 +586,21 @@ function setShowLiveWpm(live, nosave) {
|
|||
live = false;
|
||||
}
|
||||
ConfigSet.showLiveWpm(live);
|
||||
if (live) {
|
||||
LiveWpm.show();
|
||||
} else {
|
||||
LiveWpm.hide();
|
||||
}
|
||||
if (!nosave) saveConfigToCookie();
|
||||
}
|
||||
|
||||
function toggleShowLiveWpm() {
|
||||
ConfigSet.showLiveWpm(!Config.showLiveWpm);
|
||||
if (Config.showLiveWpm) {
|
||||
LiveWpm.show();
|
||||
} else {
|
||||
LiveWpm.hide();
|
||||
}
|
||||
saveConfigToCookie();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue