const type = getParameterByName("type");
const dropdown = document.getElementById("answer");
const question_input = document.getElementById("question");
const question_label = document.getElementById("question_label");
if (!["teacher", "pupil"].includes(type)) window.location.href = "/";
dropdown.insertAdjacentHTML(
"beforeend",
'",
);
document.querySelector("legend").innerText = type == "teacher" ? "Lehrer-Ranking" : "Schüler-Ranking";
document.querySelector("p").innerText = "Welche/r " + (type == "teacher" ? "Lehrer/in" : "Schüler/in") + "...";
document.querySelector("form").setAttribute("action", "api/answer?type=" + type);
function appendOption(response) {
response.forEach((elem) => {
dropdown.insertAdjacentHTML(
"beforeend",
``,
);
});
}
fetch("/auth/api/list" + (type == "teacher" ? "?class=teacher" : ""))
.then((response) => response.json())
.then((response) => appendOption(response));
fetch("/poll/api/get?type=" + type)
.then((response) => response.json())
.then((response) => {
question_label.innerText = response["question"];
question_input.setAttribute("value", response["id"]);
});
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return "";
return decodeURIComponent(results[2].replace(/\+/g, " "));
}