-
Notifications
You must be signed in to change notification settings - Fork 0
/
teacher-page-get.js
34 lines (33 loc) · 963 Bytes
/
teacher-page-get.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
console.log(JSON.stringify((() => {
const items = Array.from(document.querySelectorAll('#main > article.page.type-page > div.entry-content > *'))
const result = [];
let currentHeader = null;
for (const item of items) {
if (item.nodeName === 'P') {
// a no-subject field
result.push({
department: '',
text: item.innerHTML
});
} else if (item.nodeName === 'UL') {
if (currentHeader) {
for (const child of Array.from(item.children)) {
if (child.nodeName === 'LI') {
result.push({
department: currentHeader,
text: child.innerHTML
});
}
}
}
} else if (item.nodeName === 'H2') {
currentHeader = item.innerText.trim();
if (currentHeader === 'Departments') {
// this header doesn't count!
currentHeader = null;
}
}
// ignore all other node names
}
return result;
})()));