feat: 考试结果页去重与跳课,构建镜像脚本支持国内换源

考试:
- 新增 src/exam-plan.js(纯函数)判定结果页处置:只有本页确实点过
  「提交考试/确定交卷」才算一次空卷交卷,平台恢复的旧结果页先回
  「考试说明页」重进,不再在结果页和课程页之间空转
- 重试也不会好的确定性失败(交卷次数到上限、说明页无「开始考试」、
  答卷页无「提交考试」、结果页反复回退)改为本轮跳过该课继续下一门,
  记录在 S.skippedCourses(sessionStorage),不会停下整轮刷课
- 新一轮开跑时清空 skippedCourses / examEmptySubmits,人工处理后可重试
- 补 dev/tests/exam-test.mjs(npm run test:exam,5 条用例)

构建:
- 新增 scripts/build-docker.mjs/.cmd/.sh(npm run docker:build):
  国内换源、按包版本打标签、构建后自检、--dry-run
- Dockerfile 增加 APT_MIRROR / NPM_REGISTRY 构建参数,
  docker-compose.yml 透传三个 build args,.env.example 补说明
This commit is contained in:
void committed 2026-10-29 21:31:45 +08:00
1 parent b588b1042f
commit 17217dbeb1
18 files changed
+763 -53

No files matched your search

