-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseIDs.ts
29 lines (23 loc) · 1.34 KB
/
parseIDs.ts
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
import {HTMLElement} from "node-html-parser";
export const IDsTypes = ["group", "auditory", "teacher", "weekday"] as const;
export type IDsType = typeof IDsTypes[number];
export type IDsRecords = Record<IDsType, Map<string, number>>;
const ignoringValues: Array<string> = ["Выберите класс", "Выберите аудиторию", "Выберите преподавателя", "Выберите день", "Нет", "Учитель"];
export default function parseIDs (page: HTMLElement): IDsRecords {
let IDs = Object.fromEntries(IDsTypes.map(IDType => [IDType, new Map<string, number>()])) as IDsRecords;
page.getElementsByTagName("form")[0]
.getElementsByTagName("select")
// @ts-ignore I can't use string as searchElement in includes method of IDsTypes (readonly array of literals)
.filter(element => IDsTypes.includes(element.attributes["data-name"]))
.forEach(select => {
let IDType = select.attributes["data-name"] as IDsType;
select.getElementsByTagName("option")
.filter(option => !ignoringValues.includes(option.text))
.forEach(option => {
let name = option.text;
let id = parseInt(option.attributes["value"]);
IDs[IDType].set(name, id);
});
});
return IDs;
}