This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
AutoEval.js
146 lines (120 loc) · 4.47 KB
/
AutoEval.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
// ==UserScript==
// @name 中大自动评教
// @name:en SYSU Auto Evaluation
// @name:zh 中大自动评教
// @name:zh-CN 中大自动评教
// @namespace https://github.com/KumaTea
// @namespace https://greasyfork.org/en/users/169784-kumatea
// @version 0.2.1.0
// @description 中山大学教务系统学生自动评教脚本
// @description:en Automatic Script for Student Evaluation from Academic Affairs System of Sun Yat-sen University
// @description:zh 中山大学教务系统学生自动评教脚本
// @description:zh-cn 中山大学教务系统学生自动评教脚本
// @author KumaTea
// @match https://jwxt.sysu.edu.cn/jwxt/mk/evaluation/
// @require https://unpkg.com/sweetalert@2.1.2/dist/sweetalert.min.js
// @license MIT
// ==/UserScript==
/* jshint esversion: 8 */
let item = 0; // Evaluation block index
let delay = 2000; // 延迟2秒,过短易出错
let times; // 获取新项目频次
let finish; // Finishing alert
let repeat; // 总评教次数
let good_rate = 1; // 评优率,默认100%,请设置于[0,1]区间
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function react_input(component, value) {
// Credit: https://github.com/facebook/react/issues/11488#issuecomment-347775628
let last_value = component.value;
component.value = value;
let event = new Event('input', {bubbles: true});
// React 15
event.simulated = true;
// React 16
let tracker = component._valueTracker;
if (tracker) {
tracker.setValue(last_value);
}
component.dispatchEvent(event);
}
async function autoEval() {
for (repeat = 0; repeat < 5; repeat++) {
for (times = 0; times < 10; times++) {
await sleep(delay);
if (document.querySelector('.stu-eva-con').querySelectorAll('.sys-card')[item])
// Select an evaluation block
{
document.querySelector('.stu-eva-con').querySelectorAll('.sys-card')[item].querySelector('button').click();
}
// Click the start button
else {
break;
}
// No available evaluation block, exit the function
await sleep(delay);
let table_rows = document.querySelectorAll('.ant-table-wrapper')[1].querySelector('.ant-table-tbody').querySelectorAll('.ant-table-row');
for (let i = 0; i < table_rows.length; i++) {
let table_column = table_rows[i].querySelectorAll('td');
react_input(table_rows[i].querySelector('input.ant-input'),
Math.round(good_rate * parseInt(table_column[table_column.length - 2].textContent)));
}
// Click all option refer to good evaluating rate
await sleep(delay);
document.querySelector('.ant-modal-footer').querySelector('.ant-btn-primary').click();
// Click submit button
await sleep(delay);
let captcha = true;
let block_img;
try {
block_img = document.querySelector('.ant-modal-body').querySelectorAll('img');
} catch (e) {
block_img = [];
captcha = false;
}
while (captcha) {
if (block_img.length > 0) {
if (block_img[block_img.length - 1].alt === "验证码") {
sweetAlert("请手动输入验证码,然后稍作等待。", {buttons: false, timer: 3000,});
} else {
captcha = false;
break;
}
} else {
captcha = false;
break;
}
await sleep(delay * 5);
try {
document.querySelector('.ant-modal-footer').querySelector('.ant-btn-primary').click();
// Submit again
} catch (e) {
void (0);
// Do nothing: user have clicked
}
await sleep(delay);
try {
block_img = document.querySelector('.ant-modal-body').querySelectorAll('img');
} catch (e) {
block_img = [];
captcha = false;
}
}
// Detect if manually input captcha is needed
if (document.querySelector('.ant-modal-close') != null) {
document.querySelector('.ant-modal-close').click();
item++;
}
// Count if evaluation failed
}
document.querySelector('.stu-eva-con').querySelector('.stu-eva-more').querySelector('i').click();
// Click get more
}
if (item > 0) {
finish = "评教完成。\n共" + item + "次无法评价。";
} else {
finish = "评教已顺利完成。";
}
}
autoEval().then(r => {sweetAlert(finish);});