11// ==UserScript==
22// @name 不学习何以强国-beta
33// @namespace http://tampermonkey.net/
4- // @version 20211216
4+ // @version 20211221
55// @description 问题反馈位置: https://github.com/TechXueXi/techxuexi-js/issues 。读文章,看视频,做习题。
66// @author techxuexi ,荷包蛋。
77// @match https://www.xuexi.cn
@@ -61,10 +61,14 @@ var pause = false;//是否暂停答题
6161var examWeeklyPageNo = 1 ;
6262//每周答题总页码
6363var examWeeklyTotalPageCount = null ;
64+ //每周答题开启逆序答题: false: 顺序答题; true: 逆序答题
65+ var examWeeklyReverse = false ;
6466//专项答题当前页码
6567var examPaperPageNo = 1 ;
6668//专项答题总页码
6769var examPaperTotalPageCount = null ;
70+ //专项答题开启逆序答题: false: 顺序答题; true: 逆序答题
71+ var examPaperReverse = false ;
6872//每周答题,专项答题 请求rate 限制 每 3000ms 一次
6973const ratelimitms = 3000 ;
7074$ ( document ) . ready ( function ( ) {
@@ -145,8 +149,8 @@ $(document).ready(function () {
145149 } else {
146150 }
147151} ) ;
148-
149-
152+
153+
150154//获取video标签
151155function getVideoTag ( ) {
152156 let iframe = document . getElementsByTagName ( "iframe" ) [ 0 ] ;
@@ -166,7 +170,7 @@ function getVideoTag() {
166170 "pauseButton" : pauseButton
167171 }
168172}
169-
173+
170174//读新闻或者看视频
171175//type:0为新闻,1为视频
172176async function reading ( type ) {
@@ -353,12 +357,26 @@ function doExamPractice() {
353357 } , 1000 ) ;
354358 } ) ;
355359}
356- //获取专项答题列表
357- function getExamPaper ( ) {
360+
361+ //初始化专项答题总页数属性
362+ async function InitExamPaperAttr ( ) {
363+ var data = await getExamPaperByPageNo ( 1 ) ; // 默认从第一页获取全部页属性
364+ if ( data ) {
365+ // 初始化总页码
366+ examPaperTotalPageCount = data . totalPageCount ;
367+ // 若专项答题逆序, 则从最后一页开始
368+ if ( examPaperReverse ) {
369+ examPaperPageNo = examPaperTotalPageCount ;
370+ }
371+ }
372+ }
373+
374+ //获取指定页数的专项答题列表
375+ function getExamPaperByPageNo ( examPaperPageNoParam ) {
358376 return new Promise ( function ( resolve ) {
359377 $ . ajax ( {
360378 type : "GET" ,
361- url : ExamPaperListUrl . replace ( "{pageNo}" , examPaperPageNo ) ,
379+ url : ExamPaperListUrl . replace ( "{pageNo}" , examPaperPageNoParam ) ,
362380 xhrFields : {
363381 withCredentials : true //如果没有这个请求失败
364382 } ,
@@ -375,21 +393,25 @@ function getExamPaper() {
375393 } ) ;
376394 } )
377395}
396+
378397//查询专项答题列表看看还有没有没做过的,有则返回id
379398async function findExamPaper ( ) {
380399 var continueFind = true ;
381400 var examPaperId = null ;
382- console . log ( "正在寻找未完成的专项答题" )
401+ console . log ( "初始化专项答题属性" ) ;
402+ await InitExamPaperAttr ( ) ;
403+ console . log ( "正在寻找未完成的专项答题" ) ;
383404 while ( continueFind ) {
384405 let startTime = Date . now ( ) ;
385-
386- await getExamPaper ( ) . then ( async ( data ) => {
406+
407+ await getExamPaperByPageNo ( examPaperPageNo ) . then ( async ( data ) => {
387408 if ( data ) {
388- if ( examPaperTotalPageCount == null ) {
389- //如果总页码没初始化,则初始化
390- examPaperTotalPageCount = data . totalPageCount ;
391- }
392409 let examPapers = data . list ; //获取专项答题的列表
410+ if ( examPaperReverse ) {
411+ // 若开启逆序答题, 则反转专项答题列表
412+ console . log ( "专项答题,开启逆序模式,从最早的题目开始答题" ) ;
413+ examPapers . reverse ( ) ;
414+ }
393415 for ( let j = 0 ; j < examPapers . length ; j ++ ) {
394416 //遍历查询有没有没做过的
395417 if ( examPapers [ j ] . status != 2 ) { //status: 1为"开始答题" , 2为"重新答题"
@@ -401,17 +423,19 @@ async function findExamPaper() {
401423 }
402424 if ( ! continueFind ) {
403425 } else {
404- //增加页码
405- examPaperPageNo ++ ;
406- if ( examPaperTotalPageCount == null || examPaperPageNo > examPaperTotalPageCount ) {
426+ //增加页码 (若开启逆序翻页, 则减少页码)
427+ examPaperPageNo += examPaperReverse ? - 1 : 1 ;
428+ if ( examPaperTotalPageCount == null
429+ || examPaperPageNo > examPaperTotalPageCount
430+ || examPaperPageNo < 1 ) {
407431 //已经找完所有页码,还是没找到,不再继续查找
408432 continueFind = false ;
409433 }
410434 }
411435 } else {
412436 continueFind = false ;
413437 }
414-
438+
415439 //fix code = 429
416440 let remainms = Date . now ( ) - startTime ;
417441 if ( remainms < ratelimitms ) {
@@ -442,12 +466,26 @@ function doExamPaper() {
442466 } ) ;
443467 } )
444468}
445- //获取每周答题列表
446- function getExamWeekly ( ) {
469+
470+ //初始化每周答题总页数属性
471+ async function InitExamWeeklyAttr ( ) {
472+ var data = await getExamWeeklyByPageNo ( 1 ) ; // 默认从第一页获取全部页属性
473+ if ( data ) {
474+ // 初始化总页码
475+ examWeeklyTotalPageCount = data . totalPageCount ;
476+ // 若每周答题逆序, 则从最后一页开始
477+ if ( examWeeklyReverse ) {
478+ examWeeklyPageNo = examWeeklyTotalPageCount ;
479+ }
480+ }
481+ }
482+
483+ //获取指定页数的每周答题列表
484+ function getExamWeeklyByPageNo ( examWeeklyPageNoParam ) {
447485 return new Promise ( function ( resolve ) {
448486 $ . ajax ( {
449487 type : "GET" ,
450- url : ExamWeeklyListUrl . replace ( "{pageNo}" , examWeeklyPageNo ) ,
488+ url : ExamWeeklyListUrl . replace ( "{pageNo}" , examWeeklyPageNoParam ) ,
451489 xhrFields : {
452490 withCredentials : true //如果没有这个请求失败
453491 } ,
@@ -464,21 +502,29 @@ function getExamWeekly() {
464502 } ) ;
465503 } )
466504}
505+
467506//查询每周答题列表看看还有没有没做过的,有则返回id
468507async function findExamWeekly ( ) {
469508 var continueFind = true ;
470509 var examWeeklyId = null ;
471- console . log ( "正在寻找未完成的每周答题" )
510+ console . log ( "初始化每周答题" ) ;
511+ await InitExamWeeklyAttr ( ) ;
512+ console . log ( "正在寻找未完成的每周答题" ) ;
472513 while ( continueFind ) {
473514 let startTime = Date . now ( ) ;
474- await getExamWeekly ( ) . then ( async ( data ) => {
515+ await getExamWeeklyByPageNo ( examWeeklyPageNo ) . then ( async ( data ) => {
475516 if ( data ) {
476- if ( examWeeklyTotalPageCount == null ) {
477- //如果总页码没初始化,则初始化
478- examWeeklyTotalPageCount = data . totalPageCount ;
517+ if ( examWeeklyReverse ) {
518+ // 若开启逆序答题, 则反转列表
519+ console . log ( "每周答题,开启逆序模式,从最早的题目开始答题" ) ;
520+ data . list . reverse ( ) ;
479521 }
480522 for ( let i = 0 ; i < data . list . length ; i ++ ) {
481523 let examWeeks = data . list [ i ] . practices ; //获取每周的测试列表
524+ if ( examWeeklyReverse ) {
525+ // 若开启逆序, 则反转每周的测试列表
526+ examWeeks . reverse ( ) ;
527+ }
482528 for ( let j = 0 ; j < examWeeks . length ; j ++ ) {
483529 //遍历查询有没有没做过的
484530 if ( examWeeks [ j ] . status != 2 ) { //status: 1为"开始答题" , 2为"重新答题"
@@ -496,16 +542,18 @@ async function findExamWeekly() {
496542 if ( ! continueFind ) {
497543 } else {
498544 //增加页码
499- examWeeklyPageNo ++ ;
500- if ( examWeeklyTotalPageCount == null || examWeeklyPageNo > examWeeklyTotalPageCount ) {
545+ examWeeklyPageNo += examWeeklyReverse ? - 1 : 1 ;
546+ if ( examWeeklyTotalPageCount == null
547+ || examWeeklyPageNo > examWeeklyTotalPageCount
548+ || examWeeklyPageNo < 1 ) {
501549 //已经找完所有页码,还是没找到,不再继续查找
502550 continueFind = false ;
503551 }
504552 }
505553 } else {
506554 continueFind = false ;
507555 }
508-
556+
509557 //fix code = 429
510558 let remainms = Date . now ( ) - startTime ;
511559 if ( remainms < ratelimitms ) {
@@ -982,7 +1030,7 @@ async function start() {
9821030 taskProgress = await getToday ( ) ;
9831031 if ( taskProgress != null ) {
9841032 console . log ( "开始学习" )
985-
1033+
9861034 //检查新闻
9871035 if ( settings [ 0 ] && taskProgress [ 0 ] . currentScore != taskProgress [ 0 ] . dayMaxScore ) {
9881036 tasks [ 0 ] = false ; //只要还有要做的,就当做没完成
@@ -992,7 +1040,7 @@ async function start() {
9921040 } else {
9931041 tasks [ 0 ] = true ;
9941042 }
995-
1043+
9961044 //检查视频
9971045 let temp = parseInt ( taskProgress [ 1 ] . dayMaxScore - taskProgress [ 1 ] . currentScore ) ;
9981046 let temp2 = parseInt ( taskProgress [ 3 ] . dayMaxScore - taskProgress [ 3 ] . currentScore ) ;
@@ -1004,7 +1052,7 @@ async function start() {
10041052 } else {
10051053 tasks [ 1 ] = true ;
10061054 }
1007-
1055+
10081056 //检查每日答题
10091057 if ( settings [ 6 ] && taskProgress [ 6 ] . currentScore != taskProgress [ 6 ] . dayMaxScore ) {
10101058 tasks [ 2 ] = false ; //只要还有要做的,就当做没完成
@@ -1013,7 +1061,7 @@ async function start() {
10131061 } else {
10141062 tasks [ 2 ] = true ;
10151063 }
1016-
1064+
10171065 //检查每周答题
10181066 if ( settings [ 2 ] && taskProgress [ 2 ] . currentScore == 0 ) {
10191067 tasks [ 3 ] = false ; //只要还有要做的,就当做没完成
@@ -1026,7 +1074,7 @@ async function start() {
10261074 } else {
10271075 tasks [ 3 ] = true ;
10281076 }
1029-
1077+
10301078 //检查专项练习
10311079 if ( settings [ 5 ] && taskProgress [ 5 ] . currentScore == 0 ) {
10321080 tasks [ 4 ] = false ; //只要还有要做的,就当做没完成
@@ -1039,7 +1087,7 @@ async function start() {
10391087 } else {
10401088 tasks [ 4 ] = true ;
10411089 }
1042-
1090+
10431091 if ( tasks [ 0 ] && tasks [ 1 ] && tasks [ 2 ] && tasks [ 3 ] && tasks [ 4 ] ) {
10441092 //如果检查都做完了,就不用继续了
10451093 continueToDo = false ;
0 commit comments