blob: 991876d1a65727a6d60ff4c45e33d27923e9be1f (
plain)
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
|
import { getUserIconUrl, getCourseParticipantsUrl } from "./config.js";
/**
* Class to represent Students.
*/
class Student {
constructor(id, name, group) {
this.id = id;
this.name = name;
this.group = group;
}
async getIconUrl() {
return await getUserIconUrl(this.id);
}
}
async function fetchStudent(nameFilter, groupFilter) {
return await fetchStudents(nameFilter, groupFilter)[0];
}
const idRegex = /id=(\d+)/;
async function fetchStudents(nameFilter, groupFilter) {
const res = await fetch(getCourseParticipantsUrl());
const doc = new DOMParser().parseFromString(await res.text(), "text/html");
const table = doc.querySelector("tbody");
let students = [];
table.querySelectorAll("tr").forEach(row => {
if (row.classList.contains("emptyrow"))
return;
const roleCell = row.querySelector(".c4");
// TODO(muhq): Is this locale dependent?
if (roleCell.innerHTML.includes("Lehrer")) {
return;
}
const nameCell = row.querySelector(".c1");
let name;
if (nameCell.firstChild.firstChild.tagName == "SPAN")
name = nameCell.firstChild.firstChild.title;
else
name = nameCell.innerText;
const profileUrl = nameCell.querySelector("a.aabtn").href;
const match = idRegex.exec(profileUrl);
const id = match[1];
const groupCell = row.querySelector(".c5");
const groupsText = groupCell.querySelector("a.quickeditlink").textContent;
const group = groupsText.trim();
if ((!nameFilter || name.includes(nameFilter)) &&
(!groupFilter || groupFilter === group))
{
students.push(new Student(id, name, group));
}
});
return students;
}
export { Student, fetchStudents, fetchStudent };
|