-
Notifications
You must be signed in to change notification settings - Fork 2
/
course.js
80 lines (70 loc) · 3.72 KB
/
course.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
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
main();
function main() {
checkAllCourses();
}
function checkInterestedCourses() {
// get all wanted courses
var list = localStorage.getItem("courses");
if (!list) {
console.log("No wanted course. Exit");
return;
}
// monitor courses avalibility
var handle = setInterval(function () {
list.forEach(element => {
GM_xmlhttpRequest({
"method": "POST",
"url": "https://bkzhjx.wh.sdu.edu.cn/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=" + element + "&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=",
"data": "sEcho=1&iColumns=16&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=dwmc&mDataProp_4=jkfs&mDataProp_5=xmmc&mDataProp_6=xf&mDataProp_7=skls&mDataProp_8=sksj&mDataProp_9=skdd&mDataProp_10=xqmc&mDataProp_11=xkrs&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=szkcflmc&mDataProp_15=czOper",
"nocache": true,
"responseType": "json",
"onload": function (response) {
if (!response.response || !response.response.aaData || !response.response.aaData[0].syrs || !response.response.aaData[0].kcmc) {
console.log("Responsed data contains error. Exit");
clearInterval(handle);
return;
}
if (response.response.aaData[0].syrs != "0") {
new Notification("Course " + response.response.aaData[0].kcmc + "(" + element + ") is avaliable now. Left seats: " + response.response.aaData[0].syrs);
}
},
});
});
}, Math.random() * 10000 + 20000);
}
function checkAllCourses() {
// monitor courses avalibility
console.log("checking all courses...");
var handle = setInterval(function () {
console.log("current time: " + new Date().getTime());
GM_xmlhttpRequest({
"method": "POST",
"url": "https://bkzhjx.wh.sdu.edu.cn/jsxsd/xsxkkc/xsxkGgxxkxk?kcxx=&skls=&skxq=&skjc=&sfym=false&sfct=false&szjylb=&sfxx=true&skfs=&xqid=",
"headers": { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", },
"data": "sEcho=1&iColumns=16&sColumns=&iDisplayStart=0&iDisplayLength=300&mDataProp_0=kch&mDataProp_1=kcmc&mDataProp_2=kxhnew&mDataProp_3=dwmc&mDataProp_4=jkfs&mDataProp_5=xmmc&mDataProp_6=xf&mDataProp_7=skls&mDataProp_8=sksj&mDataProp_9=skdd&mDataProp_10=xqmc&mDataProp_11=xkrs&mDataProp_12=syrs&mDataProp_13=ctsm&mDataProp_14=szkcflmc&mDataProp_15=czOper",
"nocache": true,
"responseType": "json",
"onload": function (response) {
if (!response.response || !response.response.aaData) {
console.log("Responsed data contains error. Exit");
clearInterval(handle);
return;
}
var data = response.response.aaData;
console.log("total course number: " + data.length);
var notificationdata = "";
data.forEach(element => {
console.log("course: " + element.kcmc + " , course availability: " + element.syrs);
if (element.syrs < 5 && element.syrs != 0) {
notificationdata += element.kcmc + "(" + element.kch + ") is avaliable now. Left: " + element.syrs + "\n";
}
});
if (notificationdata)
{
new Notification(notificationdata);
console.warn(notificationdata);
}
},
});
}, Math.random() * 10000 + 20000);
}