Skip to content

Commit

Permalink
fix(script): 全面优化答题速度,优化存在题库缓存时无需执行搜题间隔等待,优化特定网课勾选答案时需要停顿,正常网课无需停顿的情况…
Browse files Browse the repository at this point in the history
…,极大加速了答案勾选过程。
  • Loading branch information
ennnncy committed Mar 27, 2024
1 parent 9e052f8 commit 1ca3448
Show file tree
Hide file tree
Showing 10 changed files with 562 additions and 574 deletions.
4 changes: 0 additions & 4 deletions packages/core/src/core/worker/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ export type WorkOptions<E extends RawElements> = {
answerer: AnswererType<E>;
/** 工作器 */
work: DefaultWork<E> | CustomWork<E>;
/** 查题间隔(秒) */
requestPeriod?: number;
/** 答题间隔(秒), 如果过快可能导致保存答案失败啊,或者被检测到 */
resolvePeriod?: number;
/** 多线程数量(个) */
thread?: number;
/** 分隔符 */
Expand Down
18 changes: 4 additions & 14 deletions packages/core/src/core/worker/question.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { QuestionResolver, WorkContext } from './interface';
import { resolvePlainAnswer, splitAnswer } from './utils';
import { answerSimilar, removeRedundant, clearString, answerExactMatch } from '../utils/string';
import { $ } from '../../utils/common';
import { StringUtils } from '../../utils/string';

/** 默认答案题目处理器 */
Expand Down Expand Up @@ -38,7 +37,6 @@ export function defaultQuestionResolve<E>(
if (index !== -1 && max > 0.6) {
/** 经自定义的处理器进行处理 */
await handler('single', ans, options[index], ctx);
await $.sleep(500);
return {
finish: true,
ratings: ratings.map((r) => r.rating)
Expand All @@ -49,7 +47,6 @@ export function defaultQuestionResolve<E>(
const index = optionStrings.findIndex((option) => result.includes(option));
if (result.length) {
await handler('single', options[index].innerText, options[index], ctx);
await $.sleep(500);
return {
finish: true
};
Expand All @@ -66,7 +63,6 @@ export function defaultQuestionResolve<E>(
continue;
}
await handler('single', options[index].innerText, options[index], ctx);
await $.sleep(500);
return { finish: true, option: options[index] };
}
}
Expand Down Expand Up @@ -180,8 +176,6 @@ export function defaultQuestionResolve<E>(
if (sorted_similar_list[0]) {
for (let i = 0; i < sorted_similar_list[0].options.length; i++) {
await handler('multiple', sorted_similar_list[0].answers[i], sorted_similar_list[0].options[i], ctx);
// 暂停一会防止点击过快
await $.sleep(500);
}

return { finish: true, sorted_similar_list, targetOptions, targetAnswers };
Expand All @@ -191,8 +185,6 @@ export function defaultQuestionResolve<E>(
if (sorted_exact_list[0]) {
for (let i = 0; i < sorted_exact_list[0].length; i++) {
await handler('multiple', sorted_exact_list[0][i].innerText, sorted_exact_list[0][i], ctx);
// 暂停一会防止点击过快
await $.sleep(500);
}

return {
Expand All @@ -218,7 +210,6 @@ export function defaultQuestionResolve<E>(
continue;
}
await handler('single', options[index].innerText, options[index], ctx);
await $.sleep(500);
plainOptions.push(options[index]);
}
}
Expand Down Expand Up @@ -284,13 +275,11 @@ export function defaultQuestionResolve<E>(
if (answerShowCorrect && textShowCorrect) {
option = el;
await handler('judgement', answerShowCorrect, el, ctx);
await $.sleep(500);
break;
}
if (answerShowIncorrect && textShowIncorrect) {
option = el;
await handler('judgement', answerShowIncorrect, el, ctx);
await $.sleep(500);
break;
}
}
Expand All @@ -299,7 +288,10 @@ export function defaultQuestionResolve<E>(
}

function matches(target: string, options: string[]) {
return options.some((option) => RegExp(clearString(option, '√', '×')).test(clearString(target, '√', '×')));
return options.some(
(option) =>
clearString(removeRedundant(option), '√', '×') === clearString(removeRedundant(target), '√', '×')
);
}
}

Expand All @@ -323,12 +315,10 @@ export function defaultQuestionResolve<E>(
for (let index = 0; index < options.length; index++) {
const element = options[index];
await handler('completion', ans[index], element, ctx);
await $.sleep(500);
}
return { finish: true };
} else if (options.length === 1) {
await handler('completion', ans.join(' '), options[0], ctx);
await $.sleep(500);
return { finish: true };
}

Expand Down
Loading

0 comments on commit 1ca3448

Please sign in to comment.