+118 -19
View File
@@ -2,7 +2,7 @@
// @name 云学堂助手
// @namespace yun-xue-tang-assistant.local
// @version 2.8.0
// @description 云学堂助手:自动登录、从第一节顺序听课、自动切节、处理防挂机验证,并在课程列表页逐门自动刷课(单视频/音频课程也支持,含考试章节的课自动空卷交卷,学完自动进入下一门,可优先短课程;不跳过任何课程)
// @description 云学堂助手:自动登录、从第一节顺序听课、自动切节、处理防挂机验证,并在课程列表页逐门自动刷课(单视频/音频课程也支持,含考试章节的课自动空卷交卷,学完自动进入下一门,可优先短课程)
// @match *://kfmic.yunxuetang.cn/*
// @match *://*.yunxuetang.cn/*
// @grant none
@@ -30,7 +30,7 @@
* 顺序学习,不沿用平台上次停留的位置(否则前面的课时会被跳过,整门课永远学不完)。
* 切换成功与否以目录高亮为准:没切过去会重试并如实提示「未能切换」,不会假装已切换。
* - 试跑稳定后,把 config.js 里的 CFG.maxCourses 改成 0 即可不限门数(会持续很久)。
* - 脚本不跳过任何课程:没有「跳过本课」,也不会把课程拉黑。某门课没学完(例如遇到
* - 脚本不跳过普通课程:没有「跳过本课」,也不会把课程拉黑。某门课没学完(例如遇到
* 需要人工完成的滑块/拼图验证、答题/测验章节、长时间无计时进展)就退避重试:
* 30 秒起每次翻倍、最长 5 分钟,同一门课最多重试 CFG.maxCourseRetries 次,
* 超过才停下整轮刷课并在面板写明原因,等人工处理后点「一键刷课」接着跑。
@@ -39,7 +39,10 @@
* - 防挂机验证(每 10 分钟一次、120 秒限时)会自动点「继续学习」。
* - 考试章节支持:自动进入考试、不答题直接交卷(空白交卷)。交卷后平台会把考试节点
* 计入课程进度,含考试章节的课程也能学完。
* 同一门课最多交卷 CFG.maxExamTries 次,超过仍没计入进度就按普通未完成退避重试。
* 只有本页真的点过「提交考试/确定交卷」,看到的结果页才算一次交卷;平台恢复的旧
* 结果页会先回考试说明页重新进入,避免在结果页和课程页之间空转。
* 同一门课最多交卷 CFG.maxExamTries 次,超过仍没计入进度、或考试页没有可点的
* 「开始考试/提交考试」时,本轮跳过这门课继续下一门(会写明原因),不再反复重进。
* - 验证码/滑块需要手动完成,脚本不会绕过。
* - 课程/单位如有相关规定,请自行确认风险。
*
@@ -156,6 +159,8 @@
// 课程名 -> 完成时间戳(防平台记账延迟时重进同一门)
courseRetries: {},
// 课程名 -> { n, reason, at }(未完成重试次数)
skippedCourses: {},
// 课程名 -> { reason, at }(考试无法自动完成,本轮跳过)
examEmptySubmits: {}
// 课程 id -> 空卷交卷次数(防死循环)
};
@@ -189,6 +194,7 @@
out.awaitingListReturn = obj.awaitingListReturn === true;
out.completedTitles = asMap(obj.completedTitles);
out.courseRetries = asMap(obj.courseRetries);
out.skippedCourses = asMap(obj.skippedCourses);
out.examEmptySubmits = asMap(obj.examEmptySubmits);
return out;
}
@@ -295,6 +301,12 @@
// '' | preview | paper | result
examActionAt: 0,
// 上次考试页内点击时间
examSubmitted: false,
// 本页是否真的点过「提交考试/确定交卷」(区分残留结果页)
examPreviewAt: 0,
// 进入考试说明页的时间(找不到「开始考试」时的超时)
examStaleResults: 0,
// 本课遇到残留结果页并尝试重进的次数
examStarts: 0,
// 本形态点了多少次「开始考试」
examSubmits: 0,
@@ -365,6 +377,9 @@
R.quizChecked = false;
R.examPhase = "";
R.examActionAt = 0;
R.examSubmitted = false;
R.examPreviewAt = 0;
R.examStaleResults = 0;
R.examStarts = 0;
R.examSubmits = 0;
R.examConfirms = 0;
@@ -688,6 +703,7 @@
if (loginRememberEl) loginRememberEl.checked = false;
}
function startBatch() {
const freshStart = !S.batchRunning;
if (S.batchFinished) {
S.completedThisRun = 0;
S.batchFinished = false;
@@ -695,6 +711,10 @@
R.retryWaitUntil = 0;
R.retryTitle = "";
}
if (freshStart) {
S.skippedCourses = {};
S.examEmptySubmits = {};
}
S.batchRunning = true;
invalidateShortCatalog();
if (!S.activeCourse) S.coursePhase = PHASE_IDLE;
@@ -1189,6 +1209,28 @@
goToList(true);
}, 1200);
}
function courseSkipped(title) {
const t = norm(title);
return !!(t && (S.skippedCourses || {})[t]);
}
function skipCurrent(reason) {
const title = recordTitle();
const key = norm(title);
if (key) S.skippedCourses[key] = { reason, at: Date.now() };
S.activeCourse = null;
S.coursePhase = PHASE_IDLE;
S.awaitingListReturn = true;
R.retryWaitUntil = 0;
R.retryTitle = "";
invalidateShortCatalog();
saveRunState();
setStatus("已跳过「" + truncate(title || "当前课程", 20) + "」:" + reason + "(继续下一门)");
console.warn(TAG, "跳过课程:", title, reason);
updatePanel();
later(function() {
goToList(true);
}, 1200);
}
function failCurrent(reason) {
const title = recordTitle();
const key = norm(title);
@@ -2079,7 +2121,7 @@
if (!cat) return [];
return cat.items.filter(function(item) {
if (!item || !item.title) return false;
if (S.completedTitles[item.title]) return false;
if (S.completedTitles[item.title] || courseSkipped(item.title)) return false;
return true;
});
}
@@ -2163,7 +2205,7 @@
} else {
const card = cardForShortItem(cards, target);
if (card) {
if (card.status === "已学完" || S.completedTitles[card.title]) {
if (card.status === "已学完" || S.completedTitles[card.title] || courseSkipped(card.title)) {
forgetShortCourse(card.title);
return { wait: true };
}
@@ -2289,7 +2331,7 @@
const pending = cards.filter((c) => {
if (!c.title) return false;
if (/已学完|已完成|已学习/.test(c.status)) return false;
if (S.completedTitles[c.title]) return false;
if (S.completedTitles[c.title] || courseSkipped(c.title)) return false;
return true;
});
if (state.preferShortCourses) {
@@ -2345,8 +2387,18 @@
}
}
// src/exam-plan.js
function planExamResult(ctx) {
const submitted = !!(ctx && ctx.submitted);
const complete = !!(ctx && ctx.complete);
if (submitted) return complete ? "complete" : "count";
if (complete) return "complete";
if ((Number(ctx && ctx.staleTries) || 0) >= 2) return "skip";
return "reback";
}
// src/exam.js
var START_RE = /^(开始考试|继续考试|进入考试)$/;
var START_RE = /^(开始考试|继续考试|重新考试|进入考试)$/;
var SUBMIT_RE = /^(提交考试|提交试卷|交卷|交卷并退出)$/;
var EXAM_SUBMIT_RE = /^(提交考试|交卷|交卷并退出)$/;
var CONFIRM_RE = /^(确定|确认|确定交卷|确认交卷|提交|提交试卷)$/;
@@ -2437,12 +2489,13 @@
}
return { shown: true, btn: null };
}
function examAbort(reason, manual) {
function examAbort(reason, manual, skip) {
if (manual) {
setStatus("考试:" + reason);
return true;
}
failCurrent(reason);
if (skip) skipCurrent(reason);
else failCurrent(reason);
return true;
}
function examCourseKey() {
@@ -2466,6 +2519,8 @@
R.lastCountdown = null;
R.lastSummary = null;
R.examLeaving = false;
R.examSubmitted = false;
R.examPreviewAt = 0;
try {
const cur = location.href;
if (!target || cur === target) {
@@ -2484,8 +2539,41 @@
} catch (e) {
}
}
function finishExam() {
function backToPreview() {
R.examLeaving = false;
const btn = findClickableByText(/^返回考试说明页$/);
if (btn) {
setStatus("考试:返回考试说明页,重新进入考试…");
examClick(btn);
return;
}
backToCourse();
}
function finishExam(manual) {
if (R.examLeaving) return;
const s = readSummary();
const plan = planExamResult({
submitted: R.examSubmitted,
complete: !!(s && s.complete),
staleTries: R.examStaleResults
});
if (plan === "complete") {
R.examLeaving = true;
setStatus("考试已交卷(未答题),课程已完成");
later(completeCurrent, 1500);
return;
}
if (plan === "reback") {
R.examLeaving = true;
R.examStaleResults++;
console.log(TAG, "考试结果页不是本页交的卷(平台恢复的旧结果),返回说明页重新进入考试");
setStatus("考试结果为上次残留,返回考试说明页重新进入…");
later(backToPreview, 1500);
return;
}
if (plan === "skip") {
return examAbort("考试结果页反复出现,无法重新进入考试,需手动处理", manual, true);
}
R.examLeaving = true;
const key = examCourseKey();
if (!S.examEmptySubmits) S.examEmptySubmits = {};
@@ -2493,14 +2581,8 @@
saveRunState();
const times = S.examEmptySubmits[key];
console.log(TAG, "考试已空卷交卷(第", times, "次),返回课程页继续学习");
const s = readSummary();
if (s && s.complete) {
setStatus("考试已交卷(未答题),课程已完成");
later(completeCurrent, 1500);
return;
}
if (times >= Math.max(1, CFG.maxExamTries)) {
examAbort("已空卷交卷 " + times + " 次,仍未计入课程进度,请手动处理", false);
examAbort("已空卷交卷 " + times + " 次,仍未计入课程进度,需手动处理", manual, true);
return;
}
setStatus("考试已交卷(未答题),返回课程继续…");
@@ -2517,6 +2599,7 @@
R.examConfirms = 0;
R.examStarts = 0;
R.examActionAt = 0;
R.examPreviewAt = 0;
}
return false;
}
@@ -2527,27 +2610,33 @@
R.examConfirms = 0;
R.examStarts = 0;
R.examPaperAt = 0;
if (phase === "preview" || phase === "paper") R.examSubmitted = false;
R.examPreviewAt = phase === "preview" ? now : 0;
if (phase === "preview") {
console.log(TAG, "检测到考试章节:进入考试后不答题,直接交卷");
setStatus("检测到考试:进入考试后直接交卷…");
}
}
if (phase === "result") {
finishExam();
finishExam(manual);
return true;
}
const key = examCourseKey();
if (examTriedTimes(key) >= Math.max(1, CFG.maxExamTries)) {
return examAbort("已空卷交卷 " + examTriedTimes(key) + " 次,仍未计入课程进度,请手动处理", manual);
return examAbort("已空卷交卷 " + examTriedTimes(key) + " 次,仍未计入课程进度,需手动处理", manual, true);
}
if (now - R.examActionAt < CFG.examClickCooldownMs) return true;
if (phase === "preview") {
const root = examPreviewRoot();
const btn = findClickableByText(START_RE, root) || findClickableByText(START_RE);
if (!btn) {
if (now - R.examPreviewAt > 3e4) {
return examAbort("考试说明页没有「开始考试」按钮,需手动处理", manual, true);
}
setStatus("考试:未找到「开始考试」按钮,等待页面渲染…");
return true;
}
R.examPreviewAt = 0;
R.examActionAt = now;
R.examStarts++;
if (R.examStarts > Math.max(3, CFG.maxExamTries + 3)) {
@@ -2562,6 +2651,9 @@
const cs = confirmState();
if (cs.shown) {
if (!cs.btn) {
if (now - R.examPaperAt > 3e4) {
return examAbort("交卷确认框里没有「确定」按钮", manual);
}
setStatus("考试:交卷确认框里没找到「确定」按钮");
return true;
}
@@ -2570,12 +2662,16 @@
if (R.examConfirms > 6) {
return examAbort("交卷确认框点了多次仍未交卷", manual);
}
R.examSubmitted = true;
setStatus("考试:不答题,确认交卷…");
examClick(cs.btn);
return true;
}
const sub = findClickableByText(SUBMIT_RE);
if (!sub) {
if (now - R.examPaperAt > 3e4) {
return examAbort("答卷页没有「提交考试」按钮", manual);
}
setStatus("考试:等待「提交考试」按钮…");
return true;
}
@@ -2584,6 +2680,7 @@
}
R.examActionAt = now;
R.examSubmits++;
R.examSubmitted = true;
setStatus("考试:不答题,直接交卷…");
examClick(sub);
return true;
@@ -3006,6 +3103,8 @@
retryWaitSeconds,
completeCurrent,
failCurrent,
skipCurrent,
courseSkipped,
// 以下供开发/真机测试驱动内部路径使用:
scanCards,
currentPage,