-
Notifications
You must be signed in to change notification settings - Fork 8
/
91huayi_auto_class.js
288 lines (288 loc) · 15.4 KB
/
91huayi_auto_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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// ==UserScript==
// @name 91huayi_auto_class(91华医公需课选修课视频考试我全都要)
// @namespace https://github.com/hysbeta/91huayi
// @version 2.6.4
// @description 91huayi_auto_class_
// @author Acdtms4zfx
// @match *://*.91huayi.com/course_ware/*
// @match *://*.91huayi.com/pages/exam.aspx?*
// @match *://*.91huayi.com/pages/exam_result.aspx?*
// @match *://*.91huayi.com/pages/course.aspx?cid=*
// @match *://*.91huayi.com/pages/noplay.aspx?cid=*
// @match *://*.91huayi.com/secure/login.aspx
// @match *://*.91huayi.com/cme/index.html
// @grant none
// @supportURL https://github.com/hysbeta/91huayi
// @license CC BY-NC-ND 2.0 DEED
// @downloadURL https://update.greasyfork.org/scripts/477268/91huayi_auto_class%2891%E5%8D%8E%E5%8C%BB%E5%85%AC%E9%9C%80%E8%AF%BE%E9%80%89%E4%BF%AE%E8%AF%BE%E8%A7%86%E9%A2%91%E8%80%83%E8%AF%95%E6%88%91%E5%85%A8%E9%83%BD%E8%A6%81%29.user.js
// @updateURL https://update.greasyfork.org/scripts/477268/91huayi_auto_class%2891%E5%8D%8E%E5%8C%BB%E5%85%AC%E9%9C%80%E8%AF%BE%E9%80%89%E4%BF%AE%E8%AF%BE%E8%A7%86%E9%A2%91%E8%80%83%E8%AF%95%E6%88%91%E5%85%A8%E9%83%BD%E8%A6%81%29.meta.js
// ==/UserScript==
(function() {
'use strict';
alert = console.log;
var wait_time = 10;
console.log('91huayi_auto_exam_v2');
function getlocalStorage(name) {
if (localStorage.getItem(name) != null) {
return unescape(localStorage.getItem(name));
} else {
return null;
}
};
function setlocalStorage(name, value) {
localStorage.setItem(name, escape(value));
};
function dellocalStorage(name) {
localStorage.removeItem(name);
};
function sleep(time, unit) {
if (time == null) {
time = wait_time * 1000;
}
if (unit != null) {
time = time * 1000;
}
for (var t = Date.now(); Date.now() - t <= time;);
};
sleep();
if (document.querySelector("body").textContent.search("应用程序中的服务器错误。") != -1 && document.querySelector("body").textContent.search("运行时错误") != -1) {
console.log("Now in error page");
setTimeout(function() {
location.reload();
},
wait_time * 1000);
};
if (window.location.href.search(".91huayi.com/course_ware/") != -1) {
console.log("Now in class page");
var fuc = setInterval(function() {
document.querySelector("#video > div > div.pv-video-wrap > video").muted = true; //启用未交互后台播放
document.querySelector("#video > div > div.pv-video-wrap > video").play(); //播放
document.querySelector("#video > div > div.pv-video-wrap > video").volume = 0; //播放器静音
closeBangZhu(); //关闭提示弹窗
if (document.querySelector("#video > div > div.pv-line-tips") != null) {
document.querySelector("#video > div > div.pv-line-tips > a").click();
}; //切换线路
if (document.querySelector("#video > div > div.pv-ask-modal-wrap") != null) {
document.querySelector("#video > div > div.pv-ask-modal-wrap").remove();
}; //清除问题
if (document.querySelector("#video > div > div.sign-in-menu > div") != null) {
document.querySelector("#video > div > div.sign-in-menu > div").remove();
}; //清除签到
if (document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right") != null) {
for (var i = 1; i <= document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right").childElementCount; i++) {
if (document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > button") != null) {
if (document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > button").className.indexOf('pv-icon-volumeon') != -1) {
document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > button").click();
}; //播放按钮静音
if (document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > button").className.indexOf('pv-quality-btn') != -1) {
if (document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > div > div").childElementCount > 1) {
var expect_quality_level = document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > div > div").childElementCount - 1;
if (document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > div > div > div:nth-child(" + expect_quality_level + ")").className.indexOf('pv-active') == -1) {
document.querySelector("#video > div > div.pv-skin-blue.pv-video-bottom.pv-subtitle-hide.pv-base-control > div.pv-controls > div.pv-controls-right > div:nth-child(" + i + ") > div > div > div:nth-child(" + expect_quality_level + ")").click();
};
};
}; //视频质量降低
};
};
};
initialSign(); //调用签到保活(保持播放)
while (document.querySelector("#video > div > div.sign-in-menu > div > div.sign-in-wrap > div.sign-in-wrap_btn > span") != null) {
document.querySelector("#video > div > div.sign-in-menu > div > div.sign-in-wrap > div.sign-in-wrap_btn > span").click();
}; //签到
if (document.querySelector("#video > div > div.pv-video-wrap > div.pv-log-error > div.pv-log-errormsg").textContent != "") {
console.log("Looks like something goes wrong, try refresh the page after 10s...");
setTimeout(function() {
location.reload();
},
wait_time * 1000);
}; //If error
setlocalStorage("lastactionts", Date.parse(new Date()));
if (document.querySelector("#jrks").getAttribute('disabled') == "disabled") {
console.log("Not ready for exam yet...");
} else {
document.querySelector("#jrks").click();
};
},
wait_time * 1000);
};
if (window.location.href.search(".91huayi.com/pages/exam.aspx") != -1) {
console.log("Now in exam page");
if (getlocalStorage("correct_ans") == null) {
var correct_ans = {};
} else {
var correct_ans = JSON.parse(getlocalStorage("correct_ans"));
};
if (getlocalStorage("wrong_ans") == null) {
var wrong_ans = {};
} else {
var wrong_ans = JSON.parse(getlocalStorage("wrong_ans"));
};
console.log("correct_ans:" + JSON.stringify(correct_ans));
console.log("wrong_ans:" + JSON.stringify(wrong_ans));
var i, j, question_text, ans_text;
var sub_ans = {};
for (i = 2; i <= document.querySelector("#gvQuestion > tbody").childElementCount; i++) {
question_text = (document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table.tablestyle > thead > tr > th > span").textContent.substring(document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table.tablestyle > thead > tr > th > span").textContent.indexOf("、") + 1));
console.log("Q:" + question_text) if (correct_ans.hasOwnProperty(question_text)) {
for (j = 1; j <= document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody").childElementCount; j++) {
if (correct_ans[question_text] == document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(" + j + ") > td").textContent) {
document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(" + j + ") > td > input").click();
ans_text = document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(" + j + ") > td").textContent sub_ans[question_text] = ans_text;
console.log("Already have correct answer for this question -> " + ans_text) break;
}
}
} else if (wrong_ans.hasOwnProperty(question_text)) {
for (j = 1; j <= document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody").childElementCount; j++) {
if (wrong_ans[question_text].indexOf(document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(" + j + ") > td").textContent) == -1) {
document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(" + j + ") > td > input").click();
ans_text = document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(" + j + ") > td").textContent sub_ans[question_text] = ans_text;
console.log("Only have wrong answer for this question, try -> " + ans_text) break;
}
}
} else {
document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(1) > td > input").click();
ans_text = document.querySelector("#gvQuestion > tbody > tr:nth-child(" + i + ") > td > table:nth-child(2) > tbody > tr:nth-child(1) > td").textContent sub_ans[question_text] = ans_text;
console.log("First time meet this question, try -> " + ans_text)
}
};
console.log("sub_ans:" + JSON.stringify(sub_ans));
setlocalStorage("sub_ans", JSON.stringify(sub_ans)) setlocalStorage("lastactionts", Date.parse(new Date()));
document.querySelector("#btn_submit").click();
setTimeout(function() {
location.reload();
},
wait_time * 1000);
};
if (window.location.href.search(".91huayi.com/pages/exam_result.aspx") != -1) {
console.log("Now in exam result page");
if (getlocalStorage("sub_ans") == null) {
var sub_ans = {};
} else {
var sub_ans = JSON.parse(getlocalStorage("sub_ans"));
};
if (getlocalStorage("correct_ans") == null) {
var correct_ans = {};
} else {
var correct_ans = JSON.parse(getlocalStorage("correct_ans"));
};
if (getlocalStorage("wrong_ans") == null) {
var wrong_ans = {};
} else {
var wrong_ans = JSON.parse(getlocalStorage("wrong_ans"));
};
var i, j, key, wrong_questions;
wrong_questions = [];
for (i = 1; i <= document.querySelector("#ctl00 > div.container > div > div.cent_box > ul").childElementCount; i++) {
wrong_questions.push(document.querySelector("#ctl00 > div.container > div > div.cent_box > ul > li:nth-child(" + i + ") > p").getAttribute("title"));
};
console.log("wrong_questions:" + JSON.stringify(wrong_questions));
console.log("sub_ans:" + JSON.stringify(sub_ans));
for (key in sub_ans) {
console.log("Q:" + key);
if (wrong_questions.indexOf(key) != -1) {
console.log("Wrong answer -> " + sub_ans[key]);
if (!wrong_ans.hasOwnProperty(key)) {
wrong_ans[key] = [];
};
wrong_ans[key].push(sub_ans[key]);
} else {
correct_ans[key] = sub_ans[key];
console.log("Correct answer -> " + sub_ans[key]);
};
};
console.log("sub_ans:" + JSON.stringify(sub_ans));
console.log("correct_ans:" + JSON.stringify(correct_ans));
console.log("wrong_ans:" + JSON.stringify(wrong_ans));
if (document.querySelector("#ctl00 > div.container > div > div.cent_box > div.state_tips > p").textContent.trim() == "考试通过") {
console.log("Congratulations! Now in exam result @ pass page...");
dellocalStorage("sub_ans");
dellocalStorage("correct_ans");
dellocalStorage("wrong_ans");
var finish_state = true;
for (j = 1; j <= document.querySelector("#ctl00 > div.container > div > div.cent_box > ul").childElementCount; j++) {
if (document.querySelector("#ctl00 > div.container > div > div.cent_box > ul > li:nth-child(" + j + ") > input").value == "立即学习") {
var finish_state = false;
console.log("We will move to next class ...");
console.log("Next:" + document.querySelector("#ctl00 > div.container > div > div.cent_box > ul > li:nth-child(" + j + ") > p").title);
setlocalStorage("lastactionts", Date.parse(new Date()));
document.querySelector("#ctl00 > div.container > div > div.cent_box > ul > li:nth-child(" + j + ") > input").click();
break;
};
};
sleep();
setlocalStorage("lastactionts", Date.parse(new Date()));
if (finish_state == false) {
console.log("Now in finished page, no class to learn but finish_state is false, will reload the page to see what happen...");
} else {
console.log("Congratulations! It's all done~");
window.close();
dellocalStorage("classURL");
};
setTimeout(function() {
setlocalStorage("lastactionts", Date.parse(new Date()));
},
wait_time * 1000);
} else {
console.log("Sad... Now in exam result @ fail page...will take the exam again in " + wait_time + "s...");
dellocalStorage("sub_ans");
setlocalStorage("correct_ans", JSON.stringify(correct_ans));
setlocalStorage("wrong_ans", JSON.stringify(wrong_ans));
setlocalStorage("lastactionts", Date.parse(new Date()));
document.querySelector("#ctl00 > div.container > div > div.cent_box > div.state_foot > input:nth-child(2)").click();
};
};
if (window.location.href.search(".91huayi.com/pages/course.aspx") != -1) {
console.log("Now in course list");
setlocalStorage("classURL", window.location.href);
if (getlocalStorage("lastactionts") == null) {
console.log("Class not started yet or last action ts misssing. Do nothing now...");
setTimeout(function() {
location.reload();
},
wait_time * 1000 * 2);
} else {
setInterval(function() {
if (Date.parse(new Date()) - getlocalStorage("lastactionts") < wait_time * 1000 * 3) {
console.log("Having class now...");
//setTimeout(function(){location.reload();},wait_time * 1000 * 3);
} else {
console.log("Seems like got exception, try to take class again...");
var i;
for (i = 3; i <= document.querySelector("#containter > div.main > div.colm_mid").childElementCount; i++) {
if (document.querySelector("#containter > div.main > div.colm_mid > div:nth-child(" + i + ")").getAttribute("class") == "course") {
if (document.querySelector("#containter > div.main > div.colm_mid > div:nth-child(" + i + ") > h3 > span") == null || document.querySelector("#containter > div.main > div.colm_mid > div:nth-child(" + i + ") > h3 > span").textContent != "学习完毕") {
document.querySelector("#containter > div.main > div.colm_mid > div:nth-child(" + i + ") > h3 > a").click();
break
};
};
dellocalStorage("classURL");
if (Date.parse(new Date()) - getlocalStorage("lastactionts") < wait_time * 1000 * 60) {
dellocalStorage("lastactionts");
};
};
console.log("Will refresh the page in 30s...");
setTimeout(function() {
location.reload();
},
wait_time * 1000 * 3);
};
},
wait_time * 1000);
};
};
if (window.location.href.search(".91huayi.com/pages/noplay.aspx") != -1) {
console.log("Now in noplay page");
window.close();
};
if (window.location.href.search(".91huayi.com/secure/login.aspx") != -1) {
console.log("Now in login page");
setTimeout(function() {
location.reload();
},
wait_time * 1000 * 3);
};
if (window.location.href.search(".91huayi.com/cme/index.html") != -1 && getlocalStorage("classURL") != null) {
console.log("Now in landing page");
window.location.href = getlocalStorage("classURL");
};
})();