Spaces:
Running
Running
Update index.html
Browse files- index.html +65 -67
index.html
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
body {
|
| 7 |
font-family: Arial;
|
| 8 |
padding: 20px;
|
|
|
|
| 9 |
background-color: #f0f8ff;
|
| 10 |
color: #333;
|
| 11 |
}
|
|
@@ -83,13 +84,7 @@ button:disabled {
|
|
| 83 |
</div>
|
| 84 |
|
| 85 |
<script>
|
| 86 |
-
// ----------------
|
| 87 |
-
const allQuestions = [
|
| 88 |
-
{q:"Which index does an array start with in C?", options:["0","1","-1","Depends on compiler"], answer:"0"},
|
| 89 |
-
{q:"Which of the following correctly declares an integer array?", options:["int arr{};","int arr[10];","int arr;","int [10]arr;"], answer:"int arr[10];"},
|
| 90 |
-
{q:"What is the last valid index of an array arr[8]?", options:["7","8","6","5"], answer:"7"},
|
| 91 |
-
];
|
| 92 |
-
|
| 93 |
let selectedQuestions = [];
|
| 94 |
let userAnswers = {};
|
| 95 |
let userName, appId;
|
|
@@ -100,9 +95,22 @@ let currentIndex = 0;
|
|
| 100 |
let timerInterval;
|
| 101 |
let remainingTime = 12 * 60;
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
// ---------------- VALIDATE AND START
|
| 106 |
async function validateAndStart(){
|
| 107 |
userName = document.getElementById("name").value.trim();
|
| 108 |
appId = document.getElementById("appId").value.trim();
|
|
@@ -129,14 +137,16 @@ async function validateAndStart(){
|
|
| 129 |
// ---------------- CHECK PREVIOUS ATTEMPT ------------------
|
| 130 |
function checkPreviousAttempt(appId){
|
| 131 |
return fetch(GOOGLE_SHEET_URL + "?checkAppId=" + encodeURIComponent(appId))
|
| 132 |
-
.then(
|
| 133 |
-
.then(
|
| 134 |
-
.catch(
|
| 135 |
}
|
| 136 |
|
| 137 |
// ---------------- START TEST ------------------
|
| 138 |
-
function startTest(){
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
|
| 141 |
document.getElementById("user-info").classList.add("hidden");
|
| 142 |
document.getElementById("quiz").classList.remove("hidden");
|
|
@@ -144,12 +154,51 @@ function startTest(){
|
|
| 144 |
examStarted = true;
|
| 145 |
testSubmitted = false;
|
| 146 |
|
| 147 |
-
enterFullscreen();
|
|
|
|
| 148 |
currentIndex = 0;
|
| 149 |
showQuestion();
|
| 150 |
startTimer();
|
| 151 |
}
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
// ---------------- TIMER ------------------
|
| 154 |
function startTimer(){
|
| 155 |
updateTimerDisplay();
|
|
@@ -170,7 +219,7 @@ function updateTimerDisplay(){
|
|
| 170 |
document.getElementById("timer").innerText = `Time Left: ${minutes}m ${seconds}s`;
|
| 171 |
}
|
| 172 |
|
| 173 |
-
// ---------------- SHOW
|
| 174 |
function showQuestion(){
|
| 175 |
const q = selectedQuestions[currentIndex];
|
| 176 |
const container = document.getElementById("question-container");
|
|
@@ -204,57 +253,6 @@ function nextQuestion(){
|
|
| 204 |
}
|
| 205 |
}
|
| 206 |
|
| 207 |
-
// ---------------- FULLSCREEN HANDLING ------------------
|
| 208 |
-
function enterFullscreen(){
|
| 209 |
-
document.documentElement.requestFullscreen().catch(()=>{});
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
document.addEventListener("fullscreenchange", () => {
|
| 213 |
-
if(!document.fullscreenElement && examStarted && !testSubmitted){
|
| 214 |
-
violations++;
|
| 215 |
-
alert("You exited fullscreen! Test submitted.");
|
| 216 |
-
submitTest();
|
| 217 |
-
}
|
| 218 |
-
});
|
| 219 |
-
|
| 220 |
-
// ---------------- AUTO SUBMIT ON ALT+TAB / WINDOWS KEY ------------------
|
| 221 |
-
window.addEventListener("blur", function () {
|
| 222 |
-
if (examStarted && !testSubmitted) {
|
| 223 |
-
violations++;
|
| 224 |
-
alert("You switched windows! Test submitted automatically.");
|
| 225 |
-
submitTest();
|
| 226 |
-
}
|
| 227 |
-
});
|
| 228 |
-
|
| 229 |
-
// ---------------- BLOCK ALL KEYS EXCEPT ESC ------------------
|
| 230 |
-
document.addEventListener("keydown", function(e){
|
| 231 |
-
if (!examStarted || testSubmitted) return;
|
| 232 |
-
|
| 233 |
-
if (e.key === "Escape") return;
|
| 234 |
-
|
| 235 |
-
// Block Windows key
|
| 236 |
-
if (e.key === "Meta" || e.metaKey){
|
| 237 |
-
e.preventDefault();
|
| 238 |
-
return false;
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
// Block function keys
|
| 242 |
-
if (e.key.startsWith("F")){
|
| 243 |
-
e.preventDefault();
|
| 244 |
-
return false;
|
| 245 |
-
}
|
| 246 |
-
|
| 247 |
-
// Block Ctrl, Alt, Shift combinations
|
| 248 |
-
if (e.ctrlKey || e.altKey || e.shiftKey){
|
| 249 |
-
e.preventDefault();
|
| 250 |
-
return false;
|
| 251 |
-
}
|
| 252 |
-
|
| 253 |
-
e.preventDefault();
|
| 254 |
-
e.stopPropagation();
|
| 255 |
-
return false;
|
| 256 |
-
});
|
| 257 |
-
|
| 258 |
// ---------------- SUBMIT TEST ------------------
|
| 259 |
function submitTest(){
|
| 260 |
testSubmitted = true;
|
|
|
|
| 6 |
body {
|
| 7 |
font-family: Arial;
|
| 8 |
padding: 20px;
|
| 9 |
+
text-align: center;
|
| 10 |
background-color: #f0f8ff;
|
| 11 |
color: #333;
|
| 12 |
}
|
|
|
|
| 84 |
</div>
|
| 85 |
|
| 86 |
<script>
|
| 87 |
+
// ---------------- GLOBAL VARIABLES ------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
let selectedQuestions = [];
|
| 89 |
let userAnswers = {};
|
| 90 |
let userName, appId;
|
|
|
|
| 95 |
let timerInterval;
|
| 96 |
let remainingTime = 12 * 60;
|
| 97 |
|
| 98 |
+
// ⭐ Your Google Script URL
|
| 99 |
+
const GOOGLE_SHEET_URL = "https://script.google.com/macros/s/AKfycbyVGWoxkoifMLXDN6M8bbH6_Gr6RBttgCTTvX_j63l2yZYGt_BIW7yC8keLbhns3eB1/exec";
|
| 100 |
+
|
| 101 |
+
// ---------------- LOAD QUESTIONS ------------------
|
| 102 |
+
async function loadQuestionsFromServer() {
|
| 103 |
+
const res = await fetch(GOOGLE_SHEET_URL + "?getQuestions=1");
|
| 104 |
+
const data = await res.json();
|
| 105 |
+
|
| 106 |
+
return data.map(q => ({
|
| 107 |
+
q: q.question,
|
| 108 |
+
options: q.options,
|
| 109 |
+
answer: q.options[q.answer - 1]
|
| 110 |
+
}));
|
| 111 |
+
}
|
| 112 |
|
| 113 |
+
// ---------------- VALIDATE AND START ------------------
|
| 114 |
async function validateAndStart(){
|
| 115 |
userName = document.getElementById("name").value.trim();
|
| 116 |
appId = document.getElementById("appId").value.trim();
|
|
|
|
| 137 |
// ---------------- CHECK PREVIOUS ATTEMPT ------------------
|
| 138 |
function checkPreviousAttempt(appId){
|
| 139 |
return fetch(GOOGLE_SHEET_URL + "?checkAppId=" + encodeURIComponent(appId))
|
| 140 |
+
.then(r => r.json())
|
| 141 |
+
.then(d => d.exists)
|
| 142 |
+
.catch(() => false);
|
| 143 |
}
|
| 144 |
|
| 145 |
// ---------------- START TEST ------------------
|
| 146 |
+
async function startTest(){
|
| 147 |
+
|
| 148 |
+
const allQuestions = await loadQuestionsFromServer();
|
| 149 |
+
selectedQuestions = allQuestions.sort(()=>0.5 - Math.random());
|
| 150 |
|
| 151 |
document.getElementById("user-info").classList.add("hidden");
|
| 152 |
document.getElementById("quiz").classList.remove("hidden");
|
|
|
|
| 154 |
examStarted = true;
|
| 155 |
testSubmitted = false;
|
| 156 |
|
| 157 |
+
await enterFullscreen(); // ⭐ NOW FULLSCREEN ENTERS CLEANLY ⭐
|
| 158 |
+
|
| 159 |
currentIndex = 0;
|
| 160 |
showQuestion();
|
| 161 |
startTimer();
|
| 162 |
}
|
| 163 |
|
| 164 |
+
// ---------------- FULLSCREEN FUNCTION ------------------
|
| 165 |
+
async function enterFullscreen() {
|
| 166 |
+
let elem = document.documentElement;
|
| 167 |
+
|
| 168 |
+
if (elem.requestFullscreen) await elem.requestFullscreen();
|
| 169 |
+
else if (elem.webkitRequestFullscreen) await elem.webkitRequestFullscreen();
|
| 170 |
+
else if (elem.msRequestFullscreen) await elem.msRequestFullscreen();
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// ---------------- FULLSCREEN EXIT DETECTION ------------------
|
| 174 |
+
document.addEventListener("fullscreenchange", () => {
|
| 175 |
+
if (!document.fullscreenElement && examStarted && !testSubmitted) {
|
| 176 |
+
violations++;
|
| 177 |
+
alert("⚠ You exited fullscreen! Test submitted automatically.");
|
| 178 |
+
submitTest();
|
| 179 |
+
}
|
| 180 |
+
});
|
| 181 |
+
|
| 182 |
+
// ---------------- AUTO SUBMIT ON ALT+TAB ------------------
|
| 183 |
+
window.addEventListener("blur", () => {
|
| 184 |
+
if (examStarted && !testSubmitted) {
|
| 185 |
+
violations++;
|
| 186 |
+
alert("⚠ Window switch detected! Test submitted.");
|
| 187 |
+
submitTest();
|
| 188 |
+
}
|
| 189 |
+
});
|
| 190 |
+
|
| 191 |
+
// ---------------- BLOCK KEYS ------------------
|
| 192 |
+
document.addEventListener("keydown", function(e){
|
| 193 |
+
if (!examStarted || testSubmitted) return;
|
| 194 |
+
|
| 195 |
+
if (e.key === "Escape") return;
|
| 196 |
+
if (e.key.startsWith("F")) e.preventDefault();
|
| 197 |
+
if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) e.preventDefault();
|
| 198 |
+
|
| 199 |
+
e.preventDefault();
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
// ---------------- TIMER ------------------
|
| 203 |
function startTimer(){
|
| 204 |
updateTimerDisplay();
|
|
|
|
| 219 |
document.getElementById("timer").innerText = `Time Left: ${minutes}m ${seconds}s`;
|
| 220 |
}
|
| 221 |
|
| 222 |
+
// ---------------- SHOW QUESTION ------------------
|
| 223 |
function showQuestion(){
|
| 224 |
const q = selectedQuestions[currentIndex];
|
| 225 |
const container = document.getElementById("question-container");
|
|
|
|
| 253 |
}
|
| 254 |
}
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
// ---------------- SUBMIT TEST ------------------
|
| 257 |
function submitTest(){
|
| 258 |
testSubmitted = true;
|