This commit is contained in:
Miodec 2021-03-17 17:41:02 +00:00
commit e3a2dc09b8
8 changed files with 14204 additions and 108 deletions

File diff suppressed because it is too large Load diff

View file

@ -115,6 +115,7 @@ const refactoredSrc = [
"./src/js/test/keymap.js",
"./src/js/test/live-wpm.js",
"./src/js/test/caps-warning.js",
"./src/js/test/live-acc.js"
];
//legacy files

10518
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -129,7 +129,7 @@ let commands = {
id: "toggleShowLiveAcc",
display: "Toggle live accuracy display",
exec: () => {
toggleShowLiveAcc();
LiveAcc.show();
},
},
{

View file

@ -44,3 +44,4 @@ import * as TestUI from "./test-ui";
import * as Keymap from "./keymap";
import * as LiveWpm from "./live-wpm";
import * as CapsWarning from "./caps-warning";
import * as LiveAcc from './live-acc';

View file

@ -1262,7 +1262,7 @@ function showResult(difficultyFailed = false) {
Caret.hide();
LiveWpm.hide();
hideCrown();
hideLiveAcc();
LiveAcc.hide();
hideTimer();
Keymap.hide();
let stats = calculateStats();
@ -2252,7 +2252,7 @@ function startTest() {
showTimer();
$("#liveWpm").text("0");
LiveWpm.show();
showLiveAcc();
LiveAcc.show();
updateTimer();
clearTimeout(timer);
@ -2462,7 +2462,7 @@ function restartTest(withSameWordset = false, nosave = false, event) {
Caret.hide();
testActive = false;
LiveWpm.hide();
hideLiveAcc();
LiveAcc.hide();
hideTimer();
bailout = false;
paceCaret = null;
@ -2807,70 +2807,6 @@ function liveWpmAndRaw() {
};
}
function updateLiveAcc(acc) {
if (!testActive || !Config.showLiveAcc) {
hideLiveAcc();
} else {
showLiveAcc();
}
let number = Math.floor(acc);
if (Config.blindMode) {
number = 100;
}
document.querySelector("#miniTimerAndLiveWpm .acc").innerHTML = number + "%";
document.querySelector("#liveAcc").innerHTML = number + "%";
}
function showLiveAcc() {
if (!Config.showLiveAcc) return;
if (!testActive) return;
if (Config.timerStyle === "mini") {
// $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity);
if (!$("#miniTimerAndLiveWpm .acc").hasClass("hidden")) return;
$("#miniTimerAndLiveWpm .acc")
.removeClass("hidden")
.css("opacity", 0)
.animate(
{
opacity: Config.timerOpacity,
},
125
);
} else {
// $("#liveWpm").css("opacity", Config.timerOpacity);
if (!$("#liveAcc").hasClass("hidden")) return;
$("#liveAcc").removeClass("hidden").css("opacity", 0).animate(
{
opacity: Config.timerOpacity,
},
125
);
}
}
function hideLiveAcc() {
// $("#liveWpm").css("opacity", 0);
// $("#miniTimerAndLiveWpm .wpm").css("opacity", 0);
$("#liveAcc").animate(
{
opacity: Config.timerOpacity,
},
125,
() => {
$("#liveAcc").addClass("hidden");
}
);
$("#miniTimerAndLiveWpm .acc").animate(
{
opacity: Config.timerOpacity,
},
125,
() => {
$("#miniTimerAndLiveWpm .acc").addClass("hidden");
}
);
}
function toggleResultWordsDisplay() {
if (TestUI.resultVisible) {
if ($("#resultWordsHistory").stop(true, true).hasClass("hidden")) {
@ -4015,7 +3951,7 @@ $(document).keydown(function (event) {
}
let acc = Misc.roundTo2(TestStats.calculateAccuracy());
updateLiveAcc(acc);
LiveAcc.update(acc);
});
function handleTab(event) {

61
src/js/test/live-acc.js Normal file
View file

@ -0,0 +1,61 @@
import Config from './config';
export function update(acc) {
let number = Math.floor(acc);
if (Config.blindMode) {
number = 100;
}
document.querySelector("#miniTimerAndLiveWpm .acc").innerHTML = number + "%";
document.querySelector("#liveAcc").innerHTML = number + "%";
}
export function show() {
if (!Config.showLiveAcc) return;
// if (!testActive) return;
if (Config.timerStyle === "mini") {
// $("#miniTimerAndLiveWpm .wpm").css("opacity", Config.timerOpacity);
if (!$("#miniTimerAndLiveWpm .acc").hasClass("hidden")) return;
$("#miniTimerAndLiveWpm .acc")
.removeClass("hidden")
.css("opacity", 0)
.animate(
{
opacity: Config.timerOpacity,
},
125
);
} else {
// $("#liveWpm").css("opacity", Config.timerOpacity);
if (!$("#liveAcc").hasClass("hidden")) return;
$("#liveAcc").removeClass("hidden").css("opacity", 0).animate(
{
opacity: Config.timerOpacity,
},
125
);
}
}
export function hide() {
// $("#liveWpm").css("opacity", 0);
// $("#miniTimerAndLiveWpm .wpm").css("opacity", 0);
$("#liveAcc").animate(
{
opacity: Config.timerOpacity,
},
125,
() => {
$("#liveAcc").addClass("hidden");
}
);
$("#miniTimerAndLiveWpm .acc").animate(
{
opacity: Config.timerOpacity,
},
125,
() => {
$("#miniTimerAndLiveWpm .acc").addClass("hidden");
}
);
}

View file

@ -609,11 +609,21 @@ function setShowLiveAcc(live, nosave) {
live = false;
}
ConfigSet.showLiveAcc(live);
if (live) {
LiveAcc.show();
} else {
LiveAcc.hide();
}
if (!nosave) saveConfigToCookie();
}
function toggleShowLiveAcc() {
function toggleLiveAcc() {
ConfigSet.showLiveAcc(!Config.showLiveAcc);
if (Config.showLiveAcc) {
LiveAcc.show();
} else {
LiveAcc.hide();
}
saveConfigToCookie();
}