-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_select_class.js
135 lines (130 loc) · 5.18 KB
/
auto_select_class.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
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
var as_goal_ts = 1614866400000;
//默认值为 2021.03.04 22:00:00
function auto_select(is_v2){
var as_ts,as_left;
as_ts = (new Date()).valueOf();
as_left = as_goal_ts - as_ts;
console.log(as_left);
console.log(as_left - 10000);
if (as_left <= 10000) {
decete(as_goal_ts,is_v2);
} else {
setTimeout("decete("+as_goal_ts+","+is_v2+")",as_left - 10000);
}
}
function decete(as_goal_ts,is_v2){
var as_ts,as_send;
as_send = false;
while(!as_send){
as_ts = (new Date()).valueOf();
if ( as_ts >= as_goal_ts ){
if(is_v2){
var s1=$('#as_s1').val(),s2=$('#as_s2').val();
if (!s1 == s2){
Ajax('single_submit',s1);
console.log("single_submit_s1");
}
Ajax('single_submit',s2);
console.log("single_submit_s2");
} else {
Ajax('submit');
console.log("submit");
}
console.log("Request send succeed!");
console.log("Send as "+as_ts);
as_send = true;
mui.toast("抢课请求发送成功,将在5秒后打开新页面以供锁定,锁定前请勿关闭本页面以便提交报错信息");
setTimeout("window.open('http://szxk.fjyun.net/szxk/detail2.html')","5000");
}
}
}
function main(){
console.log('初始化脚本中...');
if (document.URL != 'http://szxk.fjyun.net/szxk/detail2.html') {
alert("请在正确界面使用本脚本");
setTimeout("location.replace('http://szxk.fjyun.net/szxk/detail2.html')",3000);
return;
}
if ((new Date()).valueOf() > as_goal_ts) {
alert("时间戳设置错误!请修改后再试!");
return;
}
mui.toast('初始化脚本中...');
var total_c = parseInt($('.elective select').find('option:selected').attr('obj-credit'));
var realname = $('.do-real-name').html().split(' ');
if(!confirm(realname[1]+" "+realname[0]+"\n欢迎使用自动抢课脚本\n\n脚本不保证抢课成功,详细原因可见readme.md\n请勿滥用并承诺自愿承担一切后果!\nPowered By Hao_cen\nLast Update: 2021.03.04")){
return;
}
var c1=0,c2,as_credit,is_v2 = false,name = new Array(),uid = new Array();
$("tr").each(function(){
if($(this).attr('obj-id') != undefined){
c2=0;
uid[c1] = $(this).attr('obj-id');
$(this).children().toArray().forEach(element => {
c2 = c2 + 1;
if (c2 == 1){
name[c1] = element.innerHTML;
console.log(name[c1]);
}
if (c2 == 2){
as_credit = parseInt(element.innerHTML);
console.log(as_credit);
}
});
if (as_credit < total_c && is_v2 == false) {
is_v2 = true;
console.log('set v2 = true');
}
c1 = c1 + 1;
}
});
if (is_v2){
mui.toast("检测到双选选课系统\n请在修改后的网页上选课提交\n等待期间网页缓慢或未响应为正常现象");
console.log("found v2");
var div = '<div id="as_div" style="display: block;position:fixed;z-index:9999;background-color:#66ccff;text-align:center;font-color:black;"><p style="font-size:x-large;">选择课程时请注意课程备注!<br>不支持抢2节相同课程!<br>如有需要请点击切换按钮!</p><br><p>课程一</p><select id="as_s1">' ;
var selector = "";
for (let i = 0; i < name.length; i++) {
selector = selector + "<option value="+uid[i]+">"+name[i]+"</option>";
}
selector = selector + "</select>";
div =div +selector + '<br><p>课程二</p><select id="as_s2">' + selector+ '<br><button id="as_submit">提交</button><button id="as_switch">切换至单选模式</button></div>';
$("body").append(div);
$("table").hide();
$("#as_switch").click(function(){
$("#as_div").hide();
$("table").show();
$(".foot").off("click",".do-submit");
console.log("switch to v1");
mui.toast("已切换至单选选课\n如误操作请刷新页面并重新激活脚本\n请选定要抢的课程然后按下确认选课按钮\n脚本将自动接管选课逻辑\n等待期间网页缓慢或未响应为正常现象");
$('.do-submit').click(function(){
mui.toast("已确认请求,正在等待选课系统开放");
console.log("已确认请求,正在等待选课系统开放");
auto_select(false);
});
});
$("#as_submit").click(function(){
$(this).attr('disabled',true);
$('#as_switch').attr('disabled',true);
mui.toast("已确认请求,正在等待选课系统开放");
console.log("已确认请求,正在等待选课系统开放");
if($('#as_s1').val() == $('#as_s2').val()){
if(!confirm("课程选择相同,是否为误操作?\n按确认键继续操作")){
$(this).attr('disabled',false);
$('#as_switch').attr('disabled',false);
return;
}
}
auto_select(true);
});
} else {
$(".foot").off("click",".do-submit");
console.log("found v1");
mui.toast("检测到单选选课系统\n请选定要抢的课程然后按下确认选课按钮\n脚本将自动接管选课逻辑\n等待期间网页缓慢或未响应为正常现象");
$('.do-submit').click(function(){
mui.toast("已确认请求,正在等待选课系统开放");
console.log("已确认请求,正在等待选课系统开放");
auto_select(false);
});
}
}
setTimeout("main()",3000);