This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
639 lines (570 loc) · 17.4 KB
/
script.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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
// ==UserScript==
// @name 清华社视听说 - 自动答题
// @namespace http://tampermonkey.net/
// @version 0.36
// @description 解放你的双手
// @author EpicMo
// @include *://www.tsinghuaelt.com/*
// @icon https://www.tsinghuaelt.com/favicon.ico
// @require https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js
// @grant GM_addStyle
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.deleteValue
// @run-at document-start
// ==/UserScript==
(function () {
"use strict";
// 下方时间你可以根据你的网络情况酌情调整
const submitDelay = 3000; // Submit 之后的等待时间
const pageNextDelay = 5000; // 换页 之后的等待时间
const inputDelay = 500; // 输入 之后的等待时间
const allauto = [
"auto_tiankong",
"auto_luyin",
"auto_lytk",
"auto_roleplay",
"auto_danxuan",
"auto_dropchoose",
"auto_drag",
"auto_video",
];
let vocabulary = [
"fantastic",
"error",
"whatsoever",
"arouse",
"magnificent",
"remarkable",
"schoolwork",
"ease",
"devil",
"factor",
"outstanding",
"infinite",
"infinitely",
"accomplish",
"accomplished",
"mission",
"investigate",
"mysterious",
"analysis",
"peak",
"excellence",
"credit",
"responsibility",
"amount",
"entertain",
"alternative",
"irregular",
"grant",
"cease",
"concentration",
"adapt",
"weird",
"profit",
"alter",
"performance",
"echo",
"hallway",
"await",
"abortion",
"database",
"available",
"indecision",
"ban",
"predict",
"breakthrough",
"fate",
"host",
"pose",
"instance",
"expert",
"surgery",
"naval",
"aircraft",
"target",
"spoonful",
"navigation",
"numerous",
"fluent",
"mechanic",
"advertise",
"advertising",
"waken",
"enormous",
"enormously",
"oversleep",
"survey",
"best-selling",
"filmmaker",
"prosperous",
"involve",
];
let phrases = ["Yes, he is", "No, he isn't", "Yes", "No"];
let getRanWord = () => {
return vocabulary[parseInt(Math.random() * vocabulary.length)];
};
let getRanPhrase = () => {
return phrases[parseInt(Math.random() * phrases.length)];
};
let sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
let click_btn = () => {
$(".wy-course-bottom .wy-course-btn-right .wy-btn").click();
};
let config = {
autodo: allauto,
autotryerr: true,
autostop: false,
delay: 10000,
};
function input_in(e, txt) {
if (e.type == "textarea") {
e.value = txt;
} else {
e.innerText = txt;
}
let changeEvent = null;
changeEvent = document.createEvent("HTMLEvents");
changeEvent.initEvent("input", true, true);
e.dispatchEvent(changeEvent);
changeEvent = document.createEvent("HTMLEvents");
changeEvent.initEvent("keyup", true, true);
e.dispatchEvent(changeEvent);
changeEvent = document.createEvent("HTMLEvents");
changeEvent.initEvent("change", true, true);
e.dispatchEvent(changeEvent);
}
function mouseEvent(div, type, pos) {
var mousedown = document.createEvent("MouseEvents");
let x = 0;
let y = 0;
if (pos == undefined) {
let rect = div.getBoundingClientRect();
x = (rect.x * 2 + rect.width) / 2;
y = (rect.y * 2 + rect.height) / 2;
} else {
x = pos.x;
y = pos.y;
}
mousedown.initMouseEvent(
type,
true,
true,
unsafeWindow,
0,
x,
y,
x,
y,
false,
false,
false,
false,
0,
null
);
div.dispatchEvent(mousedown);
}
async function dragTo(from, to) {
let dragBlock = $(".lib-drag-block");
dragBlock.scrollTop(to.offsetTop - dragBlock[0].offsetTop);
$(document).scrollTop(dragBlock[0].offsetTop);
await sleep(100);
mouseEvent(from, "mousedown");
await sleep(100);
mouseEvent(to, "mousemove");
await sleep(10);
mouseEvent(to, "mousemove");
mouseEvent(to, "mousemove");
mouseEvent(to, "mouseup");
await sleep(100);
}
async function doTopic() {
let setTixing = async (t) => {
console.log("[+] 题型:", t);
$("#yun_status").text("当前题型:" + t);
};
if (
$(".wy-course-bottom .wy-course-btn-right .wy-btn")
.text()
.indexOf("Submit") == -1 &&
$("#J_prismPlayer").length == 0
) {
// $('.page-next')[1].click();
// await sleep(pageNextDelay);
$("#yun_status").text("当前题目已完成");
return false;
}
if (
$('img[title="录音"]').length != 0 &&
config.autodo.includes("auto_luyin")
) {
await setTixing("录音");
await doReadRepeat();
} else if (
$(".lib-textarea-container, .img-blank-answer").length != 0 &&
config.autodo.includes("auto_lytk")
) {
await setTixing("听力/图片填空");
await doListenImgAnswer();
} else if (
$(".lib-fill-blank-do-input-left").length != 0 &&
config.autodo.includes("auto_tiankong")
) {
await setTixing("填空");
await doTianKone();
} else if (
$(".lib-single-item-img").length != 0 &&
config.autodo.includes("auto_danxuan")
) {
await setTixing("单选");
await doSingleChoose();
} else if (
$(".lib-role-select-item").length != 0 &&
config.autodo.includes("auto_roleplay")
) {
await setTixing("角色扮演");
await doRolePlay();
} else if (
$(".ant-select-dropdown-menu-item").length != 0 &&
config.autodo.includes("auto_dropchoose")
) {
await setTixing("下拉选择");
await doDropChoose();
} else if (
$(".lib-drag-box").length != 0 &&
config.autodo.includes("auto_drag")
) {
await setTixing("托块");
await doDrag();
} else if (
$("#J_prismPlayer").length != 0 &&
config.autodo.includes("auto_video")
) {
await setTixing("视频");
await doVideo();
await sleep(config.delay); // 挂机,增加时长
return true;
} else {
await unSupposedOrSkip();
return false;
}
await sleep(config.delay); // 挂机,增加时长
click_btn(); // Submit
return true;
}
// ===========================================
// 填空题
async function doTianKone() {
// 先填写随机单词,获得答案
let inputs = $(".lib-fill-blank-do-input-left");
$.each(inputs, function (i, item) {
input_in(item, getRanWord());
});
await sleep(inputDelay);
click_btn(); // Submit
await sleep(submitDelay);
let answer = [],
anyAnswer = false;
$('.lib-edit-score span[data-type="1"]').each((i, item) => {
if (item.innerText.toLowerCase().indexOf("vary") != -1) {
// 任意填空
anyAnswer = true;
return false;
}
answer.push(item.innerText);
});
if (anyAnswer) {
return;
}
click_btn(); // Retry
await sleep(submitDelay);
// 提交正确答案
inputs = $(".lib-fill-blank-do-input-left");
$(inputs).each((i, item) => {
let ans = answer[i];
if (answer[i].includes(";")) {
ans = ans.split(";")[0];
}
input_in(item, ans);
});
await sleep(inputDelay);
}
// 录音题
async function doReadRepeat() {
let sum_record = 0;
if ($(".lib-oral-container-top").length != 0) {
var rec_div = $(".lib-oral-container-top");
} else {
var rec_div = $(".lib-listen-item-right-img");
}
rec_div.each((i, div) => {
if ($(div).find('img[title="播放"]').length != 0) {
return true;
}
let click_record = (e) => {
console.log("click:", e);
$(e).find('img[title="录音"],img[title="停止"]').click();
};
setTimeout(() => {
click_record(div);
}, sum_record * 5000);
setTimeout(() => {
click_record(div);
}, 3000 + sum_record * 5000);
sum_record++;
});
await sleep(2000 + sum_record * 5000);
}
// 单选题
async function doSingleChoose() {
let answer_map = { A: 0, B: 1, C: 2, D: 3, E: 4, F: 5 };
// 随机选择以获得正确答案
$(".lib-single-item-img img").click();
await sleep(inputDelay);
click_btn(); // Submit
await sleep(submitDelay);
let answer = [];
$(".lib-single-cs-answer").each((i, item) => {
answer.push(item.innerText);
});
click_btn(); // Retry
await sleep(submitDelay);
$(".lib-single-box").each((i, item) => {
$($(item).find(".lib-single-item")[answer_map[answer[i]]])
.find("img")
.click();
});
await sleep(inputDelay);
}
// 下拉选择题
async function doDropChoose() {
// 随机选择以获得正确答案
$(".ant-select-dropdown-menu-item").click();
await sleep(inputDelay);
click_btn(); // Submit
await sleep(submitDelay);
let answer = [];
$(".wy-lib-cs-key + span").each((i, item) => {
answer.push(item.innerText);
});
click_btn(); // Retry
await sleep(submitDelay);
$(".ant-select-dropdown-menu").each((i, div) => {
$(div)
.find("li")
.each((index, item) => {
if ($.trim(item.innerText) == answer[i]) {
$(item).click();
return false;
}
});
});
await sleep(inputDelay);
}
// 角色扮演
async function doRolePlay() {
$(".lib-role-select-item img")[0].click();
$(".lib-role-select-start button").click();
await sleep(80000);
}
// 听力/图片填空
async function doListenImgAnswer() {
let inputs = $(".lib-textarea-container, .img-blank-answer");
$.each(inputs, function (i, item) {
input_in(item, getRanPhrase());
});
await sleep(inputDelay);
}
// 托块
async function doDrag() {
let answerbox = $(".lib-drag-answer-list");
let boxes = $(".lib-drag-box");
for (let i = 0; i < answerbox.length; i++) {
await dragTo(boxes[i], answerbox[i]);
}
await sleep(inputDelay);
click_btn(); // Submit
await sleep(submitDelay);
let answer = [];
$(".lib-drag-stu-info-answer").each((i, item) => {
let temp = [];
$(item)
.find("span")
.each((j, answer) => {
temp.push(answer.innerText);
});
answer.push(temp);
});
click_btn(); // Retry
await sleep(submitDelay);
answerbox = $(".lib-drag-answer-list");
boxes = $(".lib-drag-box");
for (let i = 0; i < answerbox.length; i++) {
for (const box of boxes) {
if (
answer[i] != undefined &&
answer[i].includes($(box).find("span")[0].innerText)
) {
await dragTo(box, answerbox[i]);
}
}
}
await sleep(inputDelay);
}
async function doVideo() {
await sleep(2000);
let player = unsafeWindow["yunPlayer"];
if (player == undefined) {
console.error("yunPlayer is undefined!");
return;
}
player.play();
await sleep(1000);
player.seek(player.getDuration() - 5);
await sleep(8000);
}
// 不支持体型
async function unSupposedOrSkip(params) {
console.log("[!]", "遇到不支持体型或未选择,自动跳过。。。");
}
// ===========================================
let running = false;
async function initConf() {
config = await GM.getValue("config", config);
$.each(config.autodo, (index, id) => {
$("#" + id).prop("checked", true);
});
$("#set_tryerr").prop("checked", config.autotryerr);
$("#set_manu").prop("checked", config.autostop);
$("#set_delay").val(config.delay);
}
async function doLoop() {
while (running) {
let status = await doTopic();
if (!status && config.autostop) {
$("#yun_status").text("不支持当前体型, 已停止");
break;
}
console.log("[*]", "已完成,切换下一题。。。");
await sleep(submitDelay);
$(".page-next")[1].click();
await sleep(pageNextDelay);
}
$(".yunPanel button").prop("disabled", false);
$("#yun_status").text("IDLE");
}
console.log("=== 视听说 - 脚本启动 ===");
let ori_create_player = unsafeWindow["Aliplayer"];
Object.defineProperty(unsafeWindow, "Aliplayer", {
set: (v) => {
ori_create_player = v;
},
get: () => {
return function (config) {
unsafeWindow["yunPlayer"] = ori_create_player(config);
console.log("getPlayer!!!", unsafeWindow["yunPlayer"]);
return unsafeWindow["yunPlayer"];
};
},
});
window.addEventListener("load", pageFullyLoaded);
function pageFullyLoaded() {
console.log("=== 视听说 - 注入窗口 ===");
$(
`<style>.course-main{padding-left: 0px ! important;}.yunPanel input[type="checkbox"]{margin-left: 10px;}.yunPanel h3,.yunPanel input,.yunPanel label{font-size:smaller}.yunPanel p{margin:10px 0}.yunPanel{padding:10px 20px;position:fixed;top:100px;right:150px;height:380px;width:200px;border:1px solid #000;background-color:#fcff6680;z-index:9999}.yunPanel .close{position:absolute;cursor:pointer;top:8px;right:10px}.yunPanel .close:hover{color:#00000088}</style>`
).appendTo("head");
$(document.body).after(`
<div class="yunPanel">
<div class="close">x</div>
<h1 style="text-align: center;font-size: medium;">社听说 - 自动答题</h1>
<hr>
<h2 style="font-size: small;">自动完成题型:</h2>
<p>
<input type="checkbox" id="auto_tiankong">
<label for="auto_tiankong">填空</label>
<input type="checkbox" id="auto_luyin">
<label for="auto_luyin">录音</label>
<input type="checkbox" id="auto_lytk">
<label for="auto_lytk">录音填空</label>
<input type="checkbox" id="auto_roleplay">
<label for="auto_roleplay">角色扮演</label>
<input type="checkbox" id="auto_danxuan">
<label for="auto_danxuan">单项选择</label>
<input type="checkbox" id="auto_dropchoose">
<label for="auto_dropchoose">下拉选择</label>
<input type="checkbox" id="auto_drag">
<label for="auto_drag">托块</label>
<input type="checkbox" id="auto_video">
<label for="auto_video">视频</label>
</p>
<h2 style="font-size: small;">设置</h2>
<p>
<p>
<input type="checkbox" id="set_tryerr">
<label for="set_tryerr">自动试错</label>
<input type="checkbox" id="set_manu">
<label for="set_manu">不支持题型停止</label>
</p>
<label>每题耗时(ms) <input style="width: 50px;" type="text" id="set_delay"></label>
<button id="yun_save" style="float: left;margin-top:5px;width: 48%;">保存</button>
<button id="yun_reset" style="float: right;margin-top:5px;width: 48%;">默认</button>
<div style="clear: both;"></div>
</p>
<hr>
<h2 id="yun_status" style="font-size: small;text-align: center;margin-bottom:8px;">IDLE</h2>
<button id="yun_doone" style="width: 100%;margin-bottom: 3px;">做一题</button>
<button id="yun_start" style="width: 100%;">开始</button>
</div>
`);
$("#yun_start").click(() => {
if ($("#yun_start").text() == "开始") {
$("#yun_doone").prop("disabled", true);
running = true;
doLoop();
$("#yun_start").text("停止");
} else {
$(".yunPanel button").prop("disabled", true);
running = false;
$("#yun_start").text("开始");
}
});
$("#yun_doone").click(() => {
$("#yun_start").text("开始");
running = false;
$(".yunPanel button").prop("disabled", true);
doTopic().then((result) => {
$(".yunPanel button").prop("disabled", false);
if (result) {
$("#yun_status").text("Done!");
}
});
});
$(".yunPanel .close").click(() => {
$(".yunPanel").hide();
});
$("#yun_reset").click(() => {
GM.deleteValue("config");
window.location.reload();
});
$("#yun_save").click(() => {
config.autodo = [];
$.each(allauto, (index, id) => {
if ($("#" + id).prop("checked")) {
config.autodo.push(id);
}
});
config.autotryerr = $("#set_tryerr").prop("checked");
config.autostop = $("#set_manu").prop("checked");
config.delay = $("#set_delay").val();
GM.setValue("config", config).then(() => {
$("#yun_status").text("保存成功");
});
});
initConf();
}
// Your code here...
})();