@@ -503,8 +503,14 @@ <h1>CPS Tester</h1>
503503 lastRc = 0 ,
504504 lastSec = 0 ;
505505
506- const zone = document . getElementById ( "clickZone" ) ;
507- const $ = ( id ) => document . getElementById ( id ) ;
506+ const zone = document . querySelector ( "#clickZone" ) ;
507+
508+ const $ = ( selector ) => {
509+ const all = document . querySelectorAll ( selector ) ;
510+ if ( all . length > 1 )
511+ throw new Error ( `$ expects a unique match, but "${ selector } " matched ${ all . length } elements` ) ;
512+ return all [ 0 ] ; // undefined when nothing matched
513+ } ;
508514
509515 function ripple ( x , y , side ) {
510516 const rect = zone . getBoundingClientRect ( ) ;
@@ -531,11 +537,11 @@ <h1>CPS Tester</h1>
531537 else rc ++ ;
532538 ripple ( x , y , side ) ;
533539 flash ( side ) ;
534- $ ( "leftClicks" ) . textContent = lc ;
535- $ ( "rightClicks" ) . textContent = rc ;
540+ $ ( "# leftClicks" ) . textContent = lc ;
541+ $ ( "# rightClicks" ) . textContent = rc ;
536542 const total = lc + rc ;
537- $ ( "totalClicks" ) . textContent = total ;
538- $ ( "zoneTotal" ) . textContent = total ;
543+ $ ( "# totalClicks" ) . textContent = total ;
544+ $ ( "# zoneTotal" ) . textContent = total ;
539545 }
540546
541547 zone . addEventListener ( "mousedown" , ( e ) => {
@@ -548,9 +554,9 @@ <h1>CPS Tester</h1>
548554
549555 function startTest ( ) {
550556 started = true ;
551- dur = parseInt ( $ ( "durationSel" ) . value ) ;
557+ dur = parseInt ( $ ( "# durationSel" ) . value ) ;
552558 startTime = performance . now ( ) ;
553- $ ( "statusMsg" ) . textContent = "Keep clicking!" ;
559+ $ ( "# statusMsg" ) . textContent = "Keep clicking!" ;
554560 ticker = setInterval ( tick , 80 ) ;
555561 }
556562
@@ -559,16 +565,16 @@ <h1>CPS Tester</h1>
559565 const remaining = Math . max ( 0 , dur - elapsed ) ;
560566 const pct = ( remaining / dur ) * 100 ;
561567
562- $ ( "timerFill" ) . style . width = pct + "%" ;
563- $ ( "timerFill" ) . style . background =
568+ $ ( "# timerFill" ) . style . width = pct + "%" ;
569+ $ ( "# timerFill" ) . style . background =
564570 pct <= 15 ? "var(--danger)" : pct <= 30 ? "var(--warn)" : "linear-gradient(90deg, var(--left), var(--right))" ;
565571
566- $ ( "timeLeft" ) . textContent = remaining . toFixed ( 1 ) + "s" ;
572+ $ ( "# timeLeft" ) . textContent = remaining . toFixed ( 1 ) + "s" ;
567573
568574 if ( elapsed > 0 ) {
569- $ ( "leftCps" ) . textContent = ( lc / elapsed ) . toFixed ( 1 ) ;
570- $ ( "rightCps" ) . textContent = ( rc / elapsed ) . toFixed ( 1 ) ;
571- $ ( "combinedCps" ) . textContent = ( ( lc + rc ) / elapsed ) . toFixed ( 1 ) ;
575+ $ ( "# leftCps" ) . textContent = ( lc / elapsed ) . toFixed ( 1 ) ;
576+ $ ( "# rightCps" ) . textContent = ( rc / elapsed ) . toFixed ( 1 ) ;
577+ $ ( "# combinedCps" ) . textContent = ( ( lc + rc ) / elapsed ) . toFixed ( 1 ) ;
572578 }
573579
574580 // per-second max tracking
@@ -578,11 +584,11 @@ <h1>CPS Tester</h1>
578584 sr = rc - lastRc ;
579585 if ( sl > lMax ) {
580586 lMax = sl ;
581- $ ( "leftMax" ) . textContent = lMax ;
587+ $ ( "# leftMax" ) . textContent = lMax ;
582588 }
583589 if ( sr > rMax ) {
584590 rMax = sr ;
585- $ ( "rightMax" ) . textContent = rMax ;
591+ $ ( "# rightMax" ) . textContent = rMax ;
586592 }
587593 lastLc = lc ;
588594 lastRc = rc ;
@@ -595,12 +601,12 @@ <h1>CPS Tester</h1>
595601 function endTest ( ) {
596602 clearInterval ( ticker ) ;
597603 finished = true ;
598- $ ( "timerFill" ) . style . width = "0%" ;
599- $ ( "timeLeft" ) . textContent = "0.0s" ;
600- $ ( "leftCps" ) . textContent = ( lc / dur ) . toFixed ( 1 ) ;
601- $ ( "rightCps" ) . textContent = ( rc / dur ) . toFixed ( 1 ) ;
602- $ ( "combinedCps" ) . textContent = ( ( lc + rc ) / dur ) . toFixed ( 1 ) ;
603- $ ( "statusMsg" ) . textContent = "Done! Click Reset to try again." ;
604+ $ ( "# timerFill" ) . style . width = "0%" ;
605+ $ ( "# timeLeft" ) . textContent = "0.0s" ;
606+ $ ( "# leftCps" ) . textContent = ( lc / dur ) . toFixed ( 1 ) ;
607+ $ ( "# rightCps" ) . textContent = ( rc / dur ) . toFixed ( 1 ) ;
608+ $ ( "# combinedCps" ) . textContent = ( ( lc + rc ) / dur ) . toFixed ( 1 ) ;
609+ $ ( "# statusMsg" ) . textContent = "Done! Click Reset to try again." ;
604610 }
605611
606612 function resetTest ( ) {
@@ -616,12 +622,14 @@ <h1>CPS Tester</h1>
616622 lastRc = 0 ;
617623 lastSec = 0 ;
618624
619- [ "leftClicks" , "rightClicks" , "totalClicks" , "zoneTotal" ] . forEach ( ( id ) => ( $ ( id ) . textContent = "0" ) ) ;
620- [ "leftCps" , "rightCps" , "leftMax" , "rightMax" , "combinedCps" ] . forEach ( ( id ) => ( $ ( id ) . textContent = "0.0" ) ) ;
621- $ ( "timeLeft" ) . textContent = "—" ;
622- $ ( "timerFill" ) . style . width = "100%" ;
623- $ ( "timerFill" ) . style . background = "linear-gradient(90deg, var(--left), var(--right))" ;
624- $ ( "statusMsg" ) . textContent = "Click the area above to start — left or right button" ;
625+ [ "#leftClicks" , "#rightClicks" , "#totalClicks" , "#zoneTotal" ] . forEach ( ( sel ) => ( $ ( sel ) . textContent = "0" ) ) ;
626+ [ "#leftCps" , "#rightCps" , "#leftMax" , "#rightMax" , "#combinedCps" ] . forEach (
627+ ( sel ) => ( $ ( sel ) . textContent = "0.0" )
628+ ) ;
629+ $ ( "#timeLeft" ) . textContent = "—" ;
630+ $ ( "#timerFill" ) . style . width = "100%" ;
631+ $ ( "#timerFill" ) . style . background = "linear-gradient(90deg, var(--left), var(--right))" ;
632+ $ ( "#statusMsg" ) . textContent = "Click the area above to start — left or right button" ;
625633 }
626634 </ script >
627635 </ body >
0 commit comments