-
Notifications
You must be signed in to change notification settings - Fork 8
/
unipus_helper.user.js
713 lines (683 loc) · 27.2 KB
/
unipus_helper.user.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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
// ==UserScript==
// @name U校园unipus英语网课作业答案显示(不支持单元测试)
// @namespace https://greasyfork.org
// @version 1.18
// @description 小窗口显示U校园板块测试答案
// @icon https://ucontent.unipus.cn/favicon.ico
// @match *://ucontent.unipus.cn/_pc_default/pc.html?*
// @match *://u.unipus.cn/*
// @connect unipus.cn
// @connect fanyi.youdao.com
// @connect translate.google.cn
// @connect translate.google.com
// @connect api.microsofttranslator.com
// @connect api.fanyi.baidu.com
// @grant GM_xmlhttpRequest
// @grant GM.setClipboard
// @grant GM.setValue
// @grant GM.getValue
// @run-at document-end
// @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @require https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/crypto-js/4.1.1/crypto-js.min.js
// @require https://cdn.staticfile.org/blueimp-md5/1.0.1/js/md5.min.js
// @license MIT
// ==/UserScript==
/**
* 构建一个 Translator 类型,并发请求多个翻译器的结果
*
* 构建方法:
* ```js
* await Translator.new(text, direction);
* ```
*/
class Translator {
constructor(translateResult) {
this.google = translateResult[0] ?? "";
this.baidu = translateResult[1] ?? "";
this.bing = translateResult[2] ?? "";
}
static async new(text, direction) {
if (!["zh2en", "en2zh"].includes(direction)) {
throw Error("direction 参数只能接受 zh2en 或 en2zh 之一");
}
this.text = text;
this.direction = direction;
let todoList = [this._google(), this._baidu(), this._bing()];
let result = [];
let promiseResult = await Promise.allSettled(todoList);
for (let i = 0; i < promiseResult.length; i++) {
if (promiseResult[i].status === "rejected") {
console.error(promiseResult[i].reason);
} else {
result[i] = promiseResult[i].value;
}
}
return new Translator(result);
}
static async _google() {
let xhr = await getRequest(
`http://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=${this.direction.split("2")[0]}&tl=${this.direction.split("2")[1]}&q=${encodeURIComponent(this.text)}`
);
let obj = JSON.parse(xhr.responseText);
let result = "";
for (let sentence of obj.sentences) {
result += sentence.trans;
}
return result;
}
static async _baidu() {
let appid = "20211128001012194";
let salt = randomString(10);
let sec = "LmBTDmGsvh2Ww2ws2F2S";
let sign = md5(appid + this.text + salt + sec);
let xhr = await getRequest(
`http://api.fanyi.baidu.com/api/trans/vip/translate?q=${encodeURIComponent(this.text)}&from=${this.direction.split("2")[0]}&to=${this.direction.split("2")[1]}&appid=${appid}&salt=${salt}&sign=${sign}`
);
let obj = JSON.parse(xhr.responseText);
let result = "";
for (let item of obj.trans_result) {
result += item.dst;
}
return result;
}
static async _bing() {
let xhr = await getRequest(
`http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=AFC76A66CF4F434ED080D245C30CF1E71C22959C&from=${this.direction.split("2")[0]}&to=${this.direction.split("2")[1]}&text=${encodeURIComponent(this.text)}`
);
let result = xhr.responseText.replace(/<.*?>/g, "");
if (result.includes("TranslateApiExceptionMethod")) {
throw Error("TranslateApiExceptionMethod");
}
return result;
}
}
/**
* Generate a random string
* @param {number} length Length of this random string
* @returns {string} The random string
*/
function randomString(length) {
let abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
let ret = "";
for (let i = 0; i < length; i++) {
ret += abc.charAt(Math.floor(Math.random() * abc.length));
}
return ret
}
/**
* Generate a random num string
* @param {number} length Length of this random num string
* @returns {string} The random num string
*/
function randomNumString(length) {
let nums = "0123456789";
let ret = "";
for (let i = 0; i < length; i++) {
ret += nums.charAt(Math.floor(Math.random() * nums.length));
}
return ret
}
/**
* Async wait, default to 10 ms
*
* @param {number} ms How long to wait (in millisecond)
* @returns {Promise<null>}
*/
async function sleep(ms = 10) {
// 异步等待,只阻塞当前脚本调用处函数,不阻塞整个浏览器
// 调用方法:await sleep() 或 await sleep (1000)
return new Promise(function (resolve, reject) {
setTimeout(() => {
resolve();
}, ms);
})
}
async function getRequest(url, headers = {}, timeout = 5000) {
return new Promise(function (resolve, reject) {
// 由于 GM.xmlHttpRequest 默认不携带浏览器 cookie
// 且 Grease Monkey 没有提供获取 HTTP-Only 的 cookie 的 API
// 所以只能使用旧的 GM_xmlhttpRequest 来发起请求,否则会要求 SSO 登录
GM_xmlhttpRequest({
method: 'GET',
url: url,
headers: headers,
timeout: timeout,
onload: (xhr) => {
resolve(xhr);
},
onerror: (err) => {
reject(err);
},
ontimeout: (err) => {
reject(err);
}
});
});
}
/**
* Decrypt and parse "content" of XHR, thanks to SSmJaE for providing this function!
* @param {String}} json Encrypted json or raw json string
* @returns {Object} Object from raw json string
*/
function decryptContent(json) {
if (json) {
let r = json.content.slice(7)
, o = CryptoJS.enc.Utf8.parse("1a2b3c4d" + json.k)
, i = CryptoJS.enc.Hex.parse(r)
, a = CryptoJS.enc.Base64.stringify(i)
, contentJson = JSON.parse(CryptoJS.AES.decrypt(a, o, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.ZeroPadding
}).toString(CryptoJS.enc.Utf8));
json = contentJson;
console.log(json);
}
return json;
}
/**
* Copy a string to clipboard
* @param {string} str String to be copy
*/
function copyMe(str) {
function _legacyCopy() {
console.log("正在使用传统方法复制");
let tmpInput = document.createElement('input');
elem.insertAdjacentHTML("afterend", tmpInput)
tmpInput.value = str;
tmpInput.focus();
tmpInput.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
}
tmpInput.blur();
console.log('复制成功');
tmpInput.remove();
}
if (GM.setClipboard) {
GM.setClipboard(str);
} else if (navigator.clipboard && window.isSecureContext) {
console.log("正在使用 navigator clipboard api 进行复制操作");
navigator.clipboard.writeText(str)
.catch(err => {
console.log("navigator clipboard api 复制时出错,将使用传统方法进行复制")
_legacyCopy();
})
} else {
_legacyCopy();
}
}
/**
* Get token
* @returns {Promise<string>} token or fallbackToken when error.
*/
async function getToken() {
let fallbackToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvcGVuX2lkIjoidHV4NkNCQVc4aGRrcnFZdzc5SEpEWDF2aTR5Z2ptcDUiLCJuYW1lIjoiIiwiZW1haWwiOiIiLCJhZG1pbmlzdHJhdG9yIjoiZmFsc2UiLCJleHAiOjE5MDI5NzAxNTcwMDAsImlzcyI6IlI0aG03RmxQOFdvS0xaMUNmTkllIiwiYXVkIjoiZWR4LnVuaXB1cy5jbiJ9.CwuQmnSmIuts3hHAMf9lT954rKHXUNkps-PfRJp0KnU";
let oldToken = await GM.getValue("token");
if (oldToken && new Date(oldToken.expireWhen).getTime() > new Date().getTime()) {
console.info("【U校园助手】正在使用旧的token");
return oldToken.token;
}
console.info("【U校园助手】正在获取新的的token");
let url = "https://u.unipus.cn/user/data/getToken";
let xhr = await getRequest(url).catch((err) => {
console.error(err);
layui.use("layer", function () {
layer.alert(`获取 Token 失败,请刷新重试\n错误信息:${err}`);
});
return fallbackToken;
});
if (xhr.status != 200) {
layui.use("layer", function () {
layer.alert(`获取 Token 失败,请刷新重试`);
});
return fallbackToken;
}
if (!xhr.responseText.startsWith("{")) {
console.error("获取 Token 时的返回值:", xhr.responseText);
if (xhr.responseText.includes("登录")) {
layui.use("layer", function () {
layer.alert("获取 Token 失败,请尝试重新登录");
});
return null;
}
alert(`获取 Token 失败,以下是 xhr 返回值:\n${xhr.responseText}`);
return null;
}
let obj = JSON.parse(xhr.responseText);
if (!obj || !obj.token)
return fallbackToken;
let token = obj.token;
let expireWhen = new Date()
expireWhen.setDate(expireWhen.getDate() + 1);
let tokenObj = {
token: token,
expireWhen: expireWhen,
}
GM.setValue("token", tokenObj);
return token;
}
/**
* 弹窗来建议用户报告错误
* @param {string} msg 要显示的弹窗信息
*/
function suggestFeedback(msg) {
if (layui) {
layui.use("layer", function () {
layer.alert(
`${msg},请截图、复制当前网址,并点击下方按钮向作者报告这个问题`,
{
btn: ["报告这个问题", "忽略"],
yes: function (index, layero) {
window.open("https://greasyfork.org/zh-CN/scripts/437179-u%E6%A0%A1%E5%9B%ADunipus%E8%8B%B1%E8%AF%AD%E7%BD%91%E8%AF%BE%E4%BD%9C%E4%B8%9A%E7%AD%94%E6%A1%88%E6%98%BE%E7%A4%BA-%E4%B8%8D%E6%94%AF%E6%8C%81%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/feedback", "_blank");
},
btn2: function (index, layero) {
layer.close(index);
}
}
);
});
} else {
if (confirm(`${msg},请截图、复制当前网址后点击确定,来向作者报告这个问题`)) {
window.open("https://greasyfork.org/zh-CN/scripts/437179-u%E6%A0%A1%E5%9B%ADunipus%E8%8B%B1%E8%AF%AD%E7%BD%91%E8%AF%BE%E4%BD%9C%E4%B8%9A%E7%AD%94%E6%A1%88%E6%98%BE%E7%A4%BA-%E4%B8%8D%E6%94%AF%E6%8C%81%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/feedback", "_blank");
};
}
}
/**
* 显示答案浮窗
*/
function showPanel() {
layer.open({
type: 1,
area: ['310px', '400px'],
offset: 'r',
id: 'msgt',
closeBtn: 1,
title: " ",
shade: 0,
maxmin: true,
anim: 2,
content: `<div class="layui-collapse"><div class="layui-colla-item"></div></div>
<div id="content">
<table class="layui-table">
<colgroup>
<col width="100">
<col>
<col>
</colgroup>
<thead><tr></tr></thead>
<tbody></tbody>
</table>
</div>`
});
}
/**
* 解析并显示答案
*/
async function showanswer() {
let url = location.href
let arr = url.split("/")
let unit = arr[arr.length - 2]
let course = /course-v1:.*?\//g.exec(url);
course = course[0];
let token = await getToken();
let xhr = await getRequest(
`https://ucontent.unipus.cn/course/api/content/${course}${unit}/default/`,
{
'X-ANNOTATOR-AUTH-TOKEN': token
},
5000
).catch((err) => {
console.error(err);
let el = `<tr class="layui-bg"><td>答案加载失败,请刷新重试。</td></tr>`;
$("#content>table>tbody").append($(el));
});
if (xhr.status != 200) {
let el = `<tr class="layui-bg"><td>答案加载失败,请刷新重试。</td></tr>`;
$("#content>table>tbody").append($(el));
return;
}
// obj.content 是加密后的题目信息
let obj = JSON.parse(xhr.responseText) || {};
if (!obj.content) {
suggestFeedback("U校园返回的内容中不包含'content'字段,检查api是否改变");
return;
}
// 对 api 返回的 content 进行解密
var plainContent = decryptContent(obj) || {};
console.log(plainContent);
let questions = {};
for (let key in plainContent) {
// 将返回的多个或单个题目详情分别按序号装载到 questions 字典中
let quesNo = 1;
if (key.includes("content_")) {
let re = /content_(\d+):/g.exec(key);
quesNo = parseInt(re[1]);
}
questions[quesNo] = {
key: key,
content: plainContent[key]
};
}
let quesNo = /p_(\d+)/g.exec(url);
quesNo = quesNo[1];
if (questions[quesNo].key.includes(":questions")) {
// 选择题
let answers = questions[quesNo].content.questions.map(
question => question.answers);
answers.forEach((answer, index) => {
let answerId = randomString(5);
let btnId = randomString(5);
let el = `<tr class="layui-bg"><td>
<b>${index + 1}. </b>
<code id="${answerId}">${answer.join("、")}</code>
</td></tr>`;
$("#content>table>tbody").append($(el));
$(`#${btnId}`).on("click", function () {
copyMe(answer);
});
})
let find = window.setInterval(async function () {
if (document.querySelector(".questions--questionDefault-2XLzl.undefined")) {
window.clearInterval(find);
answers.forEach((answer, index) => {
let questionElem = $(".questions--questionDefault-2XLzl.undefined")[index];
let options = questionElem.querySelectorAll(".clearfix");
if (options.length == 0) {
options = questionElem.querySelectorAll(".MultipleChoice--checkbox-2_VGC");
}
for (let willSelect of answer) {
let sel = willSelect.toUpperCase().charCodeAt(0) - "A".charCodeAt(0);
options[sel].click();
}
});
}
}, 1000);
} else if (questions[quesNo].key.includes(":scoopquestions")) {
// 填空题
$("#content>table>tbody").prepend($(
`<tr class="layui-bg"><td><b>无需在此面板中复制,点击题目中的空,直接粘贴即可。</b></td></tr>`
));
let answers = questions[quesNo].content.questions.map(
question => question.answers[0]);
answers.forEach((answer, index) => {
let answerId = randomString(5);
let btnId = randomString(5);
let el = `<tr class="layui-bg"><td>
<b>${index + 1}. </b>
<code id="${answerId}">${answer}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`;
$("#content>table>tbody").append($(el));
$(`#${btnId}`).on("click", function () {
copyMe(answer);
});
})
let interval = window.setInterval(function () {
if (document.querySelector(".htmlViewBlank--holder_style-2dnxi")) {
window.clearInterval(interval);
answers.forEach((answer, index) => {
$($(".htmlViewBlank--holder_style-2dnxi")[index]).on("click", function () {
copyMe(answer);
});
});
}
}, 1000);
} else if (questions[quesNo].key.includes(':shortanswer') && questions[quesNo].content.category === "shortanswer:shortAnswer") {
// 翻译题
let question = questions[quesNo].content.content[0].html.html;
question = question.replace(/<.*?>|\(.*?\)|(.*?)/g, "");
let direction = 'zh2en';
if (/^[a-zA-Z\.,\s]+$/g.test(question.substring(0, 5))) direction = 'en2zh';
let translator = await Translator.new(question, direction);
try {
// 谷歌翻译
let result = translator.google;
let answerId = randomString(5);
let btnId = randomString(5);
$("#content>table>tbody").append($(`
<tr class="layui-bg"><td>
<b>谷歌翻译:</b>
<code id="${answerId}">${result}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`));
$(`#${btnId}`).on("click", function () {
copyMe(result);
});
} catch (e) {
console.error(e);
}
try {
// 百度翻译
let result = translator.baidu;
let answerId = randomString(5);
let btnId = randomString(5);
$("#content>table>tbody").append($(`
<tr class="layui-bg"><td>
<b>百度翻译:</b>
<code id="${answerId}">${result}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`));
$(`#${btnId}`).on("click", function () {
copyMe(result);
});
} catch (e) {
console.error(e);
}
try {
// 必应翻译
let result = translator.bing;
let answerId = randomString(5);
let btnId = randomString(5);
$("#content>table>tbody").append($(`
<tr class="layui-bg"><td>
<b>必应翻译:</b>
<code id="${answerId}">${result}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`));
$(`#${btnId}`).on("click", function () {
copyMe(result);
});
} catch (e) {
console.error(e);
}
try {
let answer = questions[quesNo].content.analysis.html;
answer = answer.replace(/<.*?>/g, "").replace(/\d\.\s?( )?/g, "");
let el = `
<tr class="layui-bg"><td>
<b>标准答案(仅供参考):</b>
${answer}
</td></tr>`;
$("#content>table>tbody").append($(el));
} catch (e) {
console.error(e);
}
} else if (questions[quesNo].key.includes(':shortanswer') || questions[quesNo].key.includes(":scoopshortanswer")) {
// 简答题
if (questions[quesNo].key.includes(':shortanswer') && questions[quesNo].content.category === "shortanswerScoop") {
if (questions[quesNo].content.analysis.html.length > 0) {
let answer = questions[quesNo].content.analysis.html;
answer = answer.replace(/<.*?>/g, "").replace(/\d\.\s?( )?/g, "");
let answerId = randomString(5);
let btnId = randomString(5);
let el = `
<tr class="layui-bg"><td>
<b>标准答案(仅供参考):</b>
<code id="${answerId}">${answer}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`;
$("#content>table>tbody").append($(el));
$(`#${btnId}`).on("click", function () {
copyMe(answer);
});
} else {
let answers = questions[quesNo].content.questions.map(
question => question.analysis.html.replace(/<.*?>/g, "").replace(/\d\.\s?( )?/g, ""));
answers.forEach((answer, index) => {
let answerId = randomString(5);
let btnId = randomString(5);
let el = `
<tr class="layui-bg"><td>
<b>${index + 1}.(仅供参考)</b>
<code id="${answerId}">${answer}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`;
$("#content>table>tbody").append($(el));
$(`#${btnId}`).on("click", function () {
copyMe(answer);
});
})
}
} else {
let answers = questions[quesNo].content.questions.map(
question => question.analysis.html.replace(/<.*?>/g, "").replace(/\d\.\s?( )?/g, ""));
answers.forEach((answer, index) => {
let answerId = randomString(5);
let btnId = randomString(5);
let el = `
<tr class="layui-bg"><td>
<b>${index + 1}.(仅供参考)</b>
<code id="${answerId}">${answer}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`;
$("#content>table>tbody").append($(el));
$(`#${btnId}`).on("click", function () {
copyMe(answer);
});
});
}
} else if (questions[quesNo].key.includes(":sequence")) {
// 排序题
let answers = questions[quesNo].content.questions.map(
question => question.answer);
answers.forEach((answer, index) => {
let el = `<tr class="layui-bg"><td>
<b>${index + 1}. </b>
<code>${answer}</code>
</td></tr>`;
$("#content>table>tbody").append($(el));
});
} else if (questions[quesNo].key.includes(":bankedcloze")) {
// 十五选十
let answers = questions[quesNo].content.questions.map(
question => question.answer);
$("#content>table>tbody").prepend($(
`<tr class="layui-bg"><td><b>无需在此面板中复制,点击题目中的空,直接粘贴即可。</b></td></tr>`
))
answers.forEach((answer, index) => {
let answerId = randomString(5);
let btnId = randomString(5);
let el = `
<tr class="layui-bg"><td>
<b>${index + 1}. </b>
<code id=${answerId}>${answer}</code>
<button style="float:right;" id="${btnId}">复制</button>
</td></tr>`;
$("#content>table>tbody").append($(el));
$(`#${btnId}`).on("click", function () {
copyMe(answer);
});
});
let find = window.setInterval(function () {
if ($(".cloze-text-pc--bc-input-k5WJk").length > 0) {
window.clearInterval(find);
answers.forEach((item, index) => {
$($(".cloze-text-pc--bc-input-k5WJk")[index]).on("click", function () {
copyMe(item);
});
});
}
}, 1000);
} else if (questions[quesNo].key.includes(":scoopselection")) {
// 下拉选择题
let answers = questions[quesNo].content.questions.map(question => {
let result = [];
for (let willSelect of question.answers) {
// willSelect 为选项,即 A、B、C、D,可在 options 中找到对应的文字内容
for (let option of question.options) {
if (option.caption === willSelect) {
result.push(option.content.html.replace(/<.*?>/g, "").replace(/\d\.\s?( )?/g, ""));
}
}
}
return result;
});
answers.forEach((answer, index) => {
let el = `
<tr class="layui-bg"><td>
<b>${index + 1}. </b>
<code>${answer.join("、")}</code>
</td></tr>`;
$("#content>table>tbody").append($(el));
});
}
}
function main() {
if (window.location.href.includes("u.unipus.cn")) {
window.setInterval(function () {
if (document.getElementsByClassName("layui-layer-shade").length > 0 && document.querySelectorAll(".layui-layer-dialog").length > 0) {
// 去除环境检测弹窗
document.querySelector(".layui-layer-shade").remove();
document.querySelector(".layui-layer-dialog").remove();
}
}, 100);
}
if (window.location.href.includes("ucontent.unipus.cn")) {
window.setInterval(function () {
if (document.querySelector('.taskTipStyle--tipBody-2h6eh')
&& document.querySelector('.taskTipStyle--tipBody-2h6eh').innerText.includes("本单元学习时间")) {
document.querySelector('button[type="button"]').click();
}
}, 100);
$('head').append('<link href="https://cdn.staticfile.org/layui/2.6.8/css/layui.css" rel="stylesheet" type="text/css" />');
let onload = function (data, status, jqxhr) {
layui.use('element', function () {
let element = layui.element;
});
layer.closeAll();
showPanel();
showanswer();
};
$.getScript("https://cdn.staticfile.org/layui/2.6.8/layui.min.js", onload)
.fail(function () {
if (arguments[0].readyState == 0) {
//加载失败则更换一个 CDN 源
$.getScript(
"https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/layui/2.6.8/layui.min.js",
onload
).fail(function () {
suggestFeedback("Layui 外部库加载失败,请检查网络连接后刷新重试,若重试仍不成功");
})
} else {
//script loaded but failed to parse
suggestFeedback("解析 Layui 外部库时出现错误:" + arguments[2].toString());
}
});
let autoClickPlay = window.setInterval(async function () {
if (
document.querySelector(".audio--aplayer-mute-2VMS7") &&
document.querySelector(".audio--aplayer-rate-ms-ZWyM6.audio--aplayer-rate-m-aH2Eu") &&
document.querySelector(".audio--aplayer-play-3oL9n")
) {
window.clearInterval(autoClickPlay);
await sleep(500);
// 点击倍速
document.querySelector(".audio--aplayer-rate-ms-ZWyM6.audio--aplayer-rate-m-aH2Eu").querySelectorAll("span")[2].click();
await sleep(300);
// 点击静音
document.querySelector(".audio--aplayer-mute-2VMS7").click();
await sleep(300);
// 点击播放
document.querySelector(".audio--aplayer-play-3oL9n").click();
}
}, 500);
window.onhashchange = () => {
$("#content>table>tbody").empty();
main();
}
}
}
(function () {
'use strict';
main();
})();