-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
715 lines (633 loc) · 29 KB
/
Copy pathindex.html
File metadata and controls
715 lines (633 loc) · 29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>اختبار قرارات الحكام</title>
<style>
:root {
--primary-color: #0d6efd; /* Bootstrap Blue */
--secondary-color: #6c757d; /* Bootstrap Gray */
--success-color: #198754; /* Bootstrap Green */
--danger-color: #dc3545; /* Bootstrap Red */
--light-color: #f8f9fa; /* Bootstrap Light Gray */
--dark-color: #212529; /* Bootstrap Dark Gray */
--font-family: 'Tahoma', sans-serif;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
font-family: var(--font-family);
background-color: var(--light-color);
color: var(--dark-color);
}
body {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.container {
width: 95%;
max-width: 800px;
height: 95vh;
max-height: 650px; /* Slightly increased max height */
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
display: flex; /* Changed to flex for easier view switching */
flex-direction: column;
justify-content: space-around; /* Adjust spacing */
overflow: hidden;
}
/* --- Views --- */
.view {
display: none; /* Hide all views by default */
flex-direction: column;
align-items: center;
justify-content: center; /* Center content vertically */
height: 100%; /* Take full height of container */
width: 100%;
}
#main-view {
display: flex; /* Show main view initially */
gap: 25px; /* Space between buttons */
}
#test-view {
justify-content: space-between; /* Space out elements in test view */
}
#results-view {
justify-content: space-between;
}
/* --- Main Menu --- */
#main-view h1 {
color: var(--primary-color);
margin-bottom: 30px;
}
#main-view button {
width: 60%;
max-width: 250px;
padding: 15px 20px;
font-size: 1.2em;
}
#exit-btn {
background-color: var(--secondary-color);
}
#exit-btn:hover {
background-color: #5a6268;
}
/* --- Test View --- */
#test-view h2 { /* Test title/status */
color: var(--dark-color);
margin: 5px 0 10px 0;
font-size: 1.2em;
min-height: 1.5em; /* Reserve space */
}
#video-container {
position: relative;
width: 100%;
height: 55vh; /* Adjust video height */
max-height: 380px;
background-color: #000;
margin-bottom: 15px;
border-radius: 5px;
overflow: hidden; /* Clip video if needed */
}
#test-video {
display: block;
width: 100%;
height: 100%;
object-fit: contain;
}
#controls-container, #options-container, #feedback-container {
width: 100%;
min-height: 50px; /* Ensure containers have some height */
margin-bottom: 10px;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
#options-container {
min-height: 60px; /* More space for options */
}
/* --- Results View --- */
#results-view h2 {
color: var(--primary-color);
margin-bottom: 15px;
}
#results-summary {
font-size: 1.1em;
margin-bottom: 15px;
padding: 10px;
background-color: var(--light-color);
border-radius: 5px;
width: 90%;
}
#results-table-container {
width: 100%;
max-height: 50vh; /* Limit table height */
overflow-y: auto; /* Allow scrolling for table only */
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
#results-table {
width: 100%;
border-collapse: collapse;
}
#results-table th, #results-table td {
border: 1px solid #ddd;
padding: 8px 5px; /* Adjust padding */
text-align: center;
font-size: 0.95em;
}
#results-table th {
background-color: var(--secondary-color);
color: white;
position: sticky; /* Keep header visible */
top: 0;
z-index: 1;
}
#results-table tr:nth-child(even){ background-color: var(--light-color); }
.result-correct { color: var(--success-color); font-weight: bold; }
.result-incorrect { color: var(--danger-color); font-weight: bold; }
/* --- Buttons --- */
button {
padding: 12px 20px;
font-size: 1em;
font-family: var(--font-family);
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s ease, transform 0.1s ease;
min-width: 110px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button:hover {
opacity: 0.9;
}
button:active {
transform: scale(0.98); /* Slight press effect */
}
button:disabled {
background-color: var(--secondary-color);
cursor: not-allowed;
opacity: 0.7;
box-shadow: none;
}
.option-button {
background-color: var(--primary-color); /* Start neutral */
min-width: 120px; /* Ensure options fit */
}
.option-button.correct-option {
background-color: var(--success-color) !important; /* Force green */
color: white !important;
}
.option-button.incorrect-option {
background-color: var(--danger-color) !important; /* Force red */
color: white !important;
}
/* Style for selected but wrong */
.option-button.selected-wrong {
border: 3px solid var(--dark-color); /* Highlight selected wrong */
}
#ready-btn { background-color: var(--success-color); }
#ready-btn:hover { background-color: #146c43; }
#stop-video-btn { background-color: var(--danger-color); }
#stop-video-btn:hover { background-color: #bb2d3b; }
#next-btn, #finish-test-btn, #results-back-btn { background-color: var(--primary-color); }
#show-results-btn { background-color: var(--success-color); }
/* --- Responsive --- */
@media (max-width: 600px) {
.container {
width: 100%;
height: 100vh;
max-height: none;
border-radius: 0;
padding: 10px;
box-shadow: none;
justify-content: space-between;
}
#main-view button {
width: 70%;
font-size: 1.1em;
}
#video-container {
height: 50vh;
max-height: none;
margin-bottom: 10px;
}
button {
padding: 15px 18px;
font-size: 1.05em;
}
#options-container {
gap: 8px;
}
#results-table th, #results-table td {
font-size: 0.9em;
padding: 6px 4px;
}
#results-view {
padding-bottom: 15px;
}
}
</style>
</head>
<body>
<div class="container">
<!-- 1. Main Menu View -->
<div id="main-view" class="view">
<h1>اختبار الحكام</h1>
<button id="take-test-btn">بدء اختبار جديد</button>
<button id="my-results-btn">نتائجي السابقة</button>
<button id="exit-btn" disabled>خروج</button> <!-- Disabled for web context -->
</div>
<!-- 2. Test View -->
<div id="test-view" class="view">
<h2 id="status">الحالة 1 من X</h2>
<div id="video-container">
<video id="test-video" playsinline muted controlsList="nodownload nofullscreen noremoteplayback"></video>
</div>
<div id="controls-container">
<button id="ready-btn" style="display: none;">جاهز / تشغيل الفيديو</button>
<button id="stop-video-btn" style="display: none;">إيقاف الفيديو</button>
</div>
<div id="options-container">
<!-- Option buttons will be added here -->
</div>
<div id="feedback-container">
<!-- Next/Finish buttons will be added here -->
</div>
</div>
<!-- 3. Results View -->
<div id="results-view" class="view">
<h2>نتائج الاختبار</h2>
<div id="results-summary"></div>
<div id="results-table-container">
<table id="results-table">
<thead>
<tr>
<th>الحالة</th>
<th>القرار المتخذ</th>
<th>الإجابة الصحيحة</th>
<th>الوقت (ثانية)</th>
<th>النتيجة</th>
<th>نقاط (الوقت)</th> <!-- Score based on time -->
</tr>
</thead>
<tbody>
<!-- Result rows will be added here -->
</tbody>
</table>
</div>
<button id="results-back-btn">العودة للقائمة الرئيسية</button>
</div>
</div>
<script>
// --- Elements ---
const mainView = document.getElementById('main-view');
const testView = document.getElementById('test-view');
const resultsView = document.getElementById('results-view');
const takeTestBtn = document.getElementById('take-test-btn');
const myResultsBtn = document.getElementById('my-results-btn');
const exitBtn = document.getElementById('exit-btn'); // Although disabled, keep ref
const statusElement = document.getElementById('status');
const videoElement = document.getElementById('test-video');
const controlsContainer = document.getElementById('controls-container');
const readyBtn = document.getElementById('ready-btn');
const stopVideoBtn = document.getElementById('stop-video-btn');
const optionsContainer = document.getElementById('options-container');
const feedbackContainer = document.getElementById('feedback-container');
const resultsSummary = document.getElementById('results-summary');
const resultsTableBody = document.querySelector('#results-table tbody');
const resultsBackBtn = document.getElementById('results-back-btn');
// --- Test Data ---
const testCases = [
{
id: '1',
videoUrl: 'https://videos.pexels.com/video-files/6217182/6217182-hd_1920_1080_30fps.mp4',
options: ['خطأ (ركلة حرة)', 'لا يوجد خطأ', 'إنذار (سلوك غير رياضي)'],
correctAnswer: 'خطأ (ركلة حرة)' // Example answer
},
{
id: '2',
videoUrl: 'https://videos.pexels.com/video-files/6217184/6217184-hd_1920_1080_30fps.mp4',
options: ['تسلل', 'هدف صحيح', 'رمية تماس'],
correctAnswer: 'هدف صحيح' // Example answer
},
{ // Note: This video is vertical format
id: '3',
videoUrl: 'https://videos.pexels.com/video-files/6217345/6217345-hd_1080_1920_30fps.mp4',
options: ['ركلة جزاء', 'تمثيل (إنذار)', 'استمرار اللعب'],
correctAnswer: 'تمثيل (إنذار)' // Example answer
},
{
id: '4',
videoUrl: 'https://videos.pexels.com/video-files/6217064/6217064-hd_1920_1080_30fps.mp4',
options: ['طرد (لعب عنيف)', 'إنذار (تهور)', 'لا يوجد خطأ'],
correctAnswer: 'إنذار (تهور)' // Example answer
}
// Add more cases if needed
];
// --- State Variables ---
let currentCaseIndex = 0;
let decisionStartTime = 0;
let currentSessionResults = []; // Holds results for the test just taken
let allTimeResults = []; // Holds all results loaded/saved from storage
const RESULTS_STORAGE_KEY = 'refereeTestResults_v1';
// --- Functions ---
function showView(viewId) {
// Hide all views
document.querySelectorAll('.view').forEach(v => v.style.display = 'none');
// Show the requested view
const viewToShow = document.getElementById(viewId);
if (viewToShow) {
viewToShow.style.display = 'flex';
} else {
console.error("View not found:", viewId);
mainView.style.display = 'flex'; // Fallback to main view
}
}
function initializeApp() {
console.log("Initializing app...");
loadAllTimeResults(); // Load previous results from storage
// Attach main menu listeners
takeTestBtn.addEventListener('click', startTest);
myResultsBtn.addEventListener('click', showAllTimeResultsScreen);
// Exit button is disabled in web, but listener could be added for other contexts
// exitBtn.addEventListener('click', () => { alert('الخروج غير مدعوم في المتصفح.'); });
resultsBackBtn.addEventListener('click', goBackToMain);
// Attach test view listeners (event delegation might be better for options)
readyBtn.addEventListener('click', readyForVideo);
stopVideoBtn.addEventListener('click', handleStopVideo);
showView('main-view'); // Start at main menu
}
function startTest() {
currentCaseIndex = 0;
currentSessionResults = []; // Clear results for the new session
feedbackContainer.innerHTML = ''; // Clear feedback area
optionsContainer.innerHTML = ''; // Clear options area
loadCase(currentCaseIndex);
showView('test-view');
}
function loadCase(index) {
if (index >= testCases.length) {
// This shouldn't be reached here due to finishTest logic
console.error("Tried to load case beyond limits.");
finishTest(); // Go to finish sequence
return;
}
const currentCase = testCases[index];
statusElement.textContent = `الحالة ${index + 1} من ${testCases.length}`;
videoElement.src = currentCase.videoUrl;
videoElement.currentTime = 0;
videoElement.pause(); // Ensure video is paused initially
// Reset UI elements for the new case
optionsContainer.innerHTML = ''; // Clear previous options
feedbackContainer.innerHTML = ''; // Clear previous feedback/next button
stopVideoBtn.style.display = 'none'; // Hide stop button
readyBtn.style.display = 'inline-block'; // Show ready button
readyBtn.disabled = false;
console.log(`Case ${index + 1} loaded.`);
}
function readyForVideo() {
readyBtn.style.display = 'none'; // Hide ready button
stopVideoBtn.style.display = 'inline-block'; // Show stop button
stopVideoBtn.disabled = false;
// Attempt to play video
videoElement.play().then(() => {
console.log("Video playing...");
}).catch(error => {
console.error("Video play failed:", error);
// Handle autoplay failure if necessary (e.g., show play icon)
statusElement.textContent += " (حدث خطأ في تشغيل الفيديو)";
// Re-show ready button or provide manual play option if needed
stopVideoBtn.style.display = 'none';
readyBtn.style.display = 'inline-block';
});
}
function handleStopVideo() {
videoElement.pause();
decisionStartTime = performance.now(); // Record time when video is stopped
stopVideoBtn.disabled = true;
stopVideoBtn.style.display = 'none'; // Hide stop button after clicking
// Create and display options
const currentCase = testCases[currentCaseIndex];
optionsContainer.innerHTML = ''; // Clear just in case
currentCase.options.forEach(optionText => {
const button = document.createElement('button');
button.textContent = optionText;
button.classList.add('option-button');
// Use an arrow function to correctly pass the optionText
button.onclick = () => handleOptionSelect(optionText, button);
optionsContainer.appendChild(button);
});
console.log("Options displayed. Waiting for selection...");
}
function handleOptionSelect(selectedOption, selectedButton) {
const decisionEndTime = performance.now();
const decisionTime = ((decisionEndTime - decisionStartTime) / 1000); // Time in seconds
// Disable all option buttons after selection
const optionButtons = optionsContainer.querySelectorAll('.option-button');
optionButtons.forEach(btn => btn.disabled = true);
const currentCase = testCases[currentCaseIndex];
const isCorrect = selectedOption === currentCase.correctAnswer;
const score = isCorrect ? parseFloat(decisionTime.toFixed(2)) : null; // Score is time if correct, null otherwise
// Highlight correct and incorrect options
optionButtons.forEach(btn => {
if (btn.textContent === currentCase.correctAnswer) {
btn.classList.add('correct-option');
} else {
btn.classList.add('incorrect-option');
}
// Add special style if the user selected the wrong one
if (btn === selectedButton && !isCorrect) {
btn.classList.add('selected-wrong');
}
});
// Store the result for this session
currentSessionResults.push({
caseId: currentCase.id,
caseIndex: currentCaseIndex + 1,
selected: selectedOption,
correct: currentCase.correctAnswer,
time: parseFloat(decisionTime.toFixed(2)), // Store with 2 decimal places
isCorrect: isCorrect,
score: score // Time if correct, null if wrong
});
console.log(`Case ${currentCaseIndex + 1}: Selected ${selectedOption}, Correct: ${currentCase.correctAnswer}, Time: ${decisionTime.toFixed(2)}s, Correct: ${isCorrect}, Score: ${score}`);
// Show feedback/next controls
feedbackContainer.innerHTML = ''; // Clear previous
if (currentCaseIndex < testCases.length - 1) {
// Not the last case - show "Next" button
const nextBtn = document.createElement('button');
nextBtn.textContent = 'التالي 👈';
nextBtn.id = 'next-btn';
nextBtn.onclick = loadNextCase;
feedbackContainer.appendChild(nextBtn);
} else {
// Last case - show "Finish" buttons
const finishBtn = document.createElement('button');
finishBtn.textContent = '📊 عرض النتائج';
finishBtn.id = 'show-results-btn';
finishBtn.onclick = finishTest; // Save and show results screen
feedbackContainer.appendChild(finishBtn);
const backToMainBtn = document.createElement('button');
backToMainBtn.textContent = '🏠 القائمة الرئيسية';
backToMainBtn.id = 'finish-back-btn';
backToMainBtn.onclick = () => {
saveResults(); // Save results even if going back directly
goBackToMain();
};
feedbackContainer.appendChild(backToMainBtn);
}
}
function loadNextCase() {
currentCaseIndex++;
loadCase(currentCaseIndex);
}
function finishTest() {
console.log("Test finished. Saving results...");
saveResults();
showResultsScreen(currentSessionResults, "نتائج الاختبار الحالي"); // Show results of the session just completed
}
// Display results (can show current session or all time)
function showResultsScreen(resultsToShow, title) {
resultsView.querySelector('h2').textContent = title; // Set title (Current or All Time)
resultsTableBody.innerHTML = ''; // Clear previous results table
let correctCount = 0;
let totalScore = 0; // Sum of times for correct answers
let validScoresCount = 0; // Count of cases with valid scores (correct answers)
if (!resultsToShow || resultsToShow.length === 0) {
resultsSummary.textContent = 'لا توجد نتائج لعرضها.';
showView('results-view');
return;
}
resultsToShow.forEach(result => {
const row = resultsTableBody.insertRow();
row.insertCell(0).textContent = result.caseIndex || result.caseId; // Show index or ID
row.insertCell(1).textContent = result.selected;
row.insertCell(2).textContent = result.correct;
row.insertCell(3).textContent = result.time.toFixed(2); // Format time
const statusCell = row.insertCell(4);
statusCell.textContent = result.isCorrect ? 'صحيح' : 'خطأ';
statusCell.classList.add(result.isCorrect ? 'result-correct' : 'result-incorrect');
const scoreCell = row.insertCell(5);
scoreCell.textContent = result.score !== null ? result.score.toFixed(2) : '---'; // Show score (time) or dashes
if (result.isCorrect) {
correctCount++;
}
if (result.score !== null) {
totalScore += result.score;
validScoresCount++;
}
});
const accuracy = resultsToShow.length > 0 ? ((correctCount / resultsToShow.length) * 100).toFixed(1) : 0;
// Calculate average score (time) only for correct answers
const averageScore = validScoresCount > 0 ? (totalScore / validScoresCount).toFixed(2) : 'N/A';
resultsSummary.innerHTML = `
إجمالي الحالات: ${resultsToShow.length}<br>
الإجابات الصحيحة: ${correctCount} (${accuracy}%)<br>
متوسط نقاط القرار الصحيح (الوقت): ${averageScore} ثانية (الأقل أفضل)
`;
showView('results-view');
}
function showAllTimeResultsScreen() {
if (allTimeResults.length === 0) {
alert("لا توجد نتائج سابقة مسجلة.");
// Optionally show the empty results screen
showResultsScreen([], "نتائجي السابقة");
return;
}
console.log("Showing all-time results.");
// Sort results by timestamp if available, or just show as loaded
showResultsScreen(allTimeResults, "نتائجي السابقة");
}
function saveResults() {
if (currentSessionResults.length > 0) {
// Add a timestamp to the session results before saving
const timestamp = new Date().toISOString();
const sessionData = {
timestamp: timestamp,
results: currentSessionResults
};
// Add current session to the beginning of all-time results
allTimeResults.unshift(sessionData); // Add newest first
try {
localStorage.setItem(RESULTS_STORAGE_KEY, JSON.stringify(allTimeResults));
console.log("Results saved to localStorage.");
// Clear session results after saving
currentSessionResults = [];
} catch (e) {
console.error("Failed to save results to localStorage:", e);
alert("حدث خطأ أثناء حفظ النتائج. قد تكون مساحة التخزين ممتلئة.");
}
} else {
console.log("No new results in current session to save.");
}
}
function loadAllTimeResults() {
try {
const storedResults = localStorage.getItem(RESULTS_STORAGE_KEY);
if (storedResults) {
allTimeResults = JSON.parse(storedResults);
// Basic validation: ensure it's an array
if (!Array.isArray(allTimeResults)) {
console.warn("Stored results format is invalid, resetting.");
allTimeResults = [];
}
// If results are stored as sessions, flatten them for display (or adjust display logic)
// For simplicity here, let's flatten them.
let flattenedResults = [];
allTimeResults.forEach(session => {
if(session.results && Array.isArray(session.results)) {
// Add session timestamp to each result for potential sorting later
session.results.forEach(r => r.sessionTimestamp = session.timestamp);
flattenedResults = flattenedResults.concat(session.results);
} else if (session.caseId) {
// Handle older format if necessary (where results were saved individually)
flattenedResults.push(session);
}
});
allTimeResults = flattenedResults; // Overwrite with flattened list for display
console.log(`Loaded ${allTimeResults.length} results from localStorage.`);
} else {
allTimeResults = [];
console.log("No previous results found in localStorage.");
}
} catch (e) {
console.error("Failed to load or parse results from localStorage:", e);
allTimeResults = [];
// Optionally clear potentially corrupted storage
// localStorage.removeItem(RESULTS_STORAGE_KEY);
}
}
function goBackToMain() {
// Optional: Stop video if going back from results during a test (unlikely scenario now)
if (!videoElement.paused) {
videoElement.pause();
}
videoElement.src = ''; // Clear video source
showView('main-view');
}
// --- Initialization ---
document.addEventListener('DOMContentLoaded', initializeApp);
// --- Prevent leaving page during test ---
window.addEventListener('beforeunload', (event) => {
if (testView.style.display === 'flex' && currentSessionResults.length < testCases.length) {
// Check if test view is active and test is not finished
event.preventDefault();
event.returnValue = 'هل أنت متأكد من رغبتك في المغادرة؟ سيتم فقدان تقدم الاختبار الحالي.'; // Standard confirmation message
}
});
</script>
</body>
</html>