@@ -93,6 +93,11 @@ function capitalizeFirstLetter(str) {
9393 return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
9494}
9595
96+ function roundedToFixed ( float , digits ) {
97+ let rounded = Math . pow ( 10 , digits ) ;
98+ return ( Math . round ( float * rounded ) / rounded ) . toFixed ( digits ) ;
99+ }
100+
96101function initWords ( ) {
97102 testActive = false ;
98103 wordsList = [ ] ;
@@ -429,7 +434,13 @@ function calculateStats() {
429434 let testSeconds = ( testNow - testStart ) / 1000 ;
430435 let wpm = Math . round ( ( chars . correctWordChars * ( 60 / testSeconds ) ) / 5 ) ;
431436 let acc = Math . floor ( ( accuracyStats . correct / ( accuracyStats . correct + accuracyStats . incorrect ) ) * 100 ) ;
432- return { wpm : wpm , acc : acc , correctChars : chars . allCorrectChars , incorrectChars : chars . incorrectChars + chars . extraChars + chars . missedChars } ;
437+ return {
438+ wpm : wpm ,
439+ acc : acc ,
440+ correctChars : chars . allCorrectChars ,
441+ incorrectChars : chars . incorrectChars + chars . extraChars + chars . missedChars ,
442+ time : testSeconds
443+ } ;
433444}
434445
435446function hideCrown ( ) {
@@ -444,13 +455,18 @@ function showCrown() {
444455
445456function showResult ( ) {
446457 testEnd = Date . now ( ) ;
458+ testActive = false ;
459+ setFocus ( false ) ;
460+ hideCaret ( ) ;
461+ hideLiveWpm ( ) ;
447462 let stats = calculateStats ( ) ;
448463 if ( stats === undefined ) {
449464 stats = {
450465 wpm : 0 ,
451466 acc : 0 ,
452467 correctChars : 0 ,
453- incorrectChars : 0
468+ incorrectChars : 0 ,
469+ time : 0
454470 }
455471 }
456472 clearIntervals ( ) ;
@@ -460,8 +476,11 @@ function showResult() {
460476 let mode2 = "" ;
461477 if ( config . mode == "time" ) {
462478 mode2 = config . time ;
479+ $ ( "#result .stats .time" ) . addClass ( 'hidden' ) ;
463480 } else if ( config . mode == "words" ) {
464481 mode2 = config . words ;
482+ $ ( "#result .stats .time" ) . removeClass ( 'hidden' ) ;
483+ $ ( "#result .stats .time .bottom" ) . text ( roundedToFixed ( stats . time , 1 ) + 's' ) ;
465484 }
466485
467486 if ( afkDetected ) {
@@ -532,15 +551,11 @@ function showResult() {
532551 infoText += "<br>" + config . language . replace ( '_' , ' ' ) ;
533552 }
534553 if ( config . punctuation ) {
535- infoText += "<br>with punctuation"
554+ infoText += "<br>punctuation"
536555 }
537556
538557 $ ( "#result .stats .info .bottom" ) . html ( infoText ) ;
539- testActive = false ;
540- setFocus ( false ) ;
541- hideCaret ( ) ;
542- hideLiveWpm ( ) ;
543-
558+
544559 let labels = [ ] ;
545560 for ( let i = 1 ; i <= wpmHistory . length ; i ++ ) {
546561 labels . push ( i . toString ( ) ) ;
@@ -1096,8 +1111,8 @@ $(document).keydown((event) => {
10961111 //space
10971112 if ( event [ "keyCode" ] == 32 ) {
10981113 if ( ! testActive ) return ;
1099- event . preventDefault ( ) ;
11001114 if ( currentInput == "" ) return ;
1115+ event . preventDefault ( ) ;
11011116 let currentWord = wordsList [ currentWordIndex ] ;
11021117 if ( config . mode == "time" ) {
11031118 let currentTop = $ ( $ ( "#words .word" ) [ currentWordIndex ] ) . position ( ) . top ;
0 commit comments