Skip to content

Commit 025d9b3

Browse files
committed
替换所有等待时间为随机数
1 parent 9e7107c commit 025d9b3

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

不学习何以强国.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ function closeWin() {
9393

9494
}
9595

96+
/**
97+
* 随机等待最小到最大之间几秒, 需要await
98+
* @param {number} minSecond 最短时长
99+
* @param {number} MaxSecond 最长时长
100+
* @returns Promise
101+
*/
102+
function waitRandomBetween(minSecond=2,MaxSecond=5){
103+
if(MaxSecond<=minSecond){
104+
MaxSecond=minSecond+3
105+
}
106+
let waitTime = Math.random() * (MaxSecond - minSecond) + minSecond
107+
return new Promise((resolve,reject)=>{
108+
setTimeout(()=>{
109+
console.log(`随机等待${waitTime}秒`)
110+
resolve()
111+
},waitTime*1000)
112+
})
113+
}
114+
96115
$(document).ready(function () {
97116
let url = window.location.href;
98117
if (url == "https://www.xuexi.cn" || url == "https://www.xuexi.cn/" || url == "https://www.xuexi.cn/index.html") {
@@ -294,7 +313,7 @@ async function readNews() {
294313
console.log("正在看第" + (i + 1) + "个新闻");
295314
let newPage = GM_openInTab(news[i].url, { active: true, insert: true, setParent: true });
296315
await waitingClose(newPage);
297-
await waitingTime(1500);
316+
await waitRandomBetween(1,3);
298317
}
299318
}
300319
//获取新闻列表
@@ -386,7 +405,7 @@ async function watchVideo() {
386405
console.log("正在观看第" + (i + 1) + "个视频");
387406
let newPage = GM_openInTab(videos[i].url, { active: true, insert: true, setParent: true })
388407
await waitingClose(newPage);
389-
await waitingTime(1500);
408+
await waitRandomBetween(1,3);
390409
}
391410
}
392411
//做每日答题
@@ -407,7 +426,8 @@ function doExamPractice() {
407426
async function waitingDependStartTime(startTime){
408427
let remainms = Date.now() - startTime;
409428
if (remainms < ratelimitms) {
410-
await waitingTime(ratelimitms - remainms + 1000)
429+
let second = (ratelimitms - remainms)/1000
430+
await waitRandomBetween(second+1 ,second+3)
411431
}
412432
}
413433
//初始化专项答题总页数属性
@@ -670,7 +690,7 @@ async function doingExam() {
670690
let shouldSaveAnswer = false;
671691
while (true) {
672692
//先等等再开始做题
673-
await waitingTime(2500);
693+
await waitRandomBetween(2,5);
674694
await doingPause();
675695
nextButton = await getNextButton();
676696
if (nextButton.textContent == "再练一次" || nextButton.textContent == "再来一组" || nextButton.textContent == "查看解析") {
@@ -683,7 +703,7 @@ async function doingExam() {
683703
}
684704
//所有提示
685705
var allTips = document.querySelectorAll("font[color=red]");
686-
await waitingTime(1500);
706+
await waitRandomBetween(2,3);
687707
//选项按钮
688708
var allbuttons = document.querySelectorAll(".q-answer");
689709
//获取所有填空
@@ -935,17 +955,6 @@ function cancelVerify() {
935955
console.log("去除验证失败");
936956
}
937957
}
938-
//等待时间工具函数
939-
function waitingTime(time) {
940-
if (!Number.isInteger(time)) {
941-
time = 1000;
942-
}
943-
return new Promise(resolve => {
944-
setTimeout(function () {
945-
resolve('done');
946-
}, time);
947-
});
948-
}
949958
//查询今日完成情况
950959
function getToday() {
951960
return new Promise(function (resolve) {

0 commit comments

Comments
 (0)