forked from Xu22Web/tech-study-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtech-study.js
3237 lines (3230 loc) · 112 KB
/
tech-study.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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name 不学习何以强国
// @namespace http://tampermonkey.net/
// @version 20221105
// @description 有趣的 `学习强国` 油猴插件。读文章,看视频,做习题。问题反馈: https://github.com/Xu22Web/tech-study-js/issues 。
// @author 原作者:techxuexi 荷包蛋。现作者:Xu22Web
// @match https://www.xuexi.cn/*
// @match https://pc.xuexi.cn/points/exam-practice.html
// @match https://pc.xuexi.cn/points/exam-weekly-detail.html?id=*
// @match https://pc.xuexi.cn/points/exam-paper-detail.html?id=*
// @match https://login.xuexi.cn/login/xuexiWeb?appid=dingoankubyrfkttorhpou&goto=https%3A%2F%2Foa.xuexi.cn&type=1&state=ffdea2ded23f45ab%2FKQreTlDFe1Id3B7BVdaaYcTMp6lsTBB%2Fs3gGevuMKfvpbABDEl9ymG3bbOgtpSN&check_login=https%3A%2F%2Fpc-api.xuexi.cn
// @require https://cdn.jsdelivr.net/npm/[email protected]
// @run-at document-start
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant GM_addElement
// @grant unsafeWindow
// @updateURL https://raw.githubusercontent.com/Xu22Web/tech-study-js/master/tech-study.js
// @downloadURL https://raw.githubusercontent.com/Xu22Web/tech-study-js/master/tech-study.js
// ==/UserScript==
/**
* @description api配置
*/
const API_CONFIG = {
// 用户信息
userInfo: 'https://pc-api.xuexi.cn/open/api/user/info',
// 总分
totalScore: 'https://pc-api.xuexi.cn/open/api/score/get',
// 当天分数
todayScore: 'https://pc-api.xuexi.cn/open/api/score/today/query',
// 任务列表
taskList: 'https://pc-proxy-api.xuexi.cn/api/score/days/listScoreProgress?sence=score&deviceType=2',
// 新闻数据
todayNews: [
'https://www.xuexi.cn/lgdata/35il6fpn0ohq.json',
'https://www.xuexi.cn/lgdata/1ap1igfgdn2.json',
'https://www.xuexi.cn/lgdata/vdppiu92n1.json',
'https://www.xuexi.cn/lgdata/152mdtl3qn1.json',
],
// 视频数据
todayVideos: [
'https://www.xuexi.cn/lgdata/525pi8vcj24p.json',
'https://www.xuexi.cn/lgdata/11vku6vt6rgom.json',
'https://www.xuexi.cn/lgdata/2qfjjjrprmdh.json',
'https://www.xuexi.cn/lgdata/3o3ufqgl8rsn.json',
'https://www.xuexi.cn/lgdata/591ht3bc22pi.json',
'https://www.xuexi.cn/lgdata/1742g60067k.json',
'https://www.xuexi.cn/lgdata/1novbsbi47k.json',
],
// 每周答题列表
weeklyList: 'https://pc-proxy-api.xuexi.cn/api/exam/service/practice/pc/weekly/more',
// 专项练习列表
paperList: 'https://pc-proxy-api.xuexi.cn/api/exam/service/paper/pc/list',
// 文本服务器保存答案
answerSave: 'https://a6.qikekeji.com/txt/data/save',
// 文本服务器获取答案
answerSearch: 'https://api.answer.uu988.xyz/answer/search',
};
/**
* @description url配置
*/
const URL_CONFIG = {
// 主页
home: /^https\:\/\/www\.xuexi\.cn(\/(index\.html)?)?$/,
// 每日答题页面
examPractice: 'https://pc.xuexi.cn/points/exam-practice.html',
// 每周答题页面
examWeekly: 'https://pc.xuexi.cn/points/exam-weekly-detail.html',
// 专项练习页面
examPaper: 'https://pc.xuexi.cn/points/exam-paper-detail.html',
// 登录界面
login: 'https://login.xuexi.cn/login/xuexiWeb?appid=dingoankubyrfkttorhpou&goto=https%3A%2F%2Foa.xuexi.cn&type=1&state=ffdea2ded23f45ab%2FKQreTlDFe1Id3B7BVdaaYcTMp6lsTBB%2Fs3gGevuMKfvpbABDEl9ymG3bbOgtpSN&check_login=https%3A%2F%2Fpc-api.xuexi.cn',
};
/**
* @description 获取cookie
* @param name
* @returns
*/
function getCookie(name) {
// 获取当前所有cookie
const strCookies = document.cookie;
// 截取变成cookie数组
const cookieText = strCookies.split(';');
// 循环每个cookie
for (const i in cookieText) {
// 将cookie截取成两部分
const item = cookieText[i].split('=');
// 判断cookie的name 是否相等
if (item[0].trim() === name) {
return item[1].trim();
}
}
return null;
}
/**
* @description 防抖
* @param callback
* @param delay
* @returns
*/
function debounce(callback, delay) {
let timer = -1;
return function (...args) {
if (timer !== -1) {
clearTimeout(timer);
}
timer = setTimeout(() => {
callback.apply(this, args);
}, delay);
};
}
/**
* @description 选择器
* @param selector
* @returns
*/
function $$(selector, parent = document) {
return Array.from(parent.querySelectorAll(selector));
}
/**
* @description 打开新窗口
*/
function openWin(url) {
return GM_openInTab(url, {
active: true,
insert: true,
setParent: true,
});
}
/**
* @description 关闭子窗口
*/
function closeWin(frame, id) {
try {
if (frame) {
window.parent.postMessage({ id, closed: true }, 'https://www.xuexi.cn');
}
else {
window.opener = window;
const win = window.open('', '_self');
win?.close();
top?.close();
}
}
catch (e) { }
}
/**
* @description 等待窗口关闭
* @param newPage
* @returns
*/
function waitingClose(newPage) {
return new Promise((resolve) => {
const doing = setInterval(() => {
if (newPage.closed) {
clearInterval(doing); // 停止定时器
resolve('done');
}
}, 1000);
});
}
/**
* @description 等待时间
* @param time
* @returns
*/
function sleep(time) {
if (!Number.isInteger(time)) {
time = 1000;
}
return new Promise((resolve) => {
setTimeout(() => {
resolve('done');
}, time);
});
}
/**
* @description 判断是否为移动端
* @returns
*/
function hasMobile() {
let isMobile = false;
if (navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
console.log('移动端');
isMobile = true;
}
if (document.body.clientWidth < 800) {
console.log('小尺寸设备端');
isMobile = true;
}
return isMobile;
}
/**
* @description 创建元素节点
* @param eleName
* @param props
* @param attrs
* @param children
* @returns
*/
function createElementNode(tagName, props, attrs, children) {
// 创建普通元素
const ele = document.createElement(tagName);
// props属性设置
for (const key in props) {
if (props[key] instanceof Object) {
for (const subkey in props[key]) {
ele[key][subkey] = props[key][subkey];
}
}
else {
ele[key] = props[key];
}
}
// attrs属性设置
for (const key in attrs) {
// 属性值
const value = attrs[key];
// 处理完的key
const formatKey = key.toLowerCase();
// 特殊属性
const specificAttrs = ['checked', 'selected', 'disabled', 'enabled'];
// xlink命名空间
if (formatKey.startsWith('xlink:')) {
// xlink属性命名空间
const attrNS = 'http://www.w3.org/1999/xlink';
if (value) {
ele.setAttributeNS(attrNS, key, value);
}
else {
ele.removeAttributeNS(attrNS, key);
}
}
else if (formatKey.startsWith('on')) {
// 事件监听
const [, eventType] = key.toLowerCase().split('on');
// 事件类型
if (eventType) {
// 回调函数
if (value instanceof Function) {
ele.addEventListener(eventType, value);
// 回调函数数组
}
else if (value instanceof Array) {
for (const i in value) {
// 回调函数
if (value[i] instanceof Function) {
ele.addEventListener(eventType, value[i]);
}
}
}
}
}
else if (specificAttrs.includes(key)) {
if (value) {
ele.setAttribute(key, '');
}
else {
ele.removeAttribute(key);
}
}
else {
ele.setAttribute(key, value);
}
}
// 子节点
if (children) {
if (children instanceof Array) {
// 过滤
const filterEle = (children.filter((child) => child));
ele.append(...filterEle);
}
else {
if (children instanceof Promise) {
children.then((child) => child && ele.append(child));
}
else {
ele.append(children);
}
}
}
return ele;
}
/**
* @description 创建svg元素
* @param tagName
* @param props
* @param attrs
* @param children
* @returns
*/
function createNSElementNode(tagName, props, attrs, children) {
// svg元素命名空间
const ns = 'http://www.w3.org/2000/svg';
// 创建svg元素
const ele = document.createElementNS(ns, tagName);
// props属性设置
for (const key in props) {
if (props[key] instanceof Object) {
for (const subkey in props[key]) {
ele[key][subkey] = props[key][subkey];
}
}
else {
ele[key] = props[key];
}
}
// attrs属性设置
for (const key in attrs) {
// 属性值
const value = attrs[key];
// 处理完的key
const formatKey = key.toLowerCase();
// 特殊属性
const specificAttrs = ['checked', 'selected', 'disabled', 'enabled'];
// xlink命名空间
if (formatKey.startsWith('xlink:')) {
// xlink属性命名空间
const attrNS = 'http://www.w3.org/1999/xlink';
if (value) {
ele.setAttributeNS(attrNS, key, value);
}
else {
ele.removeAttributeNS(attrNS, key);
}
}
else if (formatKey.startsWith('on')) {
// 事件监听
const [, eventType] = key.toLowerCase().split('on');
// 事件类型
if (eventType) {
// 回调函数
if (value instanceof Function) {
ele.addEventListener(eventType, value);
// 回调函数数组
}
else if (value instanceof Array) {
for (const i in value) {
// 回调函数
if (value[i] instanceof Function) {
ele.addEventListener(eventType, value[i]);
}
}
}
}
}
else if (specificAttrs.includes(key)) {
if (value) {
ele.setAttribute(key, '');
}
else {
ele.removeAttribute(key);
}
}
else {
ele.setAttribute(key, value);
}
}
// 子节点
if (children) {
if (children instanceof Array) {
ele.append(...children);
}
else {
ele.append(children);
}
}
return ele;
}
/**
* @description 创建文字节点
* @param text
* @returns
*/
function createTextNode(text) {
return document.createTextNode(text);
}
/**
* @description 创建随机点
* @param bounds 范围
* @returns
*/
function createRandomPoint(bounds) {
// 范围
const { x, y, width, height } = bounds;
// 横坐标
const randX = x + Math.random() * width * 0.5 + width * 0.25;
// 纵坐标
const randY = y + Math.random() * height * 0.5 + height * 0.25;
return {
x: randX,
y: randY,
};
}
/**
* @description 生成随机路径
* @param start
* @param end
* @param steps
* @returns
*/
function createRandomPath(start, end, steps) {
// 最小水平增量
const minDeltaX = (end.x - start.x) / steps;
// 最大垂直增量
const maxDeltaY = (end.y - start.y) / steps;
const path = [];
// 开始节点
path.push(start);
// 插入点
for (let i = 0; i < steps; i++) {
// 横坐标
const x = path[i].x + Math.random() * 5 + minDeltaX;
// 纵坐标
const y = path[i].y +
Math.random() * 5 * Math.pow(-1, ~~(Math.random() * 2 + 1)) +
maxDeltaY;
path.push({
x,
y,
});
}
return path;
}
/**
* @description 随机数字
* @returns
*/
function generateNumAsChar() {
return (~~(Math.random() * 10)).toString();
}
/**
* @description 随机大写字母
* @returns
*/
function generateUpperAsChar() {
return String.fromCharCode(~~(Math.random() * 26) + 65);
}
/**
* @description 随机小写字母
* @returns
*/
function generateLowerAsChar() {
return String.fromCharCode(~~(Math.random() * 26) + 97);
}
/**
* @description 随机混合字符
* @param length
* @returns
*/
function generateMix(length = 6) {
// 随机字符串
const randomText = [];
// 生成器
const typeGenerator = [
generateNumAsChar,
generateUpperAsChar,
generateLowerAsChar,
];
if (length) {
for (let i = 0; i < length; i++) {
// 随机位置
const randomIndex = ~~(Math.random() * typeGenerator.length);
randomText.push(typeGenerator[randomIndex]());
}
}
return randomText.join('');
}
const css = '* { -webkit-tap-highlight-color: transparent;}:root { --themeColor: #fa3333; --scale: 1; font-size: calc(10px * var(--scale));}@media (max-height: 768px) { :root { --scale: 0.8; } .egg_panel { top: 2rem; }}@keyframes fade { from { opacity: 0.8; } to { opacity: 0.4; background: #ccc; }}.egg_icon { width: 1em; height: 1em; fill: currentColor;}.egg_hr_wrap { position: relative; display: flex; justify-content: center; color: #ccc;}.egg_hr_wrap .egg_hr { position: absolute; top: 50%; transform: translateY(-50%); background: currentColor; height: 0.1rem; width: 30%;}.egg_hr_wrap .egg_hr:nth-of-type(1) { left: 0;}.egg_hr_wrap .egg_hr:nth-last-of-type(1) { right: 0;}.egg_hr_title { font-size: 1.2rem;}.egg_exam_btn { transition: background-color 80ms; outline: none; border: none; padding: 1.2rem 2rem; border-radius: 1.2rem; cursor: pointer; font-size: 1.8rem; font-weight: bold; text-align: center; color: #ffffff; background: #666777;}.egg_exam_btn.manual { background: #e3484b;}.egg_panel { position: fixed; top: 5rem; left: 1rem; padding: 1.2rem 2rem; border-radius: 1rem; background: #ffffffe6; backdrop-filter: blur(1rem); box-shadow: 0 0 0.1rem 0.1rem #f1f1f1; transition: 80ms ease-out; z-index: 99999; color: #333;}.egg_panel.hide { left: 0; transform: translateX(-100%);}.egg_panel_wrap.mobile .egg_panel { top: 2rem;}.egg_panel button { outline: none; border: none; padding: 0; cursor: pointer; background: none;}.egg_panel .egg_btns_wrap { position: absolute; left: 100%; top: 50%; transform: translate(-50%, -50%); transition: 80ms ease;}.egg_panel.hide .egg_btns_wrap { left: 100%; transform: translate(0, -50%);}.egg_panel .egg_setting_show_btn,.egg_panel .egg_frame_show_btn { border-radius: 50%; width: 3rem; height: 3rem; padding: 0; overflow: hidden; border: 0.2rem solid currentColor; color: white; display: grid; place-items: center; font-size: 1.8rem;}.egg_panel.hide .egg_setting_show_btn { background: var(--themeColor);}.egg_panel .egg_setting_show_btn { background: #ccc;}.egg_panel .egg_frame_show_btn { background: var(--themeColor); margin-bottom: 1rem;}.egg_panel .egg_frame_show_btn.hide { display: none;}.egg_login_wrap .egg_login_btn,.egg_user_wrap .egg_login_btn { font-size: 1.4rem; border-radius: 1rem; transition: 80ms ease; color: white;}.egg_login_wrap .egg_login_btn:active,.egg_user_wrap .egg_login_btn:active { opacity: 0.8;}.egg_login_wrap .egg_login_btn { background: var(--themeColor); padding: 0.8rem 2.4rem;}.egg_user_wrap .egg_login_btn { background: #ccc; padding: 0.4rem 0.8rem;}.egg_login_wrap { display: flex; justify-content: center; align-items: center; flex-direction: column; padding: 0.5rem 0;}.egg_login_wrap .egg_login_frame_item { height: 0; overflow: hidden;}.egg_login_wrap .egg_login_frame_item.active { --rate: 0.75; margin-top: 0.8rem; height: calc(22.8rem * var(--rate)); width: calc(22.8rem * var(--rate));}.egg_login_frame_item.active .egg_login_frame_wrap { transform: scale(var(--rate)); transform-origin: top left; overflow: hidden; padding: 1rem; width: 22.8rem; height: 22.8rem; background: white; border-radius: 1rem;}.egg_login_frame_wrap { position: relative; box-sizing: border-box; margin: 0 auto;}.egg_login_frame { width: 284px; height: 241px; border: none; transform: scale(var(--scale)); transform-origin: top left; position: absolute; left: -6.4rem; top: -2.1rem;}.egg_user_wrap { display: flex; justify-content: space-between; align-items: center;}.egg_user_wrap .egg_userinfo { display: flex; justify-content: center; align-items: center; padding: 0.5rem 0;}.egg_userinfo .egg_avatar .egg_sub_nickname,.egg_userinfo .egg_avatar .egg_avatar_img { height: 5rem; width: 5rem; border-radius: 50%; background: var(--themeColor); display: flex; justify-content: center; align-items: center; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; font-size: 2rem; color: white;}.egg_userinfo .egg_nick { padding-left: 0.5rem; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; max-width: 10rem; font-size: 1.6rem;}.egg_score_item .egg_scoreinfo { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0;}.egg_scoreinfo .egg_totalscore,.egg_scoreinfo .egg_todayscore { font-size: 1.2rem; user-select: none;}.egg_scoreinfo .egg_totalscore span,.egg_scoreinfo .egg_todayscore .egg_todayscore_btn span { padding-left: 0.2rem;}.egg_scoreinfo .egg_totalscore span,.egg_todayscore .egg_todayscore_btn span,.egg_todayscore .egg_score_details span { color: var(--themeColor); font-weight: bold;}.egg_scoreinfo .egg_todayscore { position: relative;}.egg_todayscore .egg_todayscore_btn { display: flex; align-items: center;}.egg_todayscore_btn .egg_icon { opacity: 0.3;}.egg_todayscore .egg_score_details { position: absolute; left: calc(100% + 1rem); top: 0; background: #fffffff2; border-radius: 0.5rem; opacity: 1; width: 10rem; box-shadow: 0 0 0.1rem 0.1rem #f1f1f1; transition: 80ms ease; z-index: 9;}.egg_todayscore .egg_score_details.hide { visibility: hidden; opacity: 0; left: 100%;}.egg_score_details .egg_score_title { border-bottom: 0.1rem solid #eee; padding: 0.5rem 0.8rem; display: flex; align-items: center;}.egg_score_details .egg_score_title .egg_icon { font-size: 1.4rem;}.egg_score_details .egg_score_title .egg_score_title_text { font-weight: bold; padding-left: 0.2rem;}.egg_score_details .egg_score_item { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.8rem;}.egg_setting_item { min-height: 3rem; min-width: 18rem; font-size: 1.6rem; display: flex; align-items: center; justify-content: space-between;}.egg_setting_item .egg_label_wrap { flex-grow: 1;}.egg_label_wrap .egg_progress { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0;}.egg_progress .egg_track { background: #ccc; height: 0.5rem; border-radius: 1rem; flex: 1 1 auto; overflow: hidden;}.egg_progress .egg_track .egg_bar { height: 0.5rem; background: var(--themeColor); border-radius: 1rem; width: 0; transition: width 0.5s;}.egg_progress .egg_percent { font-size: 1.2rem; padding-left: 0.5rem; width: 4rem;}.egg_detail { background: #ccc; color: white; border-radius: 10rem; font-size: 1.2rem; width: 1.6rem; height: 1.6rem; margin-left: 0.4rem; display: inline-block; text-align: center; line-height: 1.6rem; cursor: pointer;}.egg_switch { cursor: pointer; margin: 0; outline: 0; appearance: none; -webkit-appearance: none; -moz-appearance: none; position: relative; width: 4.2rem; height: 2.2rem; background: #ccc; border-radius: 5rem; transition: background 0.3s; --border-padding: 0.5rem; box-shadow: -0.1rem 0 0.1rem -0.1rem #999 inset, 0.1rem 0 0.1rem -0.1rem #999 inset;}.egg_switch::after { content: \'\'; display: inline-block; width: 1.4rem; height: 1.4rem; border-radius: 50%; background: #fff; box-shadow: 0 0 0.2rem #999; transition: 0.4s; position: absolute; top: calc(50% - (1.4rem / 2)); position: absolute; left: var(--border-padding);}.egg_switch:checked { background: var(--themeColor);}.egg_switch:checked::after { left: calc(100% - var(--border-padding) - 1.4rem);}.egg_study_item { display: flex; justify-content: center;}.egg_study_item .egg_study_btn { background: var(--themeColor); padding: 0.8rem 2.4rem; font-size: 1.4rem; border-radius: 1rem; color: white; transition: 80ms ease;}.egg_study_item .egg_study_btn:active { opacity: 0.8;}.egg_study_item .egg_study_btn.loading { animation: fade 2s ease infinite alternate;}.egg_study_item .egg_study_btn.disabled { background: #ccc;}.egg_tip_wrap { position: fixed; left: 0; top: 0; z-index: 999999; width: 100%; height: 100%; pointer-events: none;}.egg_tip_wrap .egg_tip { position: absolute; bottom: 2rem; left: 2rem; padding: 1.2rem 1.4rem; border: none; border-radius: 1rem; background: var(--themeColor); color: white; font-size: 1.4rem; transition: 200ms ease; opacity: 0; transform: scale(0.9) translateY(1rem);}.egg_tip_wrap .egg_tip.active { opacity: 1; transform: scale(1) translateY(0);}.egg_tip_wrap .egg_tip .egg_countdown { display: inline-block; color: var(--themeColor); background: white; border-radius: 0.5rem; padding: 0.2rem 0.4rem; font-weight: bold; margin-left: 0.4rem; font-size: 1.2rem;}.egg_frame_wrap { position: fixed; left: 0; top: 0; z-index: 999; width: 100%; height: 100%; visibility: visible;}.egg_frame_wrap.hide { visibility: hidden;}.egg_frame_wrap.hide .egg_frame_mask,.egg_frame_wrap.hide .egg_frame_content_wrap { opacity: 0;}.egg_frame_wrap.hide .egg_frame_content_wrap { transform: scale(0);}.egg_frame_mask { background: #00000030; width: 100%; height: 100%; opacity: 1; transition: 200ms ease;}.egg_frame_content_wrap { position: absolute; width: 80%; height: 80%; top: 10%; left: 10%; display: flex; flex-direction: column; transition: 200ms ease; border-radius: 1rem; background: #ffffffe6; backdrop-filter: blur(1rem); overflow: hidden; transform: scale(1);}.egg_frame_content_wrap.max { top: 0; left: 0; width: 100%; height: 100%; border-radius: 0;}.egg_frame_content_wrap .egg_frame_controls_wrap { width: 100%; display: flex; justify-content: space-between; align-items: center; box-sizing: border-box;}.egg_frame_controls_wrap .egg_frame_title { padding: 1rem 2rem; font-size: 1.6rem;}.egg_frame_controls .egg_frame_btn { outline: none; border: none; background: none; padding: 1rem 2rem; transition: 80ms ease; cursor: pointer; color: #333; font-size: 1.8rem;}.egg_frame_controls .egg_frame_btn:active { opacity: 0.8;}.egg_frame_wrap .egg_frame_content { width: 100%; flex-grow: 1; border-top: 1px solid #ccc; min-height: 40rem; min-width: 30rem;}.egg_frame_content .egg_frame { width: 100%; height: 100%; outline: none; border: none;}';
/**
* @description 嵌入样式
*/
GM_addStyle(css);
/* Config·配置 */
/**
* @description 每周答题开启逆序答题: false: 顺序答题; true: 逆序答题
*/
const examWeeklyReverse = true;
/**
* @description 专项答题开启逆序答题: false: 顺序答题; true: 逆序答题
*/
const examPaperReverse = true;
/**
* @description 答题请求速率限制
*/
const ratelimitms = 3000;
/**
* @description 单次最大新闻数
*/
const maxNewsNum = 6;
/**
* @description 单次最大视频数
*/
const maxVideoNum = 6;
/* Config End·配置结束 */
/* Tools·工具函数 */
/**
* @description 暂停锁
*/
function pauseLock(callback) {
return new Promise((resolve) => {
// 学习暂停
const pauseStudy = (GM_getValue('pauseStudy') || false);
if (pauseStudy) {
pauseExam(pauseStudy);
}
if (pause) {
const doing = setInterval(() => {
if (!pause) {
// 停止定时器
clearInterval(doing);
console.log('答题等待结束!');
if (callback && callback instanceof Function) {
callback('done');
}
resolve('done');
return;
}
if (callback && callback instanceof Function) {
callback('pending');
}
console.log('答题等待...');
}, 500);
return;
}
resolve('done');
});
}
/**
* @description 暂停学习锁
*/
function pauseStudyLock(callback) {
return new Promise((resolve) => {
// 暂停
const pauseStudy = GM_getValue('pauseStudy') || false;
if (pauseStudy) {
const doing = setInterval(() => {
// 暂停
const pauseStudy = GM_getValue('pauseStudy') || false;
if (!pauseStudy) {
// 停止定时器
clearInterval(doing);
console.log('学习等待结束!');
if (callback && callback instanceof Function) {
callback('done');
}
resolve('done');
return;
}
if (callback && callback instanceof Function) {
callback('pending');
}
console.log('学习等待...');
}, 500);
return;
}
resolve('done');
});
}
/* Tools End·工具函数结束 */
/* API请求函数 */
/**
* @description 获取用户信息
*/
async function getUserInfo() {
try {
const res = await fetch(API_CONFIG.userInfo, {
method: 'GET',
credentials: 'include',
});
// 请求成功
if (res.ok) {
const { data } = await res.json();
return data;
}
}
catch (err) { }
}
/**
* @description 获取总积分
*/
async function getTotalScore() {
try {
const res = await fetch(API_CONFIG.totalScore, {
method: 'GET',
credentials: 'include',
});
// 请求成功
if (res.ok) {
const { data } = await res.json();
// 总分
const { score } = data;
return score;
}
}
catch (err) { }
}
/**
* @description 获取当天总积分
*/
async function getTodayScore() {
try {
const res = await fetch(API_CONFIG.todayScore, {
method: 'GET',
credentials: 'include',
});
// 请求成功
if (res.ok) {
const { data } = await res.json();
// 当天总分
const { score } = data;
return score;
}
}
catch (err) { }
}
/**
* @description 获取任务列表
*/
async function getTaskList() {
try {
const res = await fetch(API_CONFIG.taskList, {
method: 'GET',
credentials: 'include',
});
// 请求成功
if (res.ok) {
const { data } = await res.json();
// 进度和当天总分
const { taskProgress } = data;
return taskProgress;
}
}
catch (err) { }
}
/**
* @description 获取新闻数据
*/
async function getTodayNews() {
// 随机
const randNum = ~~(Math.random() * API_CONFIG.todayNews.length);
try {
// 获取重要新闻
const res = await fetch(API_CONFIG.todayNews[randNum], {
method: 'GET',
});
// 请求成功
if (res.ok) {
const data = await res.json();
return data;
}
}
catch (err) { }
}
/**
* @description 获取视频数据
*/
async function getTodayVideos() {
// 随机
const randNum = ~~(Math.random() * API_CONFIG.todayVideos.length);
try {
// 获取重要新闻
const res = await fetch(API_CONFIG.todayVideos[randNum], {
method: 'GET',
});
// 请求成功
if (res.ok) {
const data = await res.json();
return data;
}
}
catch (err) { }
}
/**
* @description 专项练习数据
*/
async function getExamPaper(pageNo) {
// 链接
const url = `${API_CONFIG.paperList}?pageSize=50&pageNo=${pageNo}`;
try {
// 获取专项练习
const res = await fetch(url, {
method: 'GET',
credentials: 'include',
});
// 请求成功
if (res.ok) {
const data = await res.json();
const paperJson = decodeURIComponent(escape(window.atob(data.data_str.replace(/-/g, '+').replace(/_/g, '/'))));
// JSON格式化
const paper = JSON.parse(paperJson);
return paper;
}
}
catch (err) {
return [];
}
return [];
}
/**
* @description 每周答题数据
*/
async function getExamWeekly(pageNo) {
// 链接
const url = `${API_CONFIG.weeklyList}?pageSize=50&pageNo=${pageNo}`;
try {
// 获取每周答题
const res = await fetch(url, {
method: 'GET',
credentials: 'include',
});
// 请求成功
if (res.ok) {
const data = await res.json();
const paperJson = decodeURIComponent(escape(window.atob(data.data_str.replace(/-/g, '+').replace(/_/g, '/'))));
// JSON格式化
const paper = JSON.parse(paperJson);
return paper;
}
}
catch (err) {
return [];
}
return [];
}
/**
* @description 获取答案
*/
async function getAnswer(question) {
console.log('正在获取网络答案...');
// 数据
const data = {
question,
};
try {
// 请求
const res = await fetch(API_CONFIG.answerSearch, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
// 请求成功
if (res.ok) {
const data = await res.json();
// 状态
const { errno } = data;
if (errno !== -1) {
// 答案
const { answers } = data.data;
console.log('answers', answers);
return answers;
}
}
}
catch (error) { }
console.log('获取网络答案失败!');
return [];
}
/**
* @description 保存答案
*/
async function saveAnswer(key, value) {
// 内容
const content = JSON.stringify([{ title: key, content: value }]);
// 数据
const data = {
txt_name: key,
txt_content: content,
password: '',
v_id: '',
};
// 请求体
const body = Object.keys(data)
.map((key) => {
return `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`;
})
.join('&');
// 请求
const res = await fetch(API_CONFIG.answerSave, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
body,
});
// 请求成功
if (res.ok) {
try {
const data = await res.json();
return data;
}
catch (err) {
return null;
}
}
return null;
}
/* API请求函数结束 */
/* 变量 */
/**
* @description 任务进度
*/
const tasks = [
{
title: '文章选读',
currentScore: 0,
dayMaxScore: 0,
need: 0,
status: false,
tip: '每有效阅读一篇文章积1分,上限6分。有效阅读文章累计1分钟积1分,上限6分。每日上限积12分。',
},
{
title: '视听学习',
currentScore: 0,
dayMaxScore: 0,
need: 0,
status: false,
tip: '每有效一个音频或观看一个视频积1分,上限6分。有效收听音频或观看视频累计1分钟积1分,上限6分。每日上限积12分。',
},
{
title: '每日答题',
currentScore: 0,
dayMaxScore: 0,
need: 0,
status: false,
tip: '每组答题每答对1道积1分。每日上限积5分。',
},
{
title: '每周答题',
currentScore: 0,
dayMaxScore: 0,
need: 0,
status: false,
tip: '每组答题每答对1道积1分,同组答题不重复积分。每日上限积5分。',
},
{
title: '专项练习',
currentScore: 0,
dayMaxScore: 0,
need: 0,
status: false,
tip: '每组答题每答对1道积1分,同组答题不重复积分;每日仅可获得一组答题积分,5道题一组的上限5分,10道题一组的上限10分。',
},
];
/**
* @description 获取 URL
*/
const { href } = window.location;
/**
* @description 设置
*/
let settings = [
true,
true,
true,
true,
true,
false,
false,
false,
false,
false,
false,
];
/**
* @description 已经开始
*/
let started = false;
/**
* @description 是否暂停答题
*/
let pause = false;
/**
* @description 初始化登录状态
*/
let login = !!getCookie('token');
/**
* @description 新闻
*/
let news = [];
/**
* @description 视频
*/
let videos = [];
/**
* @description 登录定时器
*/
let loginTimer;
/**
* @description frame 关闭
*/
let closed = true;
/**
* @description id
*/
let id;
/* 变量结束 */
/* 组件化 */
/**
* @description 分隔符
* @returns
*/
function Hr({ text }) {
return createElementNode('div', undefined, {
class: 'egg_hr_wrap',
}, [
createElementNode('div', undefined, { class: 'egg_hr' }),
createElementNode('div', undefined, { class: 'egg_hr_title' }, createTextNode(text)),
createElementNode('div', undefined, { class: 'egg_hr' }),
]);
}
/**
* @description 设置任务项
* @returns
*/
function TaskItem({ title, tip, checked, onChange, }) {
return createElementNode('div', undefined, { class: 'egg_setting_item' }, [
createElementNode('div', undefined, { class: 'egg_label_wrap' }, [
createElementNode('label', undefined, { class: 'egg_task_title' }, createTextNode(title)),
createElementNode('div', undefined, { class: 'egg_progress' }, [
createElementNode('div', undefined, { class: 'egg_track' }, createElementNode('div', undefined, { class: 'egg_bar' })),
createElementNode('div', undefined, { class: 'egg_percent' }, [
createElementNode('span', undefined, undefined, [createTextNode(0)]),
createTextNode('%'),
]),
]),
]),
createElementNode('input', undefined, {
title: tip,
class: 'egg_switch',
type: 'checkbox',
checked,
onChange,
}),
]);
}
/**
* @description 设置普通项
* @returns
*/
function NomalItem({ title, tip, checked, onChange, }) {
return createElementNode('div', undefined, { class: 'egg_setting_item' }, [
createElementNode('div', undefined, { class: 'egg_label_wrap' }, [
createElementNode('label', undefined, { class: 'egg_task_title' }, [
createTextNode(title),
createElementNode('span', undefined, {
class: 'egg_detail',
title: tip,
}, createTextNode('i')),
]),
]),
createElementNode('input', undefined, {
title: tip,
class: 'egg_switch',
type: 'checkbox',
checked,
onChange,
}),
]);
}
/**
* @description 信息
* @returns
*/
async function Info({ login }) {
if (login) {
// 用户信息
const userInfo = await getUserInfo();
if (userInfo) {
const { avatarMediaUrl, nick } = userInfo;
return createElementNode('div', undefined, {
class: 'egg_user_wrap',
}, [
// 用户信息
createElementNode('div', undefined, { class: 'egg_userinfo' }, [
// 头像
createElementNode('div', undefined, { class: 'egg_avatar' }, avatarMediaUrl
? createElementNode('img', undefined, {
src: avatarMediaUrl,
class: 'egg_avatar_img',
})
: createElementNode('div', undefined, {
class: 'egg_sub_nickname',
}, createTextNode(nick.substring(1, 3)))),
// 昵称
createElementNode('div', { innerText: nick }, { class: 'egg_nick' }),