mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-04-29 13:38:42 +08:00
added progress for words and custom tests
This commit is contained in:
parent
e4b468cc25
commit
0e1a9f39b8
2 changed files with 34 additions and 15 deletions
public
|
@ -449,8 +449,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="section timerBar">
|
||||
<h1>timer</h1>
|
||||
<div class="text">Displays a live timer for timed tests.</div>
|
||||
<h1>timer/progress</h1>
|
||||
<div class="text">Displays a live timer for timed tests and progress for words/custom tests.</div>
|
||||
<div class="buttons">
|
||||
<div class="button on" tabindex="0" onclick="this.blur();">show</div>
|
||||
<div class="button off" tabindex="0" onclick="this.blur();">hide</div>
|
||||
|
|
|
@ -438,20 +438,34 @@ function hideTimer() {
|
|||
|
||||
function restartTimer() {
|
||||
if(config.timerStyle === "bar"){
|
||||
$("#timer").stop(true, true).animate({
|
||||
"width": "100vw"
|
||||
},0);
|
||||
if(config.mode === "time"){
|
||||
$("#timer").stop(true, true).animate({
|
||||
"width": "100vw"
|
||||
},0);
|
||||
}else if(config.mode === "words" || config.mode === "custom"){
|
||||
$("#timer").stop(true, true).animate({
|
||||
"width": "0vw"
|
||||
},0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateTimer() {
|
||||
if(config.timerStyle === "bar"){
|
||||
let percent = 100 - (((time + 1) / config.time) * 100);
|
||||
$("#timer").stop(true, true).animate({
|
||||
"width": percent + "vw"
|
||||
},1000,"linear");
|
||||
}else if(config.timerStyle === "text"){
|
||||
$("#timerNumber").html(config.time - time);
|
||||
|
||||
if(config.mode === "time"){
|
||||
if(config.timerStyle === "bar"){
|
||||
let percent = 100 - (((time + 1) / config.time) * 100);
|
||||
$("#timer").stop(true, true).animate({
|
||||
"width": percent + "vw"
|
||||
},1000,"linear");
|
||||
}else if(config.timerStyle === "text"){
|
||||
$("#timerNumber").html(config.time - time);
|
||||
}
|
||||
}else if((config.mode === "words"|| config.mode === "custom") && config.timerStyle === "bar"){
|
||||
let percent = Math.floor(((currentWordIndex+1) / wordsList.length) * 100);
|
||||
$("#timer").stop(true, true).animate({
|
||||
"width": percent + "vw"
|
||||
},250);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1662,16 +1676,18 @@ $(document).keypress(function(event) {
|
|||
}
|
||||
testActive = true;
|
||||
testStart = Date.now();
|
||||
if (config.mode == "time") {
|
||||
// if (config.mode == "time") {
|
||||
restartTimer();
|
||||
showTimer();
|
||||
}
|
||||
// }
|
||||
updateActiveElement();
|
||||
updateTimer();
|
||||
clearIntervals();
|
||||
timers.push(setInterval(function() {
|
||||
time++;
|
||||
updateTimer();
|
||||
if (config.mode === "time") {
|
||||
updateTimer();
|
||||
}
|
||||
let wpm = liveWPM();
|
||||
updateLiveWpm(wpm);
|
||||
showLiveWpm();
|
||||
|
@ -1839,6 +1855,9 @@ $(document).keydown((event) => {
|
|||
updateActiveElement();
|
||||
updateCaretPosition();
|
||||
}
|
||||
if (config.mode === "words" || config.mode === "custom") {
|
||||
updateTimer();
|
||||
}
|
||||
if (config.mode == "time") {
|
||||
addWord();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue