-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathityxb.js
375 lines (362 loc) · 16 KB
/
ityxb.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
// ==UserScript==
// @name 传智播客刷课自动答题脚本
// @icon http://stu.ityxb.com/favicon.ico
// @namespace https://noahcode.cn
// @version 0.0.2
// @description 第一次写tampermonkey脚本,功能有待叠加,相关问题请联系我QQ:70082586,若是无法自动答题,很大几率是因为题库没有,题库数据很少还需要前人先做一遍然后自动录入到题库中
// @author NoahCode
// @match *://stu.ityxb.com/*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
(function () {
'use strict';
//设置修改后,需要刷新或重新打开网课页面才会生效
var config = {
commit_jianda : false //简单题是否使用题库数据(题库数据有可能会有问题)
}
var url = location.pathname;
var errorInfo = '请联系作者QQ:70082586,告知您的详细操作与报错'
var api = 'http://129.211.93.251:2955/'
if (url.match('/preview/detail/')) {
var previewId = url.replace(/\/preview\/detail\//i, '')
var previewT = createPreviewT()
GM_xmlhttpRequest({
method: 'GET',
url: 'http://stu.ityxb.com/back/bxg/preview/info?previewId=' + previewId + '&t=' + previewT,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
var chapters = jsonObj['resultObject']['chapters'];
var chapterNum = chapters.length;
var t = createPreviewT()
for (var i = 0; i < chapterNum; i++) {
var points = chapters[i]['points']
var pointNum = points.length
for (var j = 0; j < pointNum; j++) {
var pointId = points[j]['point_id']
var videoDuration = points[j]['video_duration']
var isHaveQuestion = points[j]['is_have_question']
fuckInfo(previewId, pointId, videoDuration)
if (isHaveQuestion == true) {
dealProblems(previewId, pointId, t)
}
}
}
} else {
console.log(errorInfo)
}
}
})
}
else if (url.match('/lookPaper/busywork/')) {
var re = /\/lookPaper\/busywork\/(.*?)\/[0-9]/i
var lookPaperId = re.exec(url)[1]
var lookPaperT = createLookPaperT()
GM_xmlhttpRequest({
method: 'GET',
url: 'http://stu.ityxb.com/back/bxg/my/busywork/findStudentBusywork?busyworkId=' + lookPaperId + '&t=' + lookPaperT,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
var danxuanInfo = jsonObj['resultObject']['danxuan']
var danxuans = danxuanInfo['lists']
var danxuanNum = danxuanInfo['qNum']
if (danxuanInfo['studentTotalScore'] != 0) {
dealChooseQeustion('lookPaper', lookPaperId, '单选题', danxuans, danxuanNum)
}
var duoxuanInfo = jsonObj['resultObject']['duoxuan']
var duoxuans = duoxuanInfo['lists']
var duoxuanNum = duoxuanInfo['qNum']
if (duoxuanInfo['studentTotalScore'] != 0) {
dealChooseQeustion('lookPaper', lookPaperId, '多选题', duoxuans, duoxuanNum)
}
var panduanInfo = jsonObj['resultObject']['panduan']
var panduans = panduanInfo['lists']
var panduanNum = panduanInfo['qNum']
if (panduanInfo['studentTotalScore'] != 0) {
dealJudgeFillQeustion('lookPaper', lookPaperId, '判断题', panduans, panduanNum)
}
var tiankongInfo = jsonObj['resultObject']['tiankong']
var tiankongs = tiankongInfo['lists']
var tiankongNum = tiankongInfo['qNum']
dealJudgeFillQeustion('lookPaper', lookPaperId, '填空题', tiankongs, tiankongNum)
var jiandaInfo = jsonObj['resultObject']['jianda']
var jiandas = jiandaInfo['lists']
var jiandaNum = jiandaInfo['qNum']
dealJudgeFillQeustion('lookPaper', lookPaperId, '简答题', jiandas, jiandaNum)
} else {
console.log(errorInfo)
}
}
})
}
else if (url.match('/writePaper/busywork/')) {
var reWritePaper = /\/writePaper\/busywork\/(.*?)courseId/i
var writePaperId = url.replace(reWritePaper, '')
.replace(/\/writePaper\/busywork\//i, '')
GM_xmlhttpRequest({
method: 'POST',
url: 'http://stu.ityxb.com/back/bxg/my/busywork/startBusywork',
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
data: 'busyworkId=' + writePaperId,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
var danxuanInfo = jsonObj['resultObject']['danxuan']
var danxuans = danxuanInfo['lists']
var danxuanNum = danxuanInfo['qNum']
dealChooseQeustion('writePaper', writePaperId, '单选题', danxuans, danxuanNum)
var duoxuanInfo = jsonObj['resultObject']['duoxuan']
var duoxuans = duoxuanInfo['lists']
var duoxuanNum = duoxuanInfo['qNum']
dealChooseQeustion('writePaper', writePaperId, '多选题', duoxuans, duoxuanNum)
var panduanInfo = jsonObj['resultObject']['panduan']
var panduans = panduanInfo['lists']
var panduanNum = panduanInfo['qNum']
dealJudgeFillQeustion('writePaper', writePaperId, '判断题', panduans, panduanNum)
var tiankongInfo = jsonObj['resultObject']['tiankong']
var tiankongs = tiankongInfo['lists']
var tiankongNum = tiankongInfo['qNum']
dealJudgeFillQeustion('writePaper', writePaperId, '填空题', tiankongs, tiankongNum)
var jiandaInfo = jsonObj['resultObject']['jianda']
var jiandas = jiandaInfo['lists']
var jiandaNum = jiandaInfo['qNum']
dealJudgeFillQeustion('writePaper', writePaperId, '简答题', jiandas, jiandaNum)
} else {
console.log(errorInfo)
}
}
})
}
function dealChooseQeustion(judgeType, busyworkId, type, questions, questionNum) {
for (var i = 0; i < questionNum; i++) {
var sourceQuestion = questions[i]['questionContentText']
var question = dealContentText(sourceQuestion)
var questionOptionList = questions[i]['questionOptionList']
var questionId = questions[i]['id']
if (judgeType == 'lookPaper') {
if (questions[i]['stuScore'] == questions[i]['score']) {
var answer = ''
for (var j = 0; j < questionOptionList.length; j++) {
if (questionOptionList[j]['isSelcted']) {
if (answer != '') {
answer += ';'
}
answer += dealOption(type, questionOptionList[j]['text'])
}
}
insertToDatabase(type, question, answer)
}
} else {
for (var z = 0; z < questionOptionList.length; z++) {
var text = dealOption(type, questionOptionList[z]['text'])
console.log(text)
searchFromDatabase(busyworkId, questionId, type, question, text, z)
}
}
}
}
function dealJudgeFillQeustion(judgeType, busyworkId, type, questions, questionNum) {
for (var i = 0; i < questionNum; i++) {
var sourceQuestion = questions[i]['questionContentText']
var question = dealContentText(sourceQuestion)
var questionId = questions[i]['id']
var text = ''
if (judgeType == 'lookPaper') {
if (questions[i]['isAnswer'] == true) {
var answer = questions[i]['stuAnswer']
if (type == '判断题' || type == '简答题') {
insertToDatabase(type, question, answer)
} else {
var result = dealOption(type, answer)
insertToDatabase(type, question, result)
}
}
} else {
searchFromDatabase(busyworkId, questionId, type, question, text, 0)
}
}
}
function searchFromDatabase(busyworkId, questionId, type, question, text, index) {
GM_xmlhttpRequest({
method: 'GET',
url: api + 'search?type=' + type + '&question=' + question,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
var sourceAnswer = jsonObj['data'][0]['answer']
if (type == '单选题' || type == '多选题') {
if (sourceAnswer.search(';') != -1) {
var answers = sourceAnswer.split(';')
for (var n = 0; n < answers.length; n++) {
if (answers[n] == text) {
console.log(questionId + ' ' + index)
fuckHomeWork(busyworkId, questionId, index)
} else {
console.log(text)
}
}
} else {
if (sourceAnswer == text) {
console.log(index)
fuckHomeWork(busyworkId, questionId, index)
}
}
} else if (type == '填空题') {
var startStr = '["'
var endStr = '"]'
var str = startStr + sourceAnswer + endStr
console.log(str)
fuckHomeWork(busyworkId, questionId, str)
} else if (type == '简答题' && config.commit_jianda) {
fuckHomeWork(busyworkId, questionId, sourceAnswer)
}
else {
fuckHomeWork(busyworkId, questionId, sourceAnswer)
}
}
}
})
}
function insertToDatabase(type, question, answer) {
GM_xmlhttpRequest({
method: 'GET',
url: api + 'add?type=' + type + '&question=' + question + '&answer=' + answer,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
console.log(jsonObj['message'])
} else {
console.log(errorInfo)
}
}
});
}
function dealProblems(previewId, pointId, t) {
GM_xmlhttpRequest({
method: 'GET',
url: 'http://stu.ityxb.com/back/bxg/preview/questions?previewId=' + previewId + '&pointId=' + pointId + '&t=' + t,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
var questions = jsonObj['resultObject']
var questionNum = questions.length
for (var i = 0; i < questionNum; i++) {
var questionId = questions[i]['id'];
fuckQuestions(previewId, pointId, questionId)
}
} else {
console.log(errorInfo)
}
}
});
}
function dealOption(type, str) {
if (type == '填空题') {
var reFist = /【(.*?)】/g
var values = str.match(reFist)
var reSecond = /【(.*)】/i
var result = ''
for (var i = 0; i < values.length; i++) {
if (result != '') {
result += ';'
}
result += reSecond.exec(values[i])[1]
}
return String(result)
.replace('&', '&')
.replace('"', '"')
.replace(''', '\'')
.replace('<', '<')
.replace('>', '>')
.replace('"', '')
} else {
var re = /[A-Z]、(.*?)$/
var srouceStr = re.exec(str)[1]
return String(srouceStr)
.replace('&', '&')
.replace('"', '"')
.replace(''', '\'')
.replace('<', '<')
.replace('>', '>')
.replace('"', '')
}
}
function dealContentText(str) {
return String(str)
.replace('()', '')
.replace('。', '')
.replace(',', '')
.replace('( )', '')
}
function createPreviewT() {
var str = '1585465';
for (var i = 0; i < 6; i++) {
str += Math.floor(Math.random() * 10)
}
return str;
}
function createLookPaperT() {
var str = '1587060';
for (var i = 0; i < 6; i++) {
str += Math.floor(Math.random() * 10)
}
return str;
}
function fuckInfo(previewId, pointId, watchedDuration) {
GM_xmlhttpRequest({
method: 'POST',
url: 'http://stu.ityxb.com/back/bxg/preview/updateProgress',
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
data: 'previewId=' + previewId + '&pointId=' + pointId + '&watchedDuration=' + watchedDuration,
onload: function (data) {
if (data.status === 200) {
console.log('刷课成功')
} else {
console.log(errorInfo)
}
}
});
}
function fuckQuestions(previewId, pointId, preivewQuestionId) {
GM_xmlhttpRequest({
method: 'POST',
url: 'http://stu.ityxb.com/back/bxg/preview/ansQuestions',
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
data: 'previewId=' + previewId + '&pointId=' + pointId + '&preivewQuestionId=' + preivewQuestionId + '&stuAnswer=' + 0,
onload: function (data) {
if (data.status === 200) {
console.log('刷题成功')
} else {
console.log(errorInfo)
}
}
});
}
function fuckHomeWork(busyworkId, busyworkQuestionId, answer) {
GM_xmlhttpRequest({
method: 'POST',
url: 'http://stu.ityxb.com/back/bxg/my/busywork/updateStudentAns',
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
data: 'busyworkId=' + busyworkId + '&busyworkQuestionId=' + busyworkQuestionId + '&answer=' + answer,
onload: function (data) {
if (data.status === 200) {
var jsonObj = JSON.parse(data.response)
console.log(jsonObj)
} else {
console.log(errorInfo)
}
}
});
}
})()