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:
1 parent
b588b1042f
commit
17217dbeb1
18 files changed
+763
-53
No files matched your search
@@ -2,3 +2,18 @@
|
||||
# 凭据只认这两个变量,不能写进 config/runner.config.mjs
|
||||
YUN_XUE_TANG_USR=
|
||||
YUN_XUE_TANG_PWD=
|
||||
|
||||
# 本次最多完成几门课(docker compose 用;0 / 留空 = 不限)
|
||||
YUN_XUE_TANG_MAX_COURSES=100
|
||||
|
||||
# 时区,影响日志时间戳
|
||||
TZ=Asia/Shanghai
|
||||
|
||||
# ---- 以下三个只在构建镜像时用(docker compose build / npm run docker:build)----
|
||||
# Debian 源地址:国内建议 mirrors.tuna.tsinghua.edu.cn,留空 = 保持 deb.debian.org
|
||||
APT_MIRROR=
|
||||
# npm 源地址:国内建议 https://registry.npmmirror.com,留空 = 官方源
|
||||
NPM_REGISTRY=
|
||||
# Chrome deb 直链:国内常常下不动 dl.google.com,填自己的内网镜像地址;
|
||||
# 留空 = 按架构自动取官网地址
|
||||
CHROME_DEB_URL=
|
||||
+15
-1
@@ -21,6 +21,12 @@ FROM node:22-bookworm-slim
|
||||
# docker build --build-arg CHROME_DEB_URL=https://your-mirror/google-chrome-stable_current_amd64.deb .
|
||||
# 留空则按架构自动取官网地址。
|
||||
ARG CHROME_DEB_URL=
|
||||
# Debian 官方源在国内经常慢到几百字节每秒,可用内网/国内镜像替换:
|
||||
# docker build --build-arg APT_MIRROR=mirrors.tuna.tsinghua.edu.cn .
|
||||
# 留空 = 保持基础镜像自带的 deb.debian.org
|
||||
ARG APT_MIRROR=
|
||||
# npm 同理(https://registry.npmmirror.com 之类),留空 = 官方源
|
||||
ARG NPM_REGISTRY=
|
||||
# tzdata 让日志时间戳跟随 TZ(默认给上海时区);fonts-noto-cjk 只影响截图观感,
|
||||
# 但缺了它中文在页面里是方块,排查问题时不方便
|
||||
ENV TZ=Asia/Shanghai \
|
||||
@@ -30,6 +36,10 @@ ENV TZ=Asia/Shanghai \
|
||||
# 步骤:装基础包 → 按架构下官方 Chrome deb → 用 apt 一次装齐依赖 → 清缓存 → 验证能起来。
|
||||
# procps 提供 ps:运行器启动时靠它找「占着本 profile 的残留浏览器」并收掉(缺了也可跑,自愈会退化)。
|
||||
RUN set -eux; \
|
||||
if [ -n "$APT_MIRROR" ]; then \
|
||||
sed -ri "s|deb.debian.org|${APT_MIRROR}|g" /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list 2>/dev/null || true; \
|
||||
echo "已切换 apt 源:$APT_MIRROR"; \
|
||||
fi; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
@@ -62,7 +72,11 @@ WORKDIR /app
|
||||
# devDependencies 里的 esbuild 是构建注入脚本必需的,所以不能用 --omit=dev;
|
||||
# 留着它也能让使用者在容器里直接 `npm run build`
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --no-audit --no-fund
|
||||
RUN set -eux; \
|
||||
if [ -n "$NPM_REGISTRY" ]; then \
|
||||
npm config set registry "$NPM_REGISTRY"; \
|
||||
fi; \
|
||||
npm ci --no-audit --no-fund
|
||||
|
||||
# 业务源码 + 构建脚本 + 无头运行器(node_modules / .run-profile / run-logs / .env 由 .dockerignore 排除)
|
||||
COPY . .
|
||||
|
||||
@@ -20,8 +20,8 @@ Tampermonkey 用户脚本。支持多课时课程与单视频/音频课程;含
|
||||
| 防挂机验证 | 识别「已触发防挂机验证」弹窗并点「继续学习」;滑块/拼图类验证不绕过,提示人工处理 |
|
||||
| 课程列表自动刷课 | 在列表页逐门进入未学完的课程;每完成一门都重新调列表接口拿平台实时状态再选下一门,本次门数上限见下方配置表 |
|
||||
| 短课程优先 | 列表刷课默认按课程总时长**从短到长**选课(跨页),先完成 1 分钟的课再学 1 小时的课;面板可关闭 |
|
||||
| 考试自动空卷 | 含考试章节的课程不再跳过:自动点进考试节 → 开始/继续考试 → 一题不做直接「提交考试」→ 点「确定」交卷,交卷后课程进度被平台记账,课程即可完成;同一门课最多交卷 `maxExamTries` 次,防平台不记账时死循环 |
|
||||
| 不跳过课程 | 没有任何「跳过本课」入口,也不会把某门课加入黑名单;没学完就退避重试(30 秒起翻倍,最长 5 分钟),同一门课最多重试 `maxCourseRetries` 次,超过才停下整轮刷课并提示原因,等人工处理 |
|
||||
| 考试自动空卷 | 含考试章节的课程不再跳过:自动点进考试节 → 开始/继续考试 → 一题不做直接「提交考试」→ 点「确定」交卷,交卷后课程进度被平台记账,课程即可完成。只有本页真的点过「提交考试/确定交卷」,看到的结果页才算一次交卷;平台恢复的旧结果页会先回「考试说明页」重新进入,不会在结果页和课程页之间空转。同一门课最多交卷 `maxExamTries` 次,超过仍不记账就跳过该课继续下一门(写明原因) |
|
||||
| 不跳过普通课程 | 没有任何「跳过本课」入口,也不会把普通课程加入黑名单;没学完就退避重试(30 秒起翻倍,最长 5 分钟),同一门课最多重试 `maxCourseRetries` 次,超过才停下整轮刷课并提示原因,等人工处理。**唯一例外**:考试空卷交卷达到 `maxExamTries` 仍未计入进度,或考试页始终没有可点的「开始考试/提交考试」——继续重试只会反复进同一门课,因此本轮跳过它、继续刷其它课 |
|
||||
| 进度可续 | 学习进度存在 `sessionStorage`(`yun-xue-tang-run-state-v3`),整页跳转/刷新后继续上次的队列和页码;**运行开关不跨会话** —— 浏览器重启、运行器新建标签页后一律回到待机,必须显式开跑(避免未登录就报「运行中」) |
|
||||
| 无头运行 | 在有/无图形界面的机器上都能跑;`runner/` 可自己起无头 Chromium 并注入脚本,适合 Linux 服务器 / Windows 无人值守常驻(见下方「无头运行」) |
|
||||
|
||||
@@ -52,7 +52,7 @@ Tampermonkey 用户脚本。支持多课时课程与单视频/音频课程;含
|
||||
| `courseRetryDelayMs` | `30000` | 首次重试前的等待;每次翻倍,最长 5 分钟 |
|
||||
| `alignToFirstIncomplete` | `true` | 进入课程先从第一个未学完的课时学起;`false` = 沿用平台上次位置 |
|
||||
| `preferShortCourses` | `true` | 列表刷课时优先总时长更短的课程(正序);面板勾选框「优先短课程(时长正序)」可随时切换 |
|
||||
| `maxExamTries` | `2` | 同一门课「空卷交卷」的最大次数;超过仍没计入进度就按普通未完成重试(防死循环) |
|
||||
| `maxExamTries` | `2` | 同一门课「空卷交卷」的最大次数;超过仍没计入进度就本轮跳过该课、继续下一门(记录在会话里,重启后会重新尝试) |
|
||||
| `examClickCooldownMs` | `1500` | 考试页内两次点击的间隔(毫秒) |
|
||||
|
||||
对齐起点对「一键刷课」和自己点开的课程(需勾选「当前课程自动连播」)都生效,
|
||||
@@ -307,6 +307,21 @@ export default {
|
||||
Node 22 与 **官方 google-chrome-stable**(不是发行版 chromium —— 后者不带 H.264/AAC,
|
||||
课程视频会一直停在 0 秒),并在构建阶段跑完 `npm run build`,所以镜像开箱即用。
|
||||
|
||||
构建镜像推荐用仓库自带的脚本,它会把国内换源、按 `package.json` 版本打标签、构建后自检
|
||||
这几件容易漏的事一趟做完(纯 `docker build` 当然也能用,下面第 1 步就是它展开后的样子):
|
||||
|
||||
```bash
|
||||
npm run docker:build # 默认标签 <包名>:<版本号> + <包名>:latest
|
||||
npm run docker:build -- --mirror # 国内网络:apt 换清华源、npm 换 npmmirror
|
||||
npm run docker:build -- --check # 构建完顺手跑一次 --check 自检
|
||||
npm run docker:build -- --dry-run # 只打印将要执行的 docker 命令,不构建
|
||||
npm run docker:build -- --help # 全部选项(--tag / --platform / --no-cache / --pull / --chrome-url …)
|
||||
Windows 下也可以直接双击 scripts\build-docker.cmd;Linux/macOS 用 ./scripts/build-docker.sh
|
||||
```
|
||||
|
||||
`APT_MIRROR` / `NPM_REGISTRY` / `CHROME_DEB_URL` 三个构建参数按 **命令行 > 环境变量 > 仓库根 `.env`**
|
||||
的优先级取值,所以也可以把它们写进 `.env` 一次配好,之后直接 `npm run docker:build`。
|
||||
|
||||
```bash
|
||||
# 1. 构建(首次约 3-5 分钟,主要是下 Chrome 的 deb)
|
||||
docker build -t yun-xue-tang-assistant .
|
||||
@@ -399,12 +414,16 @@ src/ 业务脚本源码(拆成多个模块,日
|
||||
list.js 列表页 + 短课程优先
|
||||
player.js 播放器 / 防挂机 / 课时切换
|
||||
exam.js 考试自动空卷交卷
|
||||
exam-plan.js 考试结果页处置决策(纯函数,可单测)
|
||||
course.js 课程页主循环
|
||||
complete.js 完成 / 未完成重试
|
||||
complete.js 完成 / 未完成重试 / 跳课
|
||||
index.js 主循环 / 启动 / 调试入口
|
||||
scripts/ 开发与运维脚本(不在构建产物里)
|
||||
build.mjs esbuild 打包脚本(产物写回仓库根)
|
||||
check.mjs 静态检查:node --check + 批处理纯 ASCII/CRLF 校验
|
||||
build-docker.mjs 构建镜像(换源 / 打标签 / 构建后自检,参数见 --help)
|
||||
build-docker.cmd Windows 一键构建镜像(双击即可)
|
||||
build-docker.sh Linux / macOS 构建镜像(转交 build-docker.mjs)
|
||||
start-dev.cmd Windows 一键启动本地热加载服务(双击即可)
|
||||
start-headless.cmd Windows 一键启动无头运行器(双击即可)
|
||||
runner/ 无头运行器(Linux / Windows,无图形化环境)
|
||||
@@ -457,7 +476,7 @@ docs/
|
||||
|
||||
| `sessionStorage` 键(本次运行,关掉标签页即清空) | 内容 |
|
||||
| --- | --- |
|
||||
| `yun-xue-tang-run-state-v3` | 本轮是否在跑、页码、当前课程、本轮已完成与待重试记录 |
|
||||
| `yun-xue-tang-run-state-v3` | 本轮是否在跑、页码、当前课程、本轮已完成 / 待重试 / 已跳过(考试交不了)记录 |
|
||||
| `yun-xue-tang-short-catalog-v1` | 短课程时长队列缓存(TTL 5 分钟) |
|
||||
|
||||
旧版本(v2.8.0 之前)把所有状态整块存在 `localStorage` 的 `yun-xue-tang-batch-v2` 里,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* 考试结果页处置(src/exam-plan.js)自测:纯决策逻辑,不需要浏览器。
|
||||
*
|
||||
* 钉住的回归:重进课程时平台会恢复上次的考试结果页。那一页不是本页交的卷,
|
||||
* 不能计入「空卷交卷」次数,否则 maxExamTries 失效且会在结果页↔课程页之间死循环。
|
||||
*
|
||||
* 用法:
|
||||
* node dev/tests/exam-test.mjs
|
||||
* npm run test:exam
|
||||
*/
|
||||
import { planExamResult } from '../../src/exam-plan.js';
|
||||
|
||||
let failed = 0;
|
||||
function eq(actual, expect, name) {
|
||||
if (actual === expect) console.log(' ✔ ' + name);
|
||||
else {
|
||||
failed++;
|
||||
console.log(' ✘ ' + name + ' → 期望 ' + JSON.stringify(expect) +
|
||||
',实际 ' + JSON.stringify(actual));
|
||||
}
|
||||
}
|
||||
|
||||
console.log('考试结果页');
|
||||
eq(planExamResult({ submitted: true, complete: false }), 'count', '本页交的卷、平台未记账 → 计一次空卷交卷');
|
||||
eq(planExamResult({ submitted: true, complete: true }), 'complete', '本页交的卷、平台已记账 → 直接收课');
|
||||
eq(planExamResult({ submitted: false, complete: false, staleTries: 0 }), 'reback',
|
||||
'平台恢复的旧结果页 → 回考试说明页重进,不计交卷');
|
||||
eq(planExamResult({ submitted: false, complete: false, staleTries: 2 }), 'skip',
|
||||
'反复回不到考试说明页 → 跳过该课等人工');
|
||||
eq(planExamResult({ submitted: false, complete: true }), 'complete',
|
||||
'没交卷但平台已算完成 → 直接收课');
|
||||
|
||||
if (failed) {
|
||||
console.log('\n失败 ' + failed + ' 项');
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('\n全部通过');
|
||||
+7
-1
@@ -11,7 +11,13 @@
|
||||
# 这样 .env 不存在时也不会直接报错,入口脚本会降级成 --check。
|
||||
services:
|
||||
yun-xue-tang:
|
||||
build: .
|
||||
build:
|
||||
context: .
|
||||
# apt / npm 镜像源可在 .env 里覆盖(APT_MIRROR / NPM_REGISTRY),留空则用默认官方源
|
||||
args:
|
||||
APT_MIRROR: "${APT_MIRROR:-}"
|
||||
NPM_REGISTRY: "${NPM_REGISTRY:-}"
|
||||
CHROME_DEB_URL: "${CHROME_DEB_URL:-}"
|
||||
image: yun-xue-tang-assistant:latest
|
||||
container_name: yun-xue-tang
|
||||
# 为什么不是 unless-stopped:运行器「刷完了」会以退出码 0 正常退出,
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
"test:e2e:play": "node dev/tests/real-e2e.mjs --play",
|
||||
"test:tui": "node dev/tests/tui-test.mjs",
|
||||
"test:study": "node dev/tests/study-test.mjs",
|
||||
"test:exam": "node dev/tests/exam-test.mjs",
|
||||
"docker:build": "node scripts/build-docker.mjs",
|
||||
"docker:check": "node scripts/build-docker.mjs --check",
|
||||
"headless": "node runner/headless.mjs",
|
||||
"headless:check": "node runner/headless.mjs --check"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
@echo off
|
||||
rem ---------------------------------------------------------------
|
||||
rem This file must stay PURE ASCII and CRLF (see scripts\start-headless.cmd
|
||||
rem for the full explanation: cmd.exe parses batch files byte-by-byte with
|
||||
rem the current code page, so multi-byte chars / bare LF corrupt line offsets).
|
||||
rem All Chinese messages come from the Node script instead.
|
||||
rem
|
||||
rem Usage:
|
||||
rem scripts\build-docker.cmd build with default tags
|
||||
rem scripts\build-docker.cmd --mirror --check build with CN mirrors, then self-check
|
||||
rem scripts\build-docker.cmd --help list all options
|
||||
rem ---------------------------------------------------------------
|
||||
setlocal
|
||||
chcp 65001 >nul
|
||||
cd /d "%~dp0.."
|
||||
title YunXueTang Assistant - docker build
|
||||
|
||||
where node >nul 2>nul
|
||||
if errorlevel 1 goto no_node
|
||||
|
||||
node "scripts\build-docker.mjs" %*
|
||||
set RC=%ERRORLEVEL%
|
||||
if "%RC%"=="0" exit /b 0
|
||||
|
||||
echo.
|
||||
echo [exit] code %RC% (0 ok 1 build failed 2 env/args problem)
|
||||
pause
|
||||
exit /b %RC%
|
||||
|
||||
:no_node
|
||||
echo [error] node.exe not found. Install Node.js 22+ from https://nodejs.org/
|
||||
pause
|
||||
exit /b 2
|
||||
@@ -0,0 +1,342 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* 构建 Docker 镜像的便捷入口。
|
||||
*
|
||||
* 为什么要有这层脚本,而不是让人手敲 `docker build`:
|
||||
* 1. Dockerfile 里有三个构建参数(APT_MIRROR / NPM_REGISTRY / CHROME_DEB_URL),
|
||||
* 国内机器几乎必须换源才能构建成功,但每次手写 `--build-arg` 又长又容易漏;
|
||||
* 这里统一从命令行、环境变量、.env 三处按优先级取值。
|
||||
* 2. 镜像标签跟着 package.json 的 version 走,顺手再打一个 latest;
|
||||
* 版本号只在 package.json 维护一处,不靠人记。
|
||||
* 3. 构建完能直接 `--check`(只读自检:不登录、不动进度),一步验证镜像真的能起来。
|
||||
*
|
||||
* 用法:
|
||||
* npm run docker:build # 默认标签 = 包里版本号 + latest
|
||||
* npm run docker:build -- --mirror # 一键换国内源(apt 清华 + npm npmmirror)
|
||||
* npm run docker:build -- --check # 构建完立刻跑一次 --check 自检
|
||||
* npm run docker:build -- --tag my/yxt:dev # 只打指定标签
|
||||
* npm run docker:build -- --dry-run # 只打印将要执行的 docker 命令
|
||||
* npm run docker:build -- --help
|
||||
*
|
||||
* 退出码与仓库其它脚本保持一致:0 成功 / 1 构建失败 / 2 环境或参数问题。
|
||||
*/
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
|
||||
/** 国内常用镜像源预设(--mirror 一键套用);Chrome 的 deb 没有公认镜像,只能由使用者用 --chrome-url 指定 */
|
||||
const MIRROR_PRESET = {
|
||||
apt: 'mirrors.tuna.tsinghua.edu.cn',
|
||||
npm: 'https://registry.npmmirror.com',
|
||||
};
|
||||
|
||||
const HELP = `构建云学堂助手 Docker 镜像
|
||||
|
||||
用法:node scripts/build-docker.mjs [选项]
|
||||
|
||||
选项:
|
||||
-t, --tag <名称:标签> 镜像标签;可重复给多次。默认 <包名>:<package.json 版本> 加 <包名>:latest
|
||||
--mirror 一键套用国内镜像源(apt = ${MIRROR_PRESET.apt},npm = ${MIRROR_PRESET.npm})
|
||||
--apt-mirror <host> Debian 源地址,对应 Dockerfile 的 APT_MIRROR
|
||||
--npm-registry <url> npm 源地址,对应 NPM_REGISTRY
|
||||
--chrome-url <url> Chrome deb 直链,对应 CHROME_DEB_URL(国内下不动 dl.google.com 时用)
|
||||
--platform <平台> 如 linux/amd64、linux/arm64(默认用构建机架构)
|
||||
--build-arg <K=V> 透传任意额外构建参数,可重复
|
||||
--no-cache 不用构建缓存
|
||||
--pull 先拉取最新的基础镜像
|
||||
--check 构建成功后跑一次 \`docker run --rm <镜像> --check\` 自检
|
||||
--dry-run 只打印 docker 命令,不真正构建
|
||||
-h, --help 显示本帮助
|
||||
|
||||
取值优先级:命令行 > 同名环境变量 > 仓库根目录 .env > 默认值
|
||||
(只从 .env 读 APT_MIRROR / NPM_REGISTRY / CHROME_DEB_URL 三个键,凭据类变量一律不读)
|
||||
|
||||
示例:
|
||||
node scripts/build-docker.mjs --mirror --check
|
||||
node scripts/build-docker.mjs -t yun-xue-tang-assistant:test --no-cache
|
||||
APT_MIRROR=mirrors.aliyun.com node scripts/build-docker.mjs
|
||||
`;
|
||||
|
||||
/** 解析成 { options, error } —— 手写解析而非引入依赖,仓库唯一的 devDependency 是 esbuild */
|
||||
function parseArgs(argv) {
|
||||
const opts = {
|
||||
tags: [],
|
||||
mirror: false,
|
||||
aptMirror: '',
|
||||
npmRegistry: '',
|
||||
chromeUrl: '',
|
||||
platform: '',
|
||||
buildArgs: [],
|
||||
noCache: false,
|
||||
pull: false,
|
||||
check: false,
|
||||
dryRun: false,
|
||||
help: false,
|
||||
};
|
||||
|
||||
const needValue = (i, name) => {
|
||||
const v = argv[i + 1];
|
||||
if (v === undefined || v.startsWith('-')) {
|
||||
throw new Error(`选项 ${name} 需要一个值`);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
const arg = argv[i];
|
||||
// 支持 --key=value 与 --key value 两种写法
|
||||
const eq = arg.indexOf('=');
|
||||
const key = arg.startsWith('--') && eq > 0 ? arg.slice(0, eq) : arg;
|
||||
const inline = arg.startsWith('--') && eq > 0 ? arg.slice(eq + 1) : null;
|
||||
const take = (name) => (inline !== null ? inline : needValue(i, name));
|
||||
const takeAndSkip = (name) => {
|
||||
const v = take(name);
|
||||
if (inline === null) i++;
|
||||
return v;
|
||||
};
|
||||
|
||||
switch (key) {
|
||||
case '-t':
|
||||
case '--tag': {
|
||||
const v = takeAndSkip(key);
|
||||
if (!v.trim()) throw new Error('镜像标签不能为空');
|
||||
opts.tags.push(v.trim());
|
||||
break;
|
||||
}
|
||||
case '--mirror':
|
||||
opts.mirror = true;
|
||||
break;
|
||||
case '--apt-mirror':
|
||||
opts.aptMirror = takeAndSkip(key);
|
||||
break;
|
||||
case '--npm-registry':
|
||||
opts.npmRegistry = takeAndSkip(key);
|
||||
break;
|
||||
case '--chrome-url':
|
||||
opts.chromeUrl = takeAndSkip(key);
|
||||
break;
|
||||
case '--platform':
|
||||
opts.platform = takeAndSkip(key);
|
||||
break;
|
||||
case '--build-arg':
|
||||
opts.buildArgs.push(takeAndSkip(key));
|
||||
break;
|
||||
case '--no-cache':
|
||||
opts.noCache = true;
|
||||
break;
|
||||
case '--pull':
|
||||
opts.pull = true;
|
||||
break;
|
||||
case '--check':
|
||||
opts.check = true;
|
||||
break;
|
||||
case '--dry-run':
|
||||
opts.dryRun = true;
|
||||
break;
|
||||
case '-h':
|
||||
case '--help':
|
||||
opts.help = true;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`未知选项:${arg}`);
|
||||
}
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
/** 极简 .env 解析:只认 KEY=VALUE / KEY="VALUE",忽略注释与空行 */
|
||||
function readDotEnv(file) {
|
||||
const out = {};
|
||||
if (!fs.existsSync(file)) return out;
|
||||
let text = '';
|
||||
try {
|
||||
text = fs.readFileSync(file, 'utf8');
|
||||
} catch {
|
||||
return out;
|
||||
}
|
||||
for (const raw of text.split(/\r?\n/)) {
|
||||
const line = raw.trim();
|
||||
if (!line || line.startsWith('#')) continue;
|
||||
const m = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
|
||||
if (!m) continue;
|
||||
let v = m[2].trim();
|
||||
if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) {
|
||||
v = v.slice(1, -1);
|
||||
}
|
||||
out[m[1]] = v;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function readPackage(file) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
} catch (e) {
|
||||
throw new Error(`读不出 ${path.relative(ROOT, file)}:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** 把参数数组还原成可以直接粘进终端的命令行(仅用于日志展示) */
|
||||
function quote(argv) {
|
||||
return argv
|
||||
.map((a) => (/^[\w@%+=:,./-]+$/.test(a) ? a : `'${a.replace(/'/g, `'\\''`)}'`))
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
function run(cmd, args, { capture = false } = {}) {
|
||||
return spawnSync(cmd, args, {
|
||||
cwd: ROOT,
|
||||
stdio: capture ? ['ignore', 'pipe', 'pipe'] : 'inherit',
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
function main() {
|
||||
let opts;
|
||||
try {
|
||||
opts = parseArgs(process.argv.slice(2));
|
||||
} catch (e) {
|
||||
console.error('[错误] ' + e.message);
|
||||
console.error('用 --help 查看用法。');
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (opts.help) {
|
||||
process.stdout.write(HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(path.join(ROOT, 'Dockerfile'))) {
|
||||
console.error('[错误] 找不到 Dockerfile,请在仓库根目录运行。');
|
||||
return 2;
|
||||
}
|
||||
|
||||
// ---- 1. 检查 docker 是否可用(CLI 缺失和守护进程没起来,处理方式完全不同,分开报) ----
|
||||
// --dry-run 只打印命令、不真的构建,所以这里只警告不拦截,方便在没有 docker 的机器上预览
|
||||
const cli = run('docker', ['--version'], { capture: true });
|
||||
const cliOk = !cli.error && cli.status === 0;
|
||||
if (!cliOk) {
|
||||
const msg = '找不到可用的 docker 命令,请先安装 Docker Desktop / Docker Engine。';
|
||||
if (!opts.dryRun) {
|
||||
console.error('[错误] ' + msg);
|
||||
if (cli.stderr) console.error(String(cli.stderr).trim());
|
||||
return 2;
|
||||
}
|
||||
console.log('[警告] ' + msg + '(dry-run 继续)');
|
||||
} else {
|
||||
console.log('[环境] ' + String(cli.stdout).trim());
|
||||
}
|
||||
|
||||
// 守护进程没启动时,docker build 会报一长串语焉不详的连接错误,这里提前拦下
|
||||
if (cliOk) {
|
||||
const daemon = run('docker', ['info', '--format', '{{.ServerVersion}}'], { capture: true });
|
||||
if (daemon.status !== 0) {
|
||||
const detail = String(daemon.stderr || '').trim();
|
||||
if (!opts.dryRun) {
|
||||
console.error('[错误] docker 守护进程未运行(Docker Desktop 没启动 / 当前用户没权限连 socket)。');
|
||||
if (detail) console.error(detail);
|
||||
return 2;
|
||||
}
|
||||
console.log('[警告] docker 守护进程未运行(dry-run 继续)');
|
||||
} else {
|
||||
console.log('[环境] 守护进程 ' + String(daemon.stdout).trim());
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 2. 收集构建参数:命令行 > 环境变量 > .env > 默认 ----
|
||||
const pkg = readPackage(path.join(ROOT, 'package.json'));
|
||||
const dotenv = readDotEnv(path.join(ROOT, '.env'));
|
||||
const pick = (cliValue, envKey) =>
|
||||
cliValue || process.env[envKey] || dotenv[envKey] || '';
|
||||
|
||||
let aptMirror = pick(opts.aptMirror, 'APT_MIRROR');
|
||||
let npmRegistry = pick(opts.npmRegistry, 'NPM_REGISTRY');
|
||||
const chromeUrl = pick(opts.chromeUrl, 'CHROME_DEB_URL');
|
||||
if (opts.mirror) {
|
||||
// --mirror 只填空位,不覆盖使用者显式给的值
|
||||
if (!aptMirror) aptMirror = MIRROR_PRESET.apt;
|
||||
if (!npmRegistry) npmRegistry = MIRROR_PRESET.npm;
|
||||
}
|
||||
|
||||
const buildArgs = [];
|
||||
if (aptMirror) buildArgs.push('--build-arg', 'APT_MIRROR=' + aptMirror);
|
||||
if (npmRegistry) buildArgs.push('--build-arg', 'NPM_REGISTRY=' + npmRegistry);
|
||||
if (chromeUrl) buildArgs.push('--build-arg', 'CHROME_DEB_URL=' + chromeUrl);
|
||||
// 额外的 --build-arg 放最后,允许覆盖上面的预设
|
||||
for (const kv of opts.buildArgs) buildArgs.push('--build-arg', kv);
|
||||
|
||||
// ---- 3. 标签:没给就按 package.json 的版本号打 version + latest ----
|
||||
const repoName = (pkg.name || 'yun-xue-tang-assistant').toLowerCase();
|
||||
const version = pkg.version || 'dev';
|
||||
const tags = opts.tags.length ? opts.tags : [`${repoName}:${version}`, `${repoName}:latest`];
|
||||
|
||||
const args = ['build'];
|
||||
if (opts.platform) args.push('--platform', opts.platform);
|
||||
if (opts.noCache) args.push('--no-cache');
|
||||
if (opts.pull) args.push('--pull');
|
||||
for (const t of tags) args.push('-t', t);
|
||||
args.push(...buildArgs, '.');
|
||||
|
||||
const cmdline = 'docker ' + quote(args);
|
||||
console.log('[构建] 镜像标签:' + tags.join('、'));
|
||||
console.log('[构建] 上下文:' + ROOT);
|
||||
if (aptMirror) console.log('[构建] APT_MIRROR = ' + aptMirror);
|
||||
if (npmRegistry) console.log('[构建] NPM_REGISTRY = ' + npmRegistry);
|
||||
if (chromeUrl) console.log('[构建] CHROME_DEB_URL= ' + chromeUrl);
|
||||
if (!chromeUrl) console.log('[构建] CHROME_DEB_URL 未指定,将从 dl.google.com 下载(国内网络可能失败,见 README 常见问题)');
|
||||
console.log('[构建] 命令:' + cmdline);
|
||||
console.log('[构建] 首次构建约 3-5 分钟(主要是下 Chrome 的 deb),后续走缓存会快很多。\n');
|
||||
|
||||
if (opts.dryRun) {
|
||||
console.log('[dry-run] 未执行构建。');
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- 4. 真正构建 ----
|
||||
const build = run('docker', args);
|
||||
if (build.error) {
|
||||
console.error('[错误] 启动 docker build 失败:' + build.error.message);
|
||||
return 2;
|
||||
}
|
||||
if (build.status !== 0) {
|
||||
console.error('\n[失败] 构建未通过(退出码 ' + build.status + ')。常见原因:');
|
||||
console.error(' · 拉不到 Chrome deb → 加 --chrome-url <你的镜像地址>,或先配好代理');
|
||||
console.error(' · apt / npm 太慢 → 加 --mirror 换国内源');
|
||||
console.error(' · 依赖变了但缓存没失效 → 加 --no-cache 重来一次');
|
||||
return 1;
|
||||
}
|
||||
|
||||
const primary = tags[0];
|
||||
console.log('\n[完成] 已构建:' + tags.join('、'));
|
||||
|
||||
// ---- 5. 可选自检:只读,不登录、不动课程进度,用来确认镜像真的能起来 ----
|
||||
if (opts.check) {
|
||||
console.log('[自检] 运行 docker run --rm ' + primary + ' --check ...\n');
|
||||
const chk = run('docker', ['run', '--rm', primary, '--check']);
|
||||
if (chk.status !== 0) {
|
||||
console.error('\n[失败] 镜像自检未通过(退出码 ' + chk.status + ')。');
|
||||
return 1;
|
||||
}
|
||||
console.log('\n[自检] 通过:镜像内的 Node、Chrome、构建产物都可用。');
|
||||
}
|
||||
|
||||
console.log(`
|
||||
下一步:
|
||||
# 自检(不需要账号,只读)
|
||||
docker run --rm ${primary} --check
|
||||
|
||||
# 正式刷课(凭据只走环境变量,别写进镜像)
|
||||
docker run -d --name yun-xue-tang \\
|
||||
-e YUN_XUE_TANG_USR='账号' -e YUN_XUE_TANG_PWD='密码' \\
|
||||
-v "$PWD/.run-profile:/app/.run-profile" -v "$PWD/run-logs:/app/run-logs" \\
|
||||
--shm-size=512m --restart on-failure:3 ${primary}
|
||||
|
||||
# 或用 compose(账号写在 .env 里):cp .env.example .env && docker compose up -d
|
||||
`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
process.exit(main());
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
# 构建 Docker 镜像的薄封装(Linux / macOS 用)。
|
||||
# 所有逻辑都在 scripts/build-docker.mjs 里,这里只负责切到仓库根目录再转交。
|
||||
#
|
||||
# ./scripts/build-docker.sh 默认标签
|
||||
# ./scripts/build-docker.sh --mirror --check 国内源 + 构建后自检
|
||||
# ./scripts/build-docker.sh --help
|
||||
set -e
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
exec node scripts/build-docker.mjs "$@"
|
||||
@@ -61,6 +61,35 @@ export function completeCurrent() {
|
||||
later(function () { goToList(true); }, 1200);
|
||||
}
|
||||
|
||||
// 这门课在本轮是否已被判为「无法自动完成」而跳过(目前只有考试交不了的情况)
|
||||
export function courseSkipped(title) {
|
||||
const t = norm(title);
|
||||
return !!(t && (S.skippedCourses || {})[t]);
|
||||
}
|
||||
|
||||
// 跳过这门课,继续下一门。
|
||||
// 只用于「重试也不会好」的确定性失败:考试空卷交卷后平台始终不记账、
|
||||
// 结果页又回不到考试说明页。继续按 failCurrent 退避重试只会反复进同一门课,
|
||||
// 最后停下整轮刷课,其它 5000 多门课也跟着停——所以这里记下原因、本轮不再选它,
|
||||
// 由人工事后处理这门考试。记录只活在本次会话(sessionStorage),重启会重新尝试。
|
||||
export function skipCurrent(reason) {
|
||||
const title = recordTitle();
|
||||
const key = norm(title);
|
||||
if (key) S.skippedCourses[key] = { reason: reason, at: Date.now() };
|
||||
S.activeCourse = null;
|
||||
S.coursePhase = PHASE_IDLE;
|
||||
S.awaitingListReturn = true;
|
||||
R.retryWaitUntil = 0;
|
||||
R.retryTitle = '';
|
||||
// 下一门课重新拉平台实时状态;被跳过的课仍在平台未学完列表里,靠 skippedCourses 排除
|
||||
invalidateShortCatalog();
|
||||
saveRunState();
|
||||
setStatus('已跳过「' + truncate(title || '当前课程', 20) + '」:' + reason + '(继续下一门)');
|
||||
console.warn(TAG, '跳过课程:', title, reason);
|
||||
updatePanel();
|
||||
later(function () { goToList(true); }, 1200);
|
||||
}
|
||||
|
||||
// 课程没学完(不是「跳过」,是「重试」):
|
||||
// 同一门课最多重试 CFG.maxCourseRetries 次,退避等待后重新进这门课;
|
||||
// 超过次数才停止整轮刷课并明确提示——不会把这门课悄悄拉黑、换下一门。
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// ======== 考试结果页的处置决策(纯函数,便于单测) ========
|
||||
//
|
||||
// 交卷后平台会把课程恢复到「考试结果页」。重进课程时也会看到这一页,
|
||||
// 但那次并不是本页刚交的卷 —— 以前把它当成一次空卷交卷,导致:
|
||||
// · examEmptySubmits 虚增,maxExamTries 形同虚设(上限在结果分支之后才检查);
|
||||
// · 结果页 → 回课程页 → 又被恢复到结果页,同一页反复「交卷」,进度永远不动。
|
||||
//
|
||||
// 只有本页确实点过「提交考试 / 确定交卷」,结果页才算一次真实交卷。
|
||||
// 否则先回到考试说明页重新进入考试;回不去才跳过这门课,等人工处理。
|
||||
export 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';
|
||||
}
|
||||
+79
-17
@@ -8,11 +8,12 @@ import { R, S, saveRunState } from './state.js';
|
||||
import { textOf, isVisible, courseIdFromUrl } from './utils.js';
|
||||
import { later } from './lifecycle.js';
|
||||
import { setStatus } from './panel.js';
|
||||
import { failCurrent, completeCurrent } from './complete.js';
|
||||
import { failCurrent, completeCurrent, skipCurrent } from './complete.js';
|
||||
import { readSummary } from './player.js';
|
||||
import { planExamResult } from './exam-plan.js';
|
||||
|
||||
// 只认「考试」相关文案:答题/测验/问卷仍按「需要人工处理」跳过
|
||||
const START_RE = /^(开始考试|继续考试|进入考试)$/;
|
||||
const START_RE = /^(开始考试|继续考试|重新考试|进入考试)$/;
|
||||
const SUBMIT_RE = /^(提交考试|提交试卷|交卷|交卷并退出)$/;
|
||||
// 「交卷」类文案里只有考试独有的几个能用来判定「当前是考试答卷页」;
|
||||
// 「提交试卷」同样会出现在答题/测验页上,不能拿来当考试标志(否则会误抢答题页)。
|
||||
@@ -122,12 +123,13 @@ function confirmState() {
|
||||
|
||||
// 手动刷课(自己点开的课)里出错不应该动队列,只停下并提示;
|
||||
// 批量刷课走 failCurrent(重试退避,超过次数才停止整轮)。
|
||||
function examAbort(reason, manual) {
|
||||
// skip=true:重试也不会好的确定性失败(考试交不了),本轮跳过这门课继续下一门。
|
||||
function examAbort(reason, manual, skip) {
|
||||
if (manual) {
|
||||
setStatus('考试:' + reason);
|
||||
return true;
|
||||
}
|
||||
failCurrent(reason);
|
||||
if (skip) skipCurrent(reason); else failCurrent(reason);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -159,6 +161,9 @@ export function backToCourse() {
|
||||
R.lastCountdown = null;
|
||||
R.lastSummary = null;
|
||||
R.examLeaving = false;
|
||||
// 离开考试页后,再看到的结果页(平台恢复的)就不能再算一次交卷
|
||||
R.examSubmitted = false;
|
||||
R.examPreviewAt = 0;
|
||||
try {
|
||||
const cur = location.href;
|
||||
if (!target || cur === target) {
|
||||
@@ -175,8 +180,53 @@ export function backToCourse() {
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
function finishExam() {
|
||||
// 结果页其实是平台恢复的旧结果(本页没交过卷):回考试说明页重新进入考试。
|
||||
// 交卷后课程页会被恢复到考试结果页,若直接回课程页只会再次看到同一页,
|
||||
// 于是「交卷 → 回课程 → 又是结果页」无限循环,课程进度却不动。
|
||||
function backToPreview() {
|
||||
R.examLeaving = false;
|
||||
const btn = findClickableByText(/^返回考试说明页$/);
|
||||
if (btn) {
|
||||
setStatus('考试:返回考试说明页,重新进入考试…');
|
||||
examClick(btn);
|
||||
return;
|
||||
}
|
||||
// 说明页按钮也找不到:只能退回课程页重进考试节;
|
||||
// 平台若又把我们恢复到结果页,examStaleResults 会累加,最终跳过这门课。
|
||||
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);
|
||||
}
|
||||
|
||||
// plan === 'count':本页确实点了「提交考试/确定交卷」
|
||||
R.examLeaving = true;
|
||||
const key = examCourseKey();
|
||||
if (!S.examEmptySubmits) S.examEmptySubmits = {};
|
||||
@@ -185,16 +235,8 @@ function finishExam() {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -216,6 +258,7 @@ export function examTick(manual) {
|
||||
R.examConfirms = 0;
|
||||
R.examStarts = 0;
|
||||
R.examActionAt = 0;
|
||||
R.examPreviewAt = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -228,6 +271,10 @@ export function examTick(manual) {
|
||||
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('检测到考试:进入考试后直接交卷…');
|
||||
@@ -235,14 +282,15 @@ export function examTick(manual) {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -251,9 +299,14 @@ export function examTick(manual) {
|
||||
const root = examPreviewRoot();
|
||||
const btn = findClickableByText(START_RE, root) || findClickableByText(START_RE);
|
||||
if (!btn) {
|
||||
// 说明页可能永远不给「开始考试」(考试已用完次数/需人工),不能无限等
|
||||
if (now - R.examPreviewAt > 30000) {
|
||||
return examAbort('考试说明页没有「开始考试」按钮,需手动处理', manual, true);
|
||||
}
|
||||
setStatus('考试:未找到「开始考试」按钮,等待页面渲染…');
|
||||
return true;
|
||||
}
|
||||
R.examPreviewAt = 0;
|
||||
R.examActionAt = now;
|
||||
R.examStarts++;
|
||||
if (R.examStarts > Math.max(3, CFG.maxExamTries + 3)) {
|
||||
@@ -273,6 +326,9 @@ export function examTick(manual) {
|
||||
const cs = confirmState();
|
||||
if (cs.shown) {
|
||||
if (!cs.btn) {
|
||||
if (now - R.examPaperAt > 30000) {
|
||||
return examAbort('交卷确认框里没有「确定」按钮', manual);
|
||||
}
|
||||
setStatus('考试:交卷确认框里没找到「确定」按钮');
|
||||
return true;
|
||||
}
|
||||
@@ -281,6 +337,8 @@ export function examTick(manual) {
|
||||
if (R.examConfirms > 6) {
|
||||
return examAbort('交卷确认框点了多次仍未交卷', manual);
|
||||
}
|
||||
// 只有真的点了交卷,之后看到的结果页才算一次空卷交卷
|
||||
R.examSubmitted = true;
|
||||
setStatus('考试:不答题,确认交卷…');
|
||||
examClick(cs.btn);
|
||||
return true;
|
||||
@@ -288,6 +346,9 @@ export function examTick(manual) {
|
||||
|
||||
const sub = findClickableByText(SUBMIT_RE);
|
||||
if (!sub) {
|
||||
if (now - R.examPaperAt > 30000) {
|
||||
return examAbort('答卷页没有「提交考试」按钮', manual);
|
||||
}
|
||||
setStatus('考试:等待「提交考试」按钮…');
|
||||
return true;
|
||||
}
|
||||
@@ -296,6 +357,7 @@ export function examTick(manual) {
|
||||
}
|
||||
R.examActionAt = now;
|
||||
R.examSubmits++;
|
||||
R.examSubmitted = true;
|
||||
setStatus('考试:不答题,直接交卷…');
|
||||
examClick(sub);
|
||||
return true;
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ import {
|
||||
import { courseTick, manualCourseTick } from './course.js';
|
||||
import {
|
||||
stopBatch, retryCount, retryWaiting, retryWaitSeconds,
|
||||
completeCurrent, failCurrent,
|
||||
completeCurrent, failCurrent, skipCurrent, courseSkipped,
|
||||
} from './complete.js';
|
||||
import { examTick, examPhase } from './exam.js';
|
||||
import {
|
||||
@@ -95,7 +95,7 @@ try {
|
||||
sortCardsByDuration, formatDuration,
|
||||
pendingShortItems, invalidateShortCatalog,
|
||||
retryCount, retryWaiting, retryWaitSeconds,
|
||||
completeCurrent, failCurrent,
|
||||
completeCurrent, failCurrent, skipCurrent, courseSkipped,
|
||||
// 以下供开发/真机测试驱动内部路径使用:
|
||||
scanCards, currentPage, maxPageNumber, startCourse, jumpToPage, nextPage,
|
||||
listTick, courseTick, manualCourseTick,
|
||||
|
||||
+6
-5
@@ -7,7 +7,7 @@ import {
|
||||
import { norm, textOf, truncate } from './utils.js';
|
||||
import { clickNode } from './player.js';
|
||||
import { setStatus, updatePanel } from './panel.js';
|
||||
import { failCurrent, stopBatch } from './complete.js';
|
||||
import { failCurrent, stopBatch, courseSkipped } from './complete.js';
|
||||
import { retryWaiting, retryWaitSeconds } from './complete.js';
|
||||
|
||||
export function scanCards() {
|
||||
@@ -357,8 +357,8 @@ export function pendingShortItems() {
|
||||
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;
|
||||
});
|
||||
}
|
||||
@@ -450,7 +450,8 @@ export function chooseShortCourse(cards, pending) {
|
||||
} 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)) {
|
||||
// 缓存与实际状态不一致:剔除这一门,下一 tick 继续挑下一门
|
||||
forgetShortCourse(card.title);
|
||||
return { wait: true };
|
||||
@@ -607,7 +608,7 @@ export function listTick() {
|
||||
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;
|
||||
});
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ export function clearSavedCreds() {
|
||||
}
|
||||
|
||||
export function startBatch() {
|
||||
const freshStart = !S.batchRunning;
|
||||
if (S.batchFinished) {
|
||||
S.completedThisRun = 0;
|
||||
S.batchFinished = false;
|
||||
@@ -147,6 +148,13 @@ export function startBatch() {
|
||||
R.retryWaitUntil = 0;
|
||||
R.retryTitle = '';
|
||||
}
|
||||
if (freshStart) {
|
||||
// 新一轮(含重启后重新开跑):考试相关的本轮记录也清零。
|
||||
// 否则上次会话里的「已跳过 / 已交卷 N 次」会让这门课开跑就被跳过,
|
||||
// 人工处理过考试也得不到重新尝试的机会。
|
||||
S.skippedCourses = {};
|
||||
S.examEmptySubmits = {};
|
||||
}
|
||||
S.batchRunning = true;
|
||||
// 开跑时丢掉旧的时长队列:第一门课也要按平台实时状态挑
|
||||
invalidateShortCatalog();
|
||||
|
||||
+6
-3
@@ -2,7 +2,7 @@
|
||||
// @name 云学堂助手
|
||||
// @namespace yun-xue-tang-assistant.local
|
||||
// @version __YUN_XUE_TANG_VERSION__
|
||||
// @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 次,超过仍没计入进度、或考试页没有可点的
|
||||
* 「开始考试/提交考试」时,本轮跳过这门课继续下一门(会写明原因),不再反复重进。
|
||||
* - 验证码/滑块需要手动完成,脚本不会绕过。
|
||||
* - 课程/单位如有相关规定,请自行确认风险。
|
||||
*
|
||||
|
||||
@@ -54,6 +54,7 @@ export function defaultRunState() {
|
||||
// ---- 本轮记录 ----
|
||||
completedTitles: {}, // 课程名 -> 完成时间戳(防平台记账延迟时重进同一门)
|
||||
courseRetries: {}, // 课程名 -> { n, reason, at }(未完成重试次数)
|
||||
skippedCourses: {}, // 课程名 -> { reason, at }(考试无法自动完成,本轮跳过)
|
||||
examEmptySubmits: {}, // 课程 id -> 空卷交卷次数(防死循环)
|
||||
};
|
||||
}
|
||||
@@ -106,6 +107,7 @@ function restoreFrom(obj) {
|
||||
// ---- 本轮记录 ----
|
||||
out.completedTitles = asMap(obj.completedTitles);
|
||||
out.courseRetries = asMap(obj.courseRetries);
|
||||
out.skippedCourses = asMap(obj.skippedCourses);
|
||||
out.examEmptySubmits = asMap(obj.examEmptySubmits);
|
||||
return out;
|
||||
}
|
||||
@@ -207,6 +209,9 @@ export const R = {
|
||||
// 考试(空卷交卷)自动处理状态
|
||||
examPhase: '', // '' | preview | paper | result
|
||||
examActionAt: 0, // 上次考试页内点击时间
|
||||
examSubmitted: false, // 本页是否真的点过「提交考试/确定交卷」(区分残留结果页)
|
||||
examPreviewAt: 0, // 进入考试说明页的时间(找不到「开始考试」时的超时)
|
||||
examStaleResults: 0, // 本课遇到残留结果页并尝试重进的次数
|
||||
examStarts: 0, // 本形态点了多少次「开始考试」
|
||||
examSubmits: 0, // 本形态点了多少次「提交考试」
|
||||
examConfirms: 0, // 本形态点了多少次交卷确认「确定」
|
||||
@@ -268,6 +273,9 @@ export function resetCourseRuntime() {
|
||||
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;
|
||||
|
||||
+118
-19
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user