@@ -29,23 +29,52 @@ window.addEventListener('DOMContentLoaded', function(){
2929
3030/* ── SCREENS ── */
3131var LS_SCREEN = 'quizhub_last_screen' ;
32+ var LS_LAST_ATT = 'quizhub_last_screen_att' ;
3233var PERSIST_SCREENS = [ 'screen-hub' , 'screen-ctfl-home' , 'screen-ctai-version' , 'screen-ctai-home' , 'screen-ctai-home-v2' , 'screen-ctai-blitz-version' , 'screen-genai-home' , 'screen-profile' ] ;
34+ var REVIEW_SCREENS = [ 'screen-results' , 'screen-blitz-review' , 'screen-glossary-review' , 'screen-blitz-results' , 'screen-glossary-results' ] ;
3335function showScreen ( id ) {
3436 var ss = document . querySelectorAll ( '.screen' ) ;
3537 for ( var s = 0 ; s < ss . length ; s ++ ) ss [ s ] . classList . remove ( 'active' ) ;
3638 document . getElementById ( id ) . classList . add ( 'active' ) ;
3739 window . scrollTo ( 0 , 0 ) ;
3840 try {
39- if ( PERSIST_SCREENS . indexOf ( id ) >= 0 ) localStorage . setItem ( LS_SCREEN , id ) ;
40- else localStorage . removeItem ( LS_SCREEN ) ;
41+ if ( PERSIST_SCREENS . indexOf ( id ) >= 0 ) {
42+ localStorage . setItem ( LS_SCREEN , id ) ;
43+ localStorage . removeItem ( LS_LAST_ATT ) ;
44+ } else if ( REVIEW_SCREENS . indexOf ( id ) >= 0 && lastAttemptId ) {
45+ localStorage . setItem ( LS_SCREEN , id ) ;
46+ localStorage . setItem ( LS_LAST_ATT , lastAttemptId ) ;
47+ } else {
48+ localStorage . removeItem ( LS_SCREEN ) ;
49+ localStorage . removeItem ( LS_LAST_ATT ) ;
50+ }
4151 } catch ( e ) { }
4252}
53+ var LIVE_SCREENS = [ 'screen-exam' , 'screen-blitz' , 'screen-glossary' ] ;
54+ window . addEventListener ( 'beforeunload' , function ( e ) {
55+ for ( var i = 0 ; i < LIVE_SCREENS . length ; i ++ ) {
56+ var el = document . getElementById ( LIVE_SCREENS [ i ] ) ;
57+ if ( el && el . classList . contains ( 'active' ) ) {
58+ e . preventDefault ( ) ;
59+ e . returnValue = '' ;
60+ return '' ;
61+ }
62+ }
63+ } ) ;
4364window . addEventListener ( 'DOMContentLoaded' , function ( ) {
4465 try {
4566 var saved = localStorage . getItem ( LS_SCREEN ) ;
46- if ( saved && PERSIST_SCREENS . indexOf ( saved ) >= 0 && document . getElementById ( saved ) ) {
67+ if ( ! saved || ! document . getElementById ( saved ) ) return ;
68+ if ( PERSIST_SCREENS . indexOf ( saved ) >= 0 ) {
4769 if ( saved === 'screen-profile' ) openProfile ( ) ;
4870 else showScreen ( saved ) ;
71+ } else if ( REVIEW_SCREENS . indexOf ( saved ) >= 0 ) {
72+ var attId = localStorage . getItem ( LS_LAST_ATT ) ;
73+ if ( ! attId ) return ;
74+ lastAttemptId = attId ;
75+ if ( saved === 'screen-results' ) reopenAttempt ( attId ) ;
76+ else if ( saved === 'screen-blitz-review' || saved === 'screen-blitz-results' ) reopenBlitzAttempt ( attId ) ;
77+ else if ( saved === 'screen-glossary-review' || saved === 'screen-glossary-results' ) reopenGlossaryAttempt ( attId ) ;
4978 }
5079 } catch ( e ) { }
5180} ) ;
@@ -550,7 +579,6 @@ function showResults(){
550579 document . getElementById ( 'stat-unanswered' ) . textContent = unanswered ;
551580 document . getElementById ( 'review-filter' ) . value = 'all' ;
552581 applyFilter ( ) ;
553- showScreen ( 'screen-results' ) ;
554582 if ( ! _skipSaveAttempt ) {
555583 saveAttempt ( {
556584 type : 'exam' ,
@@ -564,6 +592,7 @@ function showResults(){
564592 } ) ;
565593 }
566594 _skipSaveAttempt = false ;
595+ showScreen ( 'screen-results' ) ;
567596}
568597
569598/* ── REVIEW ── */
@@ -1121,13 +1150,13 @@ function glossShowResults() {
11211150 gIconEl . setAttribute ( 'data-topic' , gTopic ) ;
11221151 }
11231152 document . getElementById ( 'gloss-results-title-text' ) . textContent = gFam + ' Glossary Practice' ;
1124- showScreen ( 'screen-glossary-results' ) ;
11251153 saveAttempt ( {
11261154 type : 'glossary' ,
11271155 pool : glossCurrentPool ,
11281156 correct : glossTotalCorrect , total : glossTotalAttempts , pct : pct ,
11291157 details : glossDetails . slice ( )
11301158 } ) ;
1159+ showScreen ( 'screen-glossary-results' ) ;
11311160}
11321161
11331162
@@ -1226,14 +1255,14 @@ function blitzShowResults(){
12261255 bIconEl . setAttribute ( 'data-topic' , bTopic ) ;
12271256 }
12281257 document . getElementById ( 'blitz-results-title-text' ) . textContent = bFam + ' Lightning Round' ;
1229- showScreen ( 'screen-blitz-results' ) ;
12301258 saveAttempt ( {
12311259 type : 'blitz' ,
12321260 pool : blitzCurrentPool ,
12331261 ctaiVersion : ( blitzCurrentPool === 'ctai' ? blitzCurrentCtaiVersion : undefined ) ,
12341262 correct : blitzCorrect , total : 10 , pct : pct , passed : pct >= 65 ,
12351263 details : blitzDetails . slice ( )
12361264 } ) ;
1265+ showScreen ( 'screen-blitz-results' ) ;
12371266}
12381267
12391268/* ── PROFILE & PERSISTENCE ── */
@@ -1374,6 +1403,7 @@ function reopenAttempt(id){
13741403 questions = ( att . mode === 'ctai' ? ctaiPool : att . mode === 'ctfl' ? CTFL_PACKS : PACKS ) [ String ( att . pack ) ] ;
13751404 if ( ! questions ) return ;
13761405 userAnswers = att . userAnswers ;
1406+ lastAttemptId = id ;
13771407 _skipSaveAttempt = true ;
13781408 showResults ( ) ;
13791409}
@@ -1398,6 +1428,7 @@ function poolLabel(pool){
13981428function reopenBlitzAttempt ( id ) {
13991429 var att = findAttempt ( id ) ;
14001430 if ( ! att || att . type !== 'blitz' || ! att . details ) return ;
1431+ lastAttemptId = id ;
14011432
14021433 var rvFam = poolLabel ( att . pool ) ;
14031434 if ( att . pool === 'ctai' ) rvFam += ' v' + ( att . ctaiVersion === 2 ? '2.0' : '1.0' ) ;
@@ -1432,6 +1463,7 @@ var _glossReviewMaxRound = 5;
14321463function reopenGlossaryAttempt ( id ) {
14331464 var att = findAttempt ( id ) ;
14341465 if ( ! att || att . type !== 'glossary' || ! att . details ) return ;
1466+ lastAttemptId = id ;
14351467
14361468 document . getElementById ( 'gloss-review-title' ) . textContent =
14371469 poolLabel ( att . pool ) + ' Glossary Practice — review' ;
0 commit comments