avatar

目录
小爱课程表适配教务网

如果你有小米手机(绝对不是广告)

怎么说,MIUI很对我胃口,特别是现在的小爱同学,贼香。

大学里面最烦人的是什么?我想个人来说查课表绝对排进前十。特别是教务网不是好用。因此,前段时间有机会加入到小米的小爱同学课程表开发者群 虽然我经常划水🤣 ,特地来将代码记录一下。

主要方法是正则表达式,利用小米提供的API即可使用。

这里我学校的教务系统是强智的,路径为http://教务网域名/jsxsd/framework/xsMain.jsp

整体界面如下所示:

就可以使用以下代码放入开发者工具,详情可以去看看官方文档

废话少说,上代码ing.

Javascript
1
2
3
4
5
6
7
8
9
function scheduleHtmlProvider(iframeContent = "", frameContent = "", dom = document) {
var request = new XMLHttpRequest();
request.open('GET', '/jsxsd/xskb/xskb_list.do', false);
request.send(null);
if (request.status === 200) { //没有的话不然会提示宽度不够🤐
return request.responseText.replace(/[\r\n]/g,"");
}

}
Javascript
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
function scheduleHtmlParser(html) {
//除函数名外都可编辑
//传入的参数为上一步函数获取到的html
//可使用正则匹配
//可使用解析dom匹配,工具内置了$,跟jquery使用方法一样,直接用就可以了,参考:https://juejin.im/post/5ea131f76fb9a03c8122d6b9
//以下为示例,您可以完全重写或在此基础上更改、
console.info(html);
let result = [];
let resultT = [];
//上课时间
const regexT = /<th width="70" height="28" align="center">.*?第.*?节&nbsp;<br\/>(.*?)-(.*?) .*?<\/th>/gm;
let timeFlag = 0;
while ((t = regexT.exec(html)) !== null) {
if (t.index === regexT.lastIndex) {
regexT.lastIndex++;
}
let reT = {}
t.forEach((matchT, groupIndexT) => {
console.log("matchT: "+matchT)
switch(groupIndexT){
case 1:
reT.section = ++timeFlag;
reT.startTime = matchT;
let hour1 = parseInt(matchT.split(':')[0]);
let minute1 = parseInt(matchT.split(':')[1]);
if( (minute1+45)>=60 ){
minute1 = minute1+45-60;
hour1++;
}else{
minute1 += 45;
}
reT.endTime = ((hour1<10)?"0":"")+hour1+":"+minute1;
resultT.push(reT);
reT = {}
console.log(timeFlag+"1")
break;
case 2:
reT.section = ++timeFlag;
reT.endTime = matchT;
let hour2 = parseInt(matchT.split(':')[0]);
let minute2 = parseInt(matchT.split(':')[1]);
if( (minute2-45)<0 ){
minute2 = minute2-45+60;
hour2--;
}else{
minute2 -= 45;
}
reT.startTime = ((hour2<10)?"0":"")+hour2+":"+minute2;
resultT.push(reT);
reT = {}
console.log(timeFlag+"2")
break;
}
});
}

//课程
const regex = /kbcontent1.*?<div id=".*?-(.*?)-2".*?style="display: none;" class="kbcontent".*?>(.*?)<\/div>/gm;
var log;
while ((m = regex.exec(html)) !== null) {
log = "";
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}

var weekDay;
m.forEach((match, groupIndex) => {

switch(groupIndex){
case 1:
weekDay = parseInt(match)
break;
case 2:
//log += ("\n内容:"+match);
const regexS = /(.*?)<br\/><font title='老师'>(.*?)<\/font><br\/><font title='周次\(节次\)'>(.*?)\(周\)\[(.*?)节\]<\/font><br\/>.*?<font title='教室'>(.*?)<\/font><br\/><font name='xsks' color='black' style='display:none;'>.*?<br\/><\/font>/gm;;
while ((mm = regexS.exec(match)) !== null) {
if (mm.index === regexS.lastIndex) {
regex.lastIndex++;
}

let re = { sections: [], weeks: [] }
mm.forEach((matchS, groupIndexS) => {
switch(groupIndexS){
case 1:
console.info("星期"+weekDay)
re.day = weekDay;
matchS = matchS.replace("---------------------<br>","")
matchS = matchS.replace("<br/>","")
console.info(" 课程名:"+matchS+"\n");
re.name = matchS;
break;
case 2:
console.info(" 老师:"+matchS+"\n");
re.teacher = matchS;
break;
case 3:
console.info(" 周次:"+matchS+"\n");
var weekRange = matchS.split(","); //处理逗号分周
for(var weekTemp = 0; weekTemp < weekRange.length; weekTemp++){
if(weekRange[weekTemp].search('-') != -1){ //如果不止一周
let begin = weekRange[weekTemp].split('-')[0];
let end = weekRange[weekTemp].split('-')[1];
for(let iii = parseInt(begin); iii <= parseInt(end); iii++){
re.weeks.push(iii);
}
}else{ //只有一周
re.weeks.push(parseInt(weekRange[weekTemp]))
}
}
break;
case 4:
console.info(" 节次:"+matchS+"\n");
if(matchS.search('-') != -1){ //如果不止一节
let begin2 = matchS.split('-')[0];
let end2 = matchS.split('-')[1];
for(let iii2 = parseInt(begin2);iii2<=parseInt(end2);iii2++){
let ree = {}
ree.section = iii2;
re.sections.push(ree);
}
}else{ //只有一节
let ree2 = {}
ree2.section = parseInt(matchS);
re.sections.push(ree2)
}
break;
case 5:
console.info(" 教室:"+matchS+"\n");
re.position = matchS;
break;
}
});
result.push(re);
}
//console.log(log);
break;
}
});
}


console.info(resultT)
console.info(result)
return { courseInfos: result, sectionTimes: resultT}
}
赏饭钱
  • wechat
    wechat
  • alipay
    alipay

评论