-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
97 lines (80 loc) · 2.94 KB
/
script.js
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
let rollCallData = [];
let countdownTimer;
const countdownDuration = 10; // 10 seconds
let acceptingSubmissions = false;
function submitRollCall() {
if (!acceptingSubmissions) {
document.getElementById('checkInStatus').innerText = "Roll call not active. Please wait for the timer.";
return;
}
const name = document.getElementById('name').value.trim();
const id = document.getElementById('id').value.trim();
if (!name || !id) {
document.getElementById('checkInStatus').innerText = "Name and ID are required!";
return;
}
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const withinBounds = (latitude > 31.6000 && latitude < 31.8000) &&
(longitude > 130.9000 && longitude < 131.2000);
if (withinBounds) {
document.getElementById('locationStatus').innerText = "Location verified ✅";
saveRollCallData(name, id, latitude, longitude);
} else {
document.getElementById('locationStatus').innerText = "Outside allowed location ❌";
}
});
} else {
document.getElementById('locationStatus').innerText = "Geolocation not supported by this browser.";
}
}
function saveRollCallData(name, id, latitude, longitude) {
const timestamp = new Date().toLocaleString();
rollCallData.push({ name, id, latitude, longitude, timestamp });
const tableRow = `
<tr>
<td>${name}</td>
<td>${id}</td>
<td>${latitude.toFixed(4)}</td>
<td>${longitude.toFixed(4)}</td>
<td>${timestamp}</td>
</tr>
`;
document.getElementById('submissionTable').insertAdjacentHTML('beforeend', tableRow);
document.getElementById('checkInStatus').innerText = "Check-In Successful!";
}
function startCountdown() {
acceptingSubmissions = true;
let timeLeft = countdownDuration;
document.getElementById('timer').innerText = `Roll call active for ${timeLeft} seconds...`;
countdownTimer = setInterval(() => {
timeLeft -= 1;
document.getElementById('timer').innerText = `Roll call active for ${timeLeft} seconds...`;
if (timeLeft <= 0) {
clearInterval(countdownTimer);
acceptingSubmissions = false;
promptFileDownload();
}
}, 1000);
}
function promptFileDownload() {
const data = JSON.stringify(rollCallData, null, 2);
const blob = new Blob([data], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "rollcall_data.json";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
document.getElementById('timer').innerText = "Download complete!";
}
function openHelp() {
document.getElementById('helpModal').style.display = "block";
}
function closeHelp() {
document.getElementById('helpModal').style.display = "none";
}