-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
391 lines (343 loc) · 21.6 KB
/
helper.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
// ==UserScript==
// @name UCAS SEP Helper
// @namespace https://github.com/ngc7331/UCAS-SEP-Helper
// @version 1.2.0
// @description useful tool for UCAS SEP
// @author xu_zh
// @match https://course.ucas.ac.cn/*
// @match https://bkkcpj.ucas.ac.cn/*
// @match https://xkcts.ucas.ac.cn:8443/evaluate/evaluateCourse/*
// @match https://xkcts.ucas.ac.cn:8443/evaluate/evaluateTeacher/*
// @match https://jwxk.ucas.ac.cn/evaluate/evaluateCourse/*
// @match https://jwxk.ucas.ac.cn/evaluate/evaluateTeacher/*
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAACxMAAAsTAQCanBgAABRRSURBVGhD3VoJVFVXlj18kUlmQWZEQEHmWRwCzjFqjCY4tCkzGq1KTDRzJTW0K53YlRiNlcRUFVGSmDjPc4xzjCGAIiKKoCIIMs8zyFB7X/7/DYh2yl6re63ea33+f/+9d98995yzzz73I/9fYKB9/x/DB4gGRowYET0UcAUGAoYAz98BKoB84CqQlJT0C15JNwA1wP8l/IH33nvvP04BnQ+II0eO/PAnwBvQDvtAeCCPxABLgNmA9ivJLqiRjJxKyS+tl+Y77fAAXm2d0tbeIRpN12NMjPqJYT8DGWDSX9wGmUugp614Oluqc8SmTZs2r1mz5pMUQPvVr8a/ZIgL8NFHH62cP3/+v/G4vLpZjp0vkJtFddLc2iY19a1yu7xB8krqpaKmWRqa28TW0liKKhplgGl/MemvETtrU/FwMBdnuwFiNcBIGeflYikTI1zF2txYPecbYClQA6gvfgV+tSFPA6tWrVqNsLetrm+RHadypKSyUarqWiU5s1TSrldIHSYvHR0i/TR475QQfwcZZGMqkyNd5URqoRw6fk3ECCkDL/EaG2sTCRtmJ+E+9mIJI1xh3OxxXmJmYih5eXm3li1btnQPoJ3CffGrDNmwYcO3CxYs+A0/7z1zU9JzqqSytkkOJd6S7JuV6hrByhoYdA3XiYnaWpnI6/NCpL6pVRZO95NPd6TLXzekigG8oEMnjBWEIG4U/6F2MiXKVWxgUOTwQTI5yk1ds379+oSFCxc+rw7ug37a9z7RH9i/f/+BuLi4J+oaW+XznRmShxw4nXpbtp24IeUIGQNjQzEw1OiN0IGOeXTMYIROf6nHvcdxz/X8GnWtDrxHHcM7ZQjP7MJa6UQ+tbS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H+xnHqXL4446FMThJDKla8P3qIOtB3A2qAC0KUdae5pV1puekjB6MvN1dK+d+/Oi9ZCKNAJPIlhKcFwvBF9DIWWIRFM4arCr5nz569s2bNmqmd3l24pyEEjaFnSJfcz/1y3xWpb2mTgz/lSjIo0tXFUiU7e4bzCJN3oARIv6HedsoLXRsE7er3c9IlWe2bI9lSDq+QgagUBoIomC+XtPXnISQ764YVZNJi0K8xjOKGx5w5c/T/nNAXeiR7b3QAmwAvLy/vyIjQoJEIA4aIDRIvGIl/DYn787nbUohQs4OEIOM6QnRS2DEp2UswVKZGu0vy1TIVWtzkyELYtGINS3HfJhhWihzj5vRzEIX+0HDcZZk/aajqWPnztO6n8fvhvh7pDgy2YPXq1Z/Y2dkNVP8wcDIHwq5RKrGqiejbmbyNmCj7DjOsIv8BgLsgpFZKdkMYVgDyaAdzVUEJE+YwOmq4vUT6DhJL5Iwr8oqb1azapNjXXnvt1e4/5twPv9oQglv4K1eu/Lj3v3Awhxj7lTCQwi4HxxU4V4+GjHsMzAnSNmOefQl/pWU3amVhpNSsl7OV+hcOSiGCxe5loHud+O/wLxmiQ5//VIMwu5xbib4DPQTyiDWDG9C6+s5EN0Ko9INB5lhxdwcL1QqwodOBv3rxn2p0PdL/GvyA5cCxY8eOY9UfCIcPH/7+DwDy0Es77ANA5J/RfEd2oiSaUAAAAABJRU5ErkJggg==
// @grant none
// @downloadURL https://raw.githubusercontent.com/ngc7331/UCAS-SEP-Helper/main/helper.js
// @updateURL https://raw.githubusercontent.com/ngc7331/UCAS-SEP-Helper/main/helper.js
// @supportURL https://github.com/ngc7331/UCAS-SEP-Helper/issues
// ==/UserScript==
(function() {
'use strict';
/* --- utils --- */
class Scheduler {
constructor() {
this._lim = 5;
this.queue = [];
this.working = [];
this._display = null;
}
addTask(task) {
return new Promise((resolve) => {
task.resolve = resolve;
if (this.working.length < this._lim) {
this.runTask(task);
} else {
this.queue.push(task);
}
this.updateDisplay();
});
}
runTask(task) {
this.working.push(task);
task().then(() => {
task.resolve();
var idx = this.working.indexOf(task);
this.working.splice(idx, 1);
if (this.queue.length > 0) {
this.runTask(this.queue.shift());
}
this.updateDisplay();
});
}
setDisplay(elem) {
this._display = elem;
}
updateDisplay() {
if (this._display === null) {
return ;
}
this._display.innerHTML = `运行/排队: ${this.working.length}/${this.queue.length}`;
}
}
function register(func, hostname) {
if (!hostname.includes(window.location.hostname)) {
return ;
}
console.log(`Registered ${func.name} for ${window.location.hostname}`)
func();
}
/* --- module --- */
function resourceBulkDownload() {
console.warn("course.ucas.ac.cn is deprecated");
function worker(mode){
// mode = 0: download all
// mode = 1: download selected
function download(url, filename) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "blob";
xhr.onload = function() {
if (xhr.status === 200) {
var content = xhr.response;
var a = document.createElement("a");
var blob = new Blob([content]);
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
console.log(`Downloaded ${filename}`);
resolve();
} else {
reject(new Error(xhr.statusText));
}
};
xhr.onerror = function() {
reject(new Error(xhr.statusText));
};
console.log(`Downloading ${filename} from ${url}`);
xhr.send();
});
}
function getA(tr) {
return tr.querySelector("td:nth-child(3) > a:nth-child(2)");
}
function getCheckBox(tr) {
return tr.querySelector("td:nth-child(2) > input");
}
var sched = new Scheduler();
sched.setDisplay(display);
const addTask = (href, name, i, tot) => {
sched.addTask(() => download(href, name))
.then(() => console.log(`Done ${i+1}/${tot}`));
}
var trs = document.querySelectorAll("#showForm > table > tbody > tr");
// filter out folders
trs = Array.prototype.filter.call(trs, function(elem) {
var a = getA(elem);
return a !== null && a.href !== undefined && !a.href.endsWith("#");
});
// filter out unchecked
if (mode == 1) {
trs = Array.prototype.filter.call(trs, function(elem) {
var box = getCheckBox(elem);
return box.checked;
});
}
console.log(trs);
// download
for (var i = 0; i < trs.length; i++) {
var a = getA(trs[i]);
var href = a.href;
var name = a.children[1].innerHTML;
console.log(`Add task (${i+1}/${trs.length})`);
addTask(href, name, i, trs.length);
}
}
function downloadAllBtnListener(event) {
event.preventDefault();
worker(0);
}
function downloadSelBtnListener(event) {
event.preventDefault();
worker(1);
}
var curr_page = document.querySelector("#toolMenu > ul > li.is-current > a");
var cpy_btn = document.getElementById("copy-button");
if (cpy_btn === null || curr_page.title !== "资源") {
return ;
}
// create buttons
var dl_sel_btn = document.createElement("button");
dl_sel_btn.style = "margin:0";
dl_sel_btn.className = "btn";
dl_sel_btn.innerHTML = "下载已选";
dl_sel_btn.addEventListener("click", downloadSelBtnListener);
var dl_all_btn = document.createElement("button");
dl_all_btn.style = "margin:0";
dl_all_btn.className = "btn";
dl_all_btn.innerHTML = "下载全部";
dl_all_btn.addEventListener("click", downloadAllBtnListener);
var display = document.createElement("span");
display.style = "padding: 5px 10px; display:block; float:left;";
// insert buttons on page
cpy_btn.parentNode.appendChild(dl_sel_btn);
cpy_btn.parentNode.appendChild(dl_all_btn);
cpy_btn.parentNode.appendChild(display);
}
function keepMeAlive() {
console.warn("course.ucas.ac.cn is deprecated");
function worker() {
var alert = document.querySelector("#timeout_alert_body");
if (alert === null) {
return ;
}
console.log("Keep alive...");
var btn = alert.querySelector("input[type=button]");
btn.click();
}
function enableBtnListener(event) {
if (enable_btn.checked) {
console.log("Keep alive enabled");
worker_id = window.setInterval(worker, interval);
} else {
console.log("Keep alive disabled");
window.clearInterval(worker_id);
}
}
// create setting
var enable_btn = document.createElement("input");
enable_btn.type = "checkbox";
enable_btn.checked = true;
enable_btn.style = "margin: 0 5px;";
enable_btn.addEventListener("change", enableBtnListener);
var enable_hint = document.createElement("a");
enable_hint.innerHTML = "保持在线";
enable_hint.href = "#";
enable_hint.appendChild(enable_btn);
var enable_li = document.createElement("li");
enable_li.className = "Mrphs-userNav__submenuitem Mrphs-userNav__submenuitem-indented";
enable_li.appendChild(enable_hint);
// insert setting on page
var menu = document.querySelector("#loginLinks > li.Mrphs-userNav__popup.js-toggle-user-nav > ul");
if (menu === null) {
return ;
}
menu.appendChild(enable_li);
// check every 5 min
const interval = 5 * 60 * 1000;
var worker_id = window.setInterval(worker, interval);
}
function coursePoll_undergraduate() {
function worker(do_submit) {
function fill(card) {
var input = card.querySelector("div > div:nth-child(3) > div > table > tr > td:nth-child(1) > div > div > div.el-checkbox-group > div:nth-child(1) > label");
if (input !== null) {
// 多选题
input.click();
return ;
}
input = card.querySelector("div > div:nth-child(3) > div > table > tr > td > div > div > div.el-radio-group > div:nth-child(1) > label");
if (input !== null) {
// 单选题
input.click();
return ;
}
input = card.querySelector("div > div:nth-child(3) > div > div > div > div > label:nth-child(1)");
if (input !== null) {
// 数字单选题
input.click();
return ;
}
input = card.querySelector("div > div:nth-child(3) > div > div > div > textarea");
if (input !== null) {
// 问答题
input.value = "好好好好好好好好好好好好好好好好好好好好";
return ;
}
console.log(card);
alert("填充失败:未知题型");
}
for (var i = 1; i < cards.length - 1; i++) {
fill(cards[i]);
}
if (do_submit) {
submit.click();
}
}
function pollBtnListener(event) {
event.preventDefault();
worker(0);
}
function pollAndSubmitBtnListener(event) {
event.preventDefault();
worker(1);
}
var cards;
var submit;
window.setTimeout(() => {
cards = document.querySelectorAll("#app > div > form > div");
if (cards.length < 3) {
return ;
}
var headers = cards[0]
submit = cards[cards.length - 1].querySelector("div > button");
var poll_btn = document.createElement("button");
poll_btn.innerHTML = "填充";
poll_btn.addEventListener("click", pollBtnListener);
var poll_submit_btn = document.createElement("button");
poll_submit_btn.innerHTML = "填充并提交";
poll_submit_btn.addEventListener("click", pollAndSubmitBtnListener);
var span = document.createElement("span");
span.style = "margin-left: 20px;";
span.appendChild(poll_btn);
span.appendChild(poll_submit_btn);
headers.querySelector("div > div > div:nth-child(2)").appendChild(span);
}, 1000);
}
function coursePoll() {
function singleSelectBtnListener(event) {
var level = parseInt(event.target.getAttribute("data-level"));
console.log(`Single select level: ${level}`);
var trs = single_select_form.querySelectorAll("tbody > tr");
for (var i = 0; i < trs.length; i++) {
var options = trs[i].querySelectorAll("td > input");
if (options.length === 0 || level >= options.length) {
console.warn("No options found at row#", i, ", skip...");
continue;
}
options[level].click();
}
}
function textFillBtnListener(event) {
const default_text = {
1355: "好好好好好好好好好好好好好好好",
1356: "非常好课程,我没有进一步的建议",
1357: `平均每周在这门课程上花费${Math.floor(Math.random()*30)}小时`,
1358: "感兴趣感兴趣感兴趣感兴趣感兴趣",
1359: "出全勤出全勤出全勤出全勤出全勤",
1403: "好好好好好好好好好好好好好好好",
1404: "非常好老师,我没有进一步的建议",
}
text_fill_btn.value = "Disclaimer: 课程评估的目的是帮助学校更好的改进课程,造福未来的学弟学妹。在时间精力允许的情况下,还请自行完成!";
for (var key in default_text) {
var input = document.querySelector(`textarea#item_${key}`);
if (input === null) {
console.warn(`Textarea not found: item_${key}`);
continue;
}
input.value = default_text[key];
}
}
var single_select_form = document.querySelector("#regfrm > table");
var single_select_ths = single_select_form.querySelectorAll("thead > tr > th");
for (var i = 2; i < single_select_ths.length; i++) {
var btn = document.createElement("input");
btn.type = "button";
btn.value = "全选";
btn.setAttribute("data-level", i - 2);
btn.addEventListener("click", singleSelectBtnListener);
single_select_ths[i].appendChild(btn);
}
var text_fill_btn = document.createElement("input");
text_fill_btn.type = "button";
text_fill_btn.value = "填充默认文本";
text_fill_btn.addEventListener("click", textFillBtnListener);
single_select_form.parentNode.insertBefore(text_fill_btn, single_select_form.nextElementSibling);
}
function fixCORS() {
var submit_btn = document.querySelector("#main-content > div > div.m-cbox.m-lgray > div.mc-body > div.form-actions > button") // evaluateCourse
|| document.querySelector("#main-content > div > div.m-cbox.m-lgray > div.mc-body > button"); // evaluateTeacher
submit_btn.addEventListener("click", () => {
var form = document.querySelector("#main-content > div > div.m-cbox.m-lgray > div.mc-body > form");
form.submit();
})
}
/* --- register --- */
register(resourceBulkDownload, ["course.ucas.ac.cn"]); // NOTE: deprecated
register(keepMeAlive, ["course.ucas.ac.cn"]); // NOTE: deprecated
register(coursePoll_undergraduate, ["bkkcpj.ucas.ac.cn"]); // NOTE: deprecated
register(coursePoll, ["xkcts.ucas.ac.cn", "jwxk.ucas.ac.cn"]);
register(fixCORS, ["xkcts.ucas.ac.cn", "jwxk.ucas.ac.cn"]);
})();