From e0f1327e3fb6986158619cb9f7101656c4e91bae Mon Sep 17 00:00:00 2001 From: kira <96469945+kirakira2021@users.noreply.github.com> Date: Tue, 21 Dec 2021 18:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=80=92=E5=BA=8F=E7=AD=94?= =?UTF-8?q?=E9=A2=98=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- techxuexi-js/version_info.json | 5 +- ...25\344\273\245\345\274\272\345\233\275.js" | 118 ++++++++++++------ 2 files changed, 87 insertions(+), 36 deletions(-) diff --git a/techxuexi-js/version_info.json b/techxuexi-js/version_info.json index 2c6717b..c952d31 100644 --- a/techxuexi-js/version_info.json +++ b/techxuexi-js/version_info.json @@ -1,5 +1,5 @@ { - "techxuexi_js_version": "v20211015", + "techxuexi_js_version": "v20211221", "notice": "...", "techxuexi_js_update_log": [{ "version": "v20211015", @@ -10,5 +10,8 @@ },{ "version": "v20211216", "info": "修复?" + },{ + "version": "v20211221", + "info": "增加倒序答题配置" }] } diff --git "a/\344\270\215\345\255\246\344\271\240\344\275\225\344\273\245\345\274\272\345\233\275.js" "b/\344\270\215\345\255\246\344\271\240\344\275\225\344\273\245\345\274\272\345\233\275.js" index 5718bff..ce4a295 100644 --- "a/\344\270\215\345\255\246\344\271\240\344\275\225\344\273\245\345\274\272\345\233\275.js" +++ "b/\344\270\215\345\255\246\344\271\240\344\275\225\344\273\245\345\274\272\345\233\275.js" @@ -1,7 +1,7 @@ // ==UserScript== // @name 不学习何以强国-beta // @namespace http://tampermonkey.net/ -// @version 20211216 +// @version 20211221 // @description 问题反馈位置: https://github.com/TechXueXi/techxuexi-js/issues 。读文章,看视频,做习题。 // @author techxuexi ,荷包蛋。 // @match https://www.xuexi.cn @@ -61,10 +61,14 @@ var pause = false;//是否暂停答题 var examWeeklyPageNo = 1; //每周答题总页码 var examWeeklyTotalPageCount = null; +//每周答题开启逆序答题: false: 顺序答题; true: 逆序答题 +var examWeeklyReverse = false; //专项答题当前页码 var examPaperPageNo = 1; //专项答题总页码 var examPaperTotalPageCount = null; +//专项答题开启逆序答题: false: 顺序答题; true: 逆序答题 +var examPaperReverse = false; //每周答题,专项答题 请求rate 限制 每 3000ms 一次 const ratelimitms = 3000; $(document).ready(function () { @@ -145,8 +149,8 @@ $(document).ready(function () { } else { } }); - - + + //获取video标签 function getVideoTag() { let iframe = document.getElementsByTagName("iframe")[0]; @@ -166,7 +170,7 @@ function getVideoTag() { "pauseButton": pauseButton } } - + //读新闻或者看视频 //type:0为新闻,1为视频 async function reading(type) { @@ -353,12 +357,26 @@ function doExamPractice() { }, 1000); }); } -//获取专项答题列表 -function getExamPaper() { + +//初始化专项答题总页数属性 +async function InitExamPaperAttr() { + var data = await getExamPaperByPageNo(1); // 默认从第一页获取全部页属性 + if (data) { + // 初始化总页码 + examPaperTotalPageCount = data.totalPageCount; + // 若专项答题逆序, 则从最后一页开始 + if (examPaperReverse) { + examPaperPageNo = examPaperTotalPageCount; + } + } +} + +//获取指定页数的专项答题列表 +function getExamPaperByPageNo(examPaperPageNoParam) { return new Promise(function (resolve) { $.ajax({ type: "GET", - url: ExamPaperListUrl.replace("{pageNo}", examPaperPageNo), + url: ExamPaperListUrl.replace("{pageNo}", examPaperPageNoParam), xhrFields: { withCredentials: true //如果没有这个请求失败 }, @@ -375,21 +393,25 @@ function getExamPaper() { }); }) } + //查询专项答题列表看看还有没有没做过的,有则返回id async function findExamPaper() { var continueFind = true; var examPaperId = null; - console.log("正在寻找未完成的专项答题") + console.log("初始化专项答题属性"); + await InitExamPaperAttr(); + console.log("正在寻找未完成的专项答题"); while (continueFind) { let startTime = Date.now(); - - await getExamPaper().then(async (data) => { + + await getExamPaperByPageNo(examPaperPageNo).then(async (data) => { if (data) { - if (examPaperTotalPageCount == null) { - //如果总页码没初始化,则初始化 - examPaperTotalPageCount = data.totalPageCount; - } let examPapers = data.list;//获取专项答题的列表 + if (examPaperReverse) { + // 若开启逆序答题, 则反转专项答题列表 + console.log("专项答题,开启逆序模式,从最早的题目开始答题"); + examPapers.reverse(); + } for (let j = 0; j < examPapers.length; j++) { //遍历查询有没有没做过的 if (examPapers[j].status != 2) {//status: 1为"开始答题" , 2为"重新答题" @@ -401,9 +423,11 @@ async function findExamPaper() { } if (!continueFind) { } else { - //增加页码 - examPaperPageNo++; - if (examPaperTotalPageCount == null || examPaperPageNo > examPaperTotalPageCount) { + //增加页码 (若开启逆序翻页, 则减少页码) + examPaperPageNo += examPaperReverse ? -1 : 1; + if (examPaperTotalPageCount == null + || examPaperPageNo > examPaperTotalPageCount + || examPaperPageNo < 1) { //已经找完所有页码,还是没找到,不再继续查找 continueFind = false; } @@ -411,7 +435,7 @@ async function findExamPaper() { } else { continueFind = false; } - + //fix code = 429 let remainms = Date.now() - startTime; if (remainms < ratelimitms) { @@ -442,12 +466,26 @@ function doExamPaper() { }); }) } -//获取每周答题列表 -function getExamWeekly() { + +//初始化每周答题总页数属性 +async function InitExamWeeklyAttr() { + var data = await getExamWeeklyByPageNo(1); // 默认从第一页获取全部页属性 + if (data) { + // 初始化总页码 + examWeeklyTotalPageCount = data.totalPageCount; + // 若每周答题逆序, 则从最后一页开始 + if (examWeeklyReverse) { + examWeeklyPageNo = examWeeklyTotalPageCount; + } + } +} + +//获取指定页数的每周答题列表 +function getExamWeeklyByPageNo(examWeeklyPageNoParam) { return new Promise(function (resolve) { $.ajax({ type: "GET", - url: ExamWeeklyListUrl.replace("{pageNo}", examWeeklyPageNo), + url: ExamWeeklyListUrl.replace("{pageNo}", examWeeklyPageNoParam), xhrFields: { withCredentials: true //如果没有这个请求失败 }, @@ -464,21 +502,29 @@ function getExamWeekly() { }); }) } + //查询每周答题列表看看还有没有没做过的,有则返回id async function findExamWeekly() { var continueFind = true; var examWeeklyId = null; - console.log("正在寻找未完成的每周答题") + console.log("初始化每周答题"); + await InitExamWeeklyAttr(); + console.log("正在寻找未完成的每周答题"); while (continueFind) { let startTime = Date.now(); - await getExamWeekly().then(async (data) => { + await getExamWeeklyByPageNo(examWeeklyPageNo).then(async (data) => { if (data) { - if (examWeeklyTotalPageCount == null) { - //如果总页码没初始化,则初始化 - examWeeklyTotalPageCount = data.totalPageCount; + if (examWeeklyReverse) { + // 若开启逆序答题, 则反转列表 + console.log("每周答题,开启逆序模式,从最早的题目开始答题"); + data.list.reverse(); } for (let i = 0; i < data.list.length; i++) { let examWeeks = data.list[i].practices;//获取每周的测试列表 + if (examWeeklyReverse) { + // 若开启逆序, 则反转每周的测试列表 + examWeeks.reverse(); + } for (let j = 0; j < examWeeks.length; j++) { //遍历查询有没有没做过的 if (examWeeks[j].status != 2) {//status: 1为"开始答题" , 2为"重新答题" @@ -496,8 +542,10 @@ async function findExamWeekly() { if (!continueFind) { } else { //增加页码 - examWeeklyPageNo++; - if (examWeeklyTotalPageCount == null || examWeeklyPageNo > examWeeklyTotalPageCount) { + examWeeklyPageNo += examWeeklyReverse ? -1 : 1; + if (examWeeklyTotalPageCount == null + || examWeeklyPageNo > examWeeklyTotalPageCount + || examWeeklyPageNo < 1) { //已经找完所有页码,还是没找到,不再继续查找 continueFind = false; } @@ -505,7 +553,7 @@ async function findExamWeekly() { } else { continueFind = false; } - + //fix code = 429 let remainms = Date.now() - startTime; if (remainms < ratelimitms) { @@ -982,7 +1030,7 @@ async function start() { taskProgress = await getToday(); if (taskProgress != null) { console.log("开始学习") - + //检查新闻 if (settings[0] && taskProgress[0].currentScore != taskProgress[0].dayMaxScore) { tasks[0] = false;//只要还有要做的,就当做没完成 @@ -992,7 +1040,7 @@ async function start() { } else { tasks[0] = true; } - + //检查视频 let temp = parseInt(taskProgress[1].dayMaxScore - taskProgress[1].currentScore); let temp2 = parseInt(taskProgress[3].dayMaxScore - taskProgress[3].currentScore); @@ -1004,7 +1052,7 @@ async function start() { } else { tasks[1] = true; } - + //检查每日答题 if (settings[6] && taskProgress[6].currentScore != taskProgress[6].dayMaxScore) { tasks[2] = false;//只要还有要做的,就当做没完成 @@ -1013,7 +1061,7 @@ async function start() { } else { tasks[2] = true; } - + //检查每周答题 if (settings[2] && taskProgress[2].currentScore == 0) { tasks[3] = false;//只要还有要做的,就当做没完成 @@ -1026,7 +1074,7 @@ async function start() { } else { tasks[3] = true; } - + //检查专项练习 if (settings[5] && taskProgress[5].currentScore == 0) { tasks[4] = false;//只要还有要做的,就当做没完成 @@ -1039,7 +1087,7 @@ async function start() { } else { tasks[4] = true; } - + if (tasks[0] && tasks[1] && tasks[2] && tasks[3] && tasks[4]) { //如果检查都做完了,就不用继续了 continueToDo = false;