-
Notifications
You must be signed in to change notification settings - Fork 1
/
ekonomi.html
264 lines (221 loc) · 7.59 KB
/
ekonomi.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script class="jsbin" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<title>CERDIG SCIENCE COMPETITION</title>
<style type="text/css" media="screen">
body {
overflow: visible;
margin: 0;
padding: 0;
font-size: 16px;
}
#timer {
background-color: #000000;
color: #FFFFFF;
font-family: arial;
font-weight: bold;
padding: 10px 30px;
margin: 20px;
border-radius: 100px;
}
iframe {
max-width: 100%;
height: 800px;
width: 100%;
border: 0;
padding-top: 8px;
margin: 0;
}
#form {
padding: 10px;
}
#popup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
/* Semi-transparent background */
z-index: 1000;
}
#popup-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background-color: #fff;
border: 1px solid #000;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
z-index: 1001;
/* Ensure the content is above the background */
}
#popup-time {
font-size: 18px;
font-weight: bold;
}
@media screen and (max-width: 600px) {
#timer {
padding: 5px 15px;
margin: 20px;
}
body {
font-size: 14px;
}
}
</style>
</head>
<body>
<div id="timer" align="center"><a class="fa fa-clock-o"></a> <span id="time"></span></div>
<span id="form">
<iframe src="https://forms.gle/kcykR8BDMzrzyYvh7">Mohon
Menunggu</iframe><br />
</span>
<div id="popup">
<div id="popup-content">
<p>Halaman ini dibekukan karena anda terdeteksi melakukan kecurangan.<br>Popup akan muncul selama:</p>
<p id="popup-time"></p>
</div>
</div>
<script>
var intervalpopupblockID = [];
var isPopupActiveLocal = false;
function isPopupActive() {
if (document.getElementById("popup").style.display === "block") return true;
return false;
};
function startTimer(duration, timerInterval, tolerance, display) {
var timer = duration;
var timerIntervalId;
var batas = timer + tolerance * 60;
timerInterval = 60 * timerInterval;
timerIntervalId = setInterval(function () {
var delayMinutes = parseInt((timer - timerInterval) / 60, 10);
var delaySeconds = parseInt((timer - timerInterval) % 60, 10);
var formattedTime = formatTime(delayMinutes, delaySeconds);
var minutes = parseInt(timer / 60, 10);
var seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
delayMinutes = delayMinutes < 10 ? "0" + delayMinutes : delayMinutes;
delaySeconds = delaySeconds < 10 ? "0" + delaySeconds : delaySeconds;
if (timer <= timerInterval) {
document.getElementById("form").style.visibility = "visible";
display.textContent = "Tersisa " + minutes + " Menit " + seconds + " detik ";
} else {
display.textContent = "Soal dibuka " + formattedTime + " lagi";
}
if (--timer < 0) {
display.textContent = tolerance + " Menit Toleransi, SILAHKAN TEKAN TOMBOL SUBMIT!";
}
if (--batas < 0) {
document.getElementById("form").style.visibility = "hidden";
display.textContent = "TIMES UP! TERIMAKASIH.";
}
}, 1000);
return timerIntervalId;
}
function formatTime(minutes, seconds) {
var days = Math.floor(minutes / (60 * 24));
var hours = Math.floor((minutes % (60 * 24)) / 60);
var remainingMinutes = minutes % 60;
var remainingSeconds = seconds;
days = days > 0 ? days + " Hari " : "";
hours = hours > 0 ? hours + " Jam " : "";
remainingMinutes = remainingMinutes > 0 ? remainingMinutes + " Menit " : "";
remainingSeconds = remainingSeconds > 0 ? remainingSeconds + " Detik" : "";
return days + hours + remainingMinutes + remainingSeconds;
}
function addMinutes(date, minutes) {
date.setMinutes(date.getMinutes() + minutes);
return date;
}
function showPopup(popupTimerValue) {
console.log('called')
var popup = document.getElementById("popup");
popup.style.display = "block";
var popupDisplay = document.querySelector('#popup-time');
var intervalId = setInterval(function () {
console.log(intervalId, popupTimerValue)
var minutes = parseInt(popupTimerValue / 60, 10);
var seconds = parseInt(popupTimerValue % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
popupDisplay.textContent = minutes + ":" + seconds + " Menit";
if (--popupTimerValue < 0) {
popup.style.display = "none";
clearInterval(intervalId);
// Set status popup aktif ke localStorage
localStorage.setItem("isPopupActive", false);
}
}, 1000);
return intervalId;
}
var intervalId = 0;
isRefresh = false;
window.onbeforeunload = function () {
isRefresh = true;
}
function handleVisibilityChange() {
if (document.visibilityState === "hidden") {
if (isRefresh) return;
if (intervalpopupblockID.length != 0 || isPopupActive()) {
for (var z of intervalpopupblockID) {
clearInterval(z);
}
}
localStorage.setItem("isPopupActive", true);
intervalId = showPopup(initialPopupTimer);
intervalpopupblockID.push(intervalId);
} else {
// Pengguna kembali ke tab saat ini
console.log("Pengguna kembali ke halaman");
}
}
function resetTimer() {
clearInterval(timerInterval);
var timerIntervalValue = 90;
var tolerance = 1;
var startDate = '2023-11-18T09:43:00.000';
var display = document.querySelector('#time');
var initDate = new Date(startDate);
var countDownDate = addMinutes(initDate, timerIntervalValue);
var nowDate = new Date();
var duration = (countDownDate.getTime() - nowDate.getTime()) / 1000;
// Jika waktu sudah habis, langsung sembunyikan form
if (duration <= 0) {
document.getElementById("form").style.visibility = "hidden";
display.textContent = "TIMES UP! TERIMAKASIH.";
return;
}
// Jika waktu belum habis, set timer dan tampilkan form
timerInterval = startTimer(duration, timerIntervalValue, tolerance, display);
document.getElementById("form").style.visibility = "hidden";
}
// Menambahkan variabel initialPopupTimer dan timerInterval secara lokal
var initialPopupTimer = 5 * 60;
var timerInterval;
window.onload = function () {
// Cek status popup di localStorage saat halaman dimuat
isPopupActiveLocal = localStorage.getItem("isPopupActive") === "true";
// Jika popup sedang aktif, tampilkan
if (isPopupActiveLocal) {
showPopup(initialPopupTimer);
}
resetTimer(); // supaya sisa waktu ujian tetap ditampilkan
document.addEventListener("visibilitychange", handleVisibilityChange, false);
// setInterval(function () {
// var isActive = document.hasFocus();
// if (!isActive && isPopupActive()) {
// showPopup(initialPopupTimer);
// }
// }, 7000);
};
</script>
</body>
</html>