-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathout.js
More file actions
101 lines (92 loc) · 2.38 KB
/
out.js
File metadata and controls
101 lines (92 loc) · 2.38 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
(async () => {
const DATABASE_URL =
"https://studentvue-sign-out-default-rtdb.firebaseio.com/index";
const auth =
localStorage.getItem("vnjneoijfononsdonsofowiejfondsofnsofsdofijnm") ===
"fun" &&
localStorage.getItem("sdfokjfnkjnwkeijdcjoisjfijknnskjdfh9o2093urd") ===
"untrue" &&
localStorage.getItem("kvjkniuu49hj0923uroovojwofi2039ruoxvjohf0r9f") ===
"true" &&
localStorage.getItem("auth") === "true";
if (auth !== true) {
window.location.replace("./noauth.html");
return;
}
const urlParams = new URLSearchParams(window.location.search);
const dbID = urlParams.get("dbID");
var data;
var queue = urlParams.get("queue") ? urlParams.get("queue") : [];
console.log(queue);
var nextIndex;
data = await fetch(DATABASE_URL + ".json").then((data) => {
return data.json();
});
document.getElementById("out").textContent = data[dbID].Name;
document.getElementById("studentForm").addEventListener("submit", (e) => {
e.preventDefault();
const index = data.findIndex((i) => {
return document.getElementById("studentID").value == i.ID;
});
if (index == dbID) {
return;
}
// Add student to queue
if (queue.length == 0) {
nextIndex = data.findIndex((i) => {
return document.getElementById("studentID").value == i.ID;
});
}
queue.push(data[index]);
document.getElementById("next").innerHTML = queue[0].Name + " is next";
});
document.getElementById("back").addEventListener("click", async () => {
const dataToSend = {
in: Date.now(),
out: data[dbID].outs[data[dbID].outs.length - 1].out,
};
const reqData = {
method: "PUT",
body: JSON.stringify(dataToSend),
headers: {
"Content-Type": "application/json",
},
};
await fetch(
DATABASE_URL +
"/" +
String(dbID) +
"/outs/" +
String(data[dbID].outs.length - 1) +
".json",
reqData
);
if (queue.length == 0) {
window.location.replace("./index.html");
return;
}
const dataToSend2 = {
out: Date.now(),
};
const reqData2 = {
method: "PUT",
body: JSON.stringify(dataToSend2),
headers: {
"Content-Type": "application/json",
},
};
await fetch(
DATABASE_URL +
"/" +
String(nextIndex) +
"/outs/" +
String(data[nextIndex].outs ? data[nextIndex].outs.length : 0) +
".json",
reqData2
);
queue.shift();
window.location.replace(
"./out.html?dbID=" + nextIndex + "&queue=" + queue
);
});
})();