feat: v2.8.0 无头运行器、考试自动交卷、改为退避重试不跳课
新增无头运行能力,解决 Linux 无图形化服务器上无法常驻的问题;同时改掉 "遇到考试课/无进展课就跳过"的策略,改为在同门课上退避重试。 - runner/:自己起无头 Chromium,用 CDP 把构建产物注入页面主世界(等价 @grant none),不装插件、不需要桌面环境或 Xvfb;含浏览器探测与启动参数、 持久化 profile、陈旧 SingletonLock 清理、优雅退出、日志轮转、启动预检 - runner.config.mjs / start-headless.cmd:通用配置 + Windows 一键入口; 凭据只走 YUN_XUE_TANG_USR / YUN_XUE_TANG_PWD 环境变量 - src/exam.js:含考试章节的课程自动进考试 → 开始/继续 → 空卷提交 → 确定, 交卷后靠平台记账推进课程;maxExamTries 限制同门课交卷次数,防不记账时死循环 - 去掉跳过与黑名单:没学完就退避重试(30s 起翻倍,最长 5 分钟), 同门课超过 maxCourseRetries 次才停整轮并提示,替代原 maxConsecutiveFailures - 每完成一门都重新拉列表接口取平台实时状态再选下一门,避免用陈旧队列 - 学习进度改存 sessionStorage(yun-xue-tang-run-state-v3),整页跳转/刷新可续; 运行开关不跨会话,浏览器重启后必须显式开跑 - dev/:新增 real-cdp / real-run / real-test / real-e2e 实跑脚本与 check.mjs 统一静态检查(JS 22 + 批处理 2),替代逐文件 node --check - docs/evidence/headless-linux-evidence.txt + 实跑截图,README 补无头部署章节
This commit is contained in:
1 parent
8193326b70
commit
ae117222df
47 files changed
+6198
-837
No files matched your search
+44
-77
@@ -1,9 +1,8 @@
|
||||
// ======== 面板 ========
|
||||
import { CFG, VERSION, LS_ENABLED, LS_PREFER_SHORT, SS_SHORT_CATALOG, PANEL_ID, TAG } from './config.js';
|
||||
import { R, S, state, save } from './state.js';
|
||||
import { R, S, state, saveRunState } from './state.js';
|
||||
import { route } from './route.js';
|
||||
import { isLoginPage, startBatch, doLoginAndStart, clearSavedCreds } from './login.js';
|
||||
import { failCurrent } from './complete.js';
|
||||
|
||||
// 会话时长:面板 footer 显示本次脚本会话自加载起已运行多久
|
||||
const SESSION_START_AT = Date.now();
|
||||
@@ -11,7 +10,6 @@ export let statusEl = null;
|
||||
let statsEl = null;
|
||||
let footerEl = null;
|
||||
let cbBatch = null;
|
||||
let btnSkip = null;
|
||||
let labelAuto = null;
|
||||
let labelBatch = null;
|
||||
let labelShort = null;
|
||||
@@ -28,15 +26,6 @@ let btnClearCreds = null;
|
||||
// 面板里两个复选框行共用同一套 label 样式
|
||||
const LABEL_CSS = 'display:flex;align-items:center;gap:6px;cursor:pointer;margin-top:4px;';
|
||||
|
||||
// 「跳过本课」/「清除失败记录」共用一套按钮样式,只有 display 不同
|
||||
function smallBtnCss(display) {
|
||||
return [
|
||||
'display:' + display, 'margin-top:6px', 'padding:2px 8px', 'cursor:pointer',
|
||||
'background:#444', 'color:#eee', 'border:1px solid #666', 'border-radius:4px',
|
||||
'font-size:12px',
|
||||
].join(';');
|
||||
}
|
||||
|
||||
function formatElapsed(ms) {
|
||||
const total = Math.max(0, Math.floor(ms / 1000));
|
||||
const h = Math.floor(total / 3600);
|
||||
@@ -52,22 +41,23 @@ export function setStatus(text) {
|
||||
}
|
||||
|
||||
export function updatePanel() {
|
||||
if (cbBatch) cbBatch.checked = S.running;
|
||||
if (cbBatch) cbBatch.checked = S.batchRunning;
|
||||
if (statsEl) {
|
||||
const limit = CFG.maxCourses > 0 ? CFG.maxCourses : '∞';
|
||||
statsEl.textContent =
|
||||
'本次 ' + S.completedThisRun + '/' + limit +
|
||||
' · 失败 ' + Object.keys(S.failed).length +
|
||||
(R.idlePassed ? ' · 验证 ' + R.idlePassed : '');
|
||||
let text = '本次 ' + S.completedThisRun + '/' + limit;
|
||||
const retryTitles = Object.keys(S.courseRetries || {}).length;
|
||||
if (retryTitles) text += ' · 待重试 ' + retryTitles;
|
||||
if (R.retryWaitUntil && Date.now() < R.retryWaitUntil) {
|
||||
text += ' · ' + Math.ceil((R.retryWaitUntil - Date.now()) / 1000) + 's 后重试';
|
||||
}
|
||||
text += (R.idlePassed ? ' · 验证 ' + R.idlePassed : '');
|
||||
statsEl.textContent = text;
|
||||
}
|
||||
if (footerEl) {
|
||||
footerEl.textContent = '会话时长 ' + formatElapsed(Date.now() - SESSION_START_AT);
|
||||
}
|
||||
if (btnSkip) {
|
||||
btnSkip.style.display = S.current && route() === 'course' ? 'block' : 'none';
|
||||
}
|
||||
if (cbAuto) cbAuto.checked = state.enabled;
|
||||
if (cbPreferShort) cbPreferShort.checked = state.preferShort;
|
||||
if (cbAuto) cbAuto.checked = state.autoPlayEnabled;
|
||||
if (cbPreferShort) cbPreferShort.checked = state.preferShortCourses;
|
||||
|
||||
const onLogin = isLoginPage();
|
||||
if (loginBox) loginBox.style.display = onLogin ? 'block' : 'none';
|
||||
@@ -77,11 +67,11 @@ export function updatePanel() {
|
||||
if (statsEl) statsEl.style.display = onLogin ? 'none' : 'block';
|
||||
if (btnOne) {
|
||||
// 「停止刷课」只在播放页出现;列表页等位置始终显示「一键刷课」
|
||||
const onCourse = route() === 'course' && !!S.current;
|
||||
const onCourse = route() === 'course' && !!S.activeCourse;
|
||||
btnOne.textContent = onLogin
|
||||
? '一键登录并刷课'
|
||||
: (onCourse && S.running ? '停止刷课' : '一键刷课');
|
||||
btnOne.title = onCourse && S.running ? '停止批量刷课' : '开始 / 继续批量刷课';
|
||||
: (onCourse && S.batchRunning ? '停止刷课' : '一键刷课');
|
||||
btnOne.title = onCourse && S.batchRunning ? '停止列表刷课' : '开始 / 继续列表刷课';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +97,7 @@ export function buildPanel() {
|
||||
titleText.style.cssText = 'font-weight:600;';
|
||||
|
||||
const titleVer = document.createElement('span');
|
||||
titleVer.id = 'yt-version';
|
||||
titleVer.id = 'yun-xue-tang-version';
|
||||
titleVer.textContent = 'v' + VERSION;
|
||||
titleVer.title = '脚本版本 v' + VERSION;
|
||||
titleVer.style.cssText = 'font-weight:400;font-size:10px;color:#8ee6c0;opacity:.85;';
|
||||
@@ -117,7 +107,7 @@ export function buildPanel() {
|
||||
|
||||
btnOne = document.createElement('button');
|
||||
btnOne.type = 'button';
|
||||
btnOne.id = 'yt-oneclick';
|
||||
btnOne.id = 'yun-xue-tang-oneclick';
|
||||
btnOne.textContent = '一键刷课';
|
||||
btnOne.style.cssText = [
|
||||
'width:100%', 'margin:2px 0 6px', 'padding:5px 8px', 'cursor:pointer',
|
||||
@@ -130,10 +120,10 @@ export function buildPanel() {
|
||||
return;
|
||||
}
|
||||
// 只有播放页的按钮才是「停止」;列表页/门户页点它一律是开始/继续,避免误停
|
||||
if (route() === 'course' && S.current && S.running) {
|
||||
S.running = false;
|
||||
save();
|
||||
setStatus('自动刷课已暂停');
|
||||
if (route() === 'course' && S.activeCourse && S.batchRunning) {
|
||||
S.batchRunning = false;
|
||||
saveRunState();
|
||||
setStatus('列表刷课已暂停');
|
||||
} else {
|
||||
startBatch();
|
||||
}
|
||||
@@ -141,7 +131,7 @@ export function buildPanel() {
|
||||
});
|
||||
|
||||
loginBox = document.createElement('div');
|
||||
loginBox.id = 'yt-login-box';
|
||||
loginBox.id = 'yun-xue-tang-login-box';
|
||||
loginBox.style.cssText = 'display:none;margin-bottom:6px;';
|
||||
|
||||
const mkInput = function (id, type, ph) {
|
||||
@@ -157,8 +147,8 @@ export function buildPanel() {
|
||||
].join(';');
|
||||
return el;
|
||||
};
|
||||
loginUserEl = mkInput('yt-login-user', 'text', '员工邮箱/账号');
|
||||
loginPassEl = mkInput('yt-login-pass', 'password', '密码');
|
||||
loginUserEl = mkInput('yun-xue-tang-login-user', 'text', '员工邮箱/账号');
|
||||
loginPassEl = mkInput('yun-xue-tang-login-pass', 'password', '密码');
|
||||
|
||||
const mkCheck = function (id, text) {
|
||||
const label = document.createElement('label');
|
||||
@@ -170,9 +160,9 @@ export function buildPanel() {
|
||||
label.appendChild(document.createTextNode(text));
|
||||
return { label: label, cb: cb };
|
||||
};
|
||||
const rem = mkCheck('yt-login-remember', '记住密码');
|
||||
const rem = mkCheck('yun-xue-tang-login-remember', '记住密码');
|
||||
loginRememberEl = rem.cb;
|
||||
const auto = mkCheck('yt-login-auto', '自动登录');
|
||||
const auto = mkCheck('yun-xue-tang-login-auto', '自动登录');
|
||||
loginAutoEl = auto.cb;
|
||||
loginRememberEl.addEventListener('change', function () {
|
||||
if (!loginRememberEl.checked) clearSavedCreds();
|
||||
@@ -211,46 +201,46 @@ export function buildPanel() {
|
||||
labelAuto.style.cssText = 'display:flex;align-items:center;gap:6px;cursor:pointer;';
|
||||
cbAuto = document.createElement('input');
|
||||
cbAuto.type = 'checkbox';
|
||||
cbAuto.id = 'yt-auto-enabled';
|
||||
cbAuto.checked = state.enabled;
|
||||
cbAuto.id = 'yun-xue-tang-auto-enabled';
|
||||
cbAuto.checked = state.autoPlayEnabled;
|
||||
cbAuto.addEventListener('change', function () {
|
||||
state.enabled = cbAuto.checked;
|
||||
state.autoPlayEnabled = cbAuto.checked;
|
||||
try { localStorage.setItem(LS_ENABLED, cbAuto.checked ? '1' : '0'); } catch (e) {}
|
||||
setStatus(cbAuto.checked ? '自动连播已开启' : '自动连播已关闭');
|
||||
});
|
||||
labelAuto.appendChild(cbAuto);
|
||||
labelAuto.appendChild(document.createTextNode('手动课程自动连播'));
|
||||
labelAuto.appendChild(document.createTextNode('当前课程自动连播'));
|
||||
|
||||
labelBatch = document.createElement('label');
|
||||
labelBatch.style.cssText = LABEL_CSS;
|
||||
cbBatch = document.createElement('input');
|
||||
cbBatch.type = 'checkbox';
|
||||
cbBatch.id = 'yt-batch-enabled';
|
||||
cbBatch.checked = S.running;
|
||||
cbBatch.id = 'yun-xue-tang-batch-enabled';
|
||||
cbBatch.checked = S.batchRunning;
|
||||
cbBatch.addEventListener('change', function () {
|
||||
if (cbBatch.checked) {
|
||||
startBatch();
|
||||
} else {
|
||||
S.running = false;
|
||||
save();
|
||||
setStatus('自动刷课已暂停');
|
||||
S.batchRunning = false;
|
||||
saveRunState();
|
||||
setStatus('列表刷课已暂停');
|
||||
}
|
||||
updatePanel();
|
||||
});
|
||||
labelBatch.appendChild(cbBatch);
|
||||
labelBatch.appendChild(document.createTextNode('自动刷课(批量)'));
|
||||
labelBatch.appendChild(document.createTextNode('课程列表自动刷课'));
|
||||
|
||||
labelShort = document.createElement('label');
|
||||
labelShort.style.cssText = LABEL_CSS;
|
||||
cbPreferShort = document.createElement('input');
|
||||
cbPreferShort.type = 'checkbox';
|
||||
cbPreferShort.id = 'yt-prefer-short';
|
||||
cbPreferShort.checked = state.preferShort;
|
||||
cbPreferShort.id = 'yun-xue-tang-prefer-short';
|
||||
cbPreferShort.checked = state.preferShortCourses;
|
||||
cbPreferShort.title = '按课程总时长从短到长选课';
|
||||
cbPreferShort.addEventListener('change', function () {
|
||||
state.preferShort = cbPreferShort.checked;
|
||||
try { localStorage.setItem(LS_PREFER_SHORT, state.preferShort ? '1' : '0'); } catch (e) {}
|
||||
if (!state.preferShort) {
|
||||
state.preferShortCourses = cbPreferShort.checked;
|
||||
try { localStorage.setItem(LS_PREFER_SHORT, state.preferShortCourses ? '1' : '0'); } catch (e) {}
|
||||
if (!state.preferShortCourses) {
|
||||
R.shortCatalog = null;
|
||||
R.shortCatalogLoading = false;
|
||||
R.shortCatalogFailedAt = 0;
|
||||
@@ -266,41 +256,20 @@ export function buildPanel() {
|
||||
labelShort.appendChild(document.createTextNode('优先短课程(时长正序)'));
|
||||
|
||||
statusEl = document.createElement('div');
|
||||
statusEl.id = 'yt-status';
|
||||
statusEl.id = 'yun-xue-tang-status';
|
||||
statusEl.textContent = '待机';
|
||||
statusEl.style.cssText = 'margin-top:6px;color:#8ee6c0;word-break:break-all;';
|
||||
|
||||
statsEl = document.createElement('div');
|
||||
statsEl.id = 'yt-stats';
|
||||
statsEl.id = 'yun-xue-tang-stats';
|
||||
statsEl.style.cssText = 'margin-top:2px;color:#aaa;';
|
||||
|
||||
btnSkip = document.createElement('button');
|
||||
btnSkip.type = 'button';
|
||||
btnSkip.textContent = '跳过本课';
|
||||
btnSkip.style.cssText = smallBtnCss('none');
|
||||
btnSkip.addEventListener('click', function () {
|
||||
if (S.current) failCurrent('手动跳过');
|
||||
});
|
||||
|
||||
const clearFail = document.createElement('button');
|
||||
clearFail.type = 'button';
|
||||
clearFail.textContent = '清除失败记录';
|
||||
clearFail.style.cssText = smallBtnCss('inline-block');
|
||||
clearFail.addEventListener('click', function () {
|
||||
S.failed = {};
|
||||
S.consecutiveFailures = 0;
|
||||
S.runFinished = false;
|
||||
save();
|
||||
updatePanel();
|
||||
setStatus('已清除失败记录');
|
||||
});
|
||||
|
||||
const hint = document.createElement('div');
|
||||
hint.textContent = '真实播放计时 · 保持窗口可见';
|
||||
hint.style.cssText = 'margin-top:6px;color:#777;font-size:11px;';
|
||||
|
||||
const footer = document.createElement('div');
|
||||
footer.id = 'yt-session-duration';
|
||||
footer.id = 'yun-xue-tang-session-duration';
|
||||
footer.textContent = '会话时长 ' + formatElapsed(0);
|
||||
footer.style.cssText = 'margin-top:4px;color:#8ee6c0;font-size:11px;';
|
||||
footerEl = footer;
|
||||
@@ -313,8 +282,6 @@ export function buildPanel() {
|
||||
box.appendChild(labelShort);
|
||||
box.appendChild(statusEl);
|
||||
box.appendChild(statsEl);
|
||||
box.appendChild(btnSkip);
|
||||
box.appendChild(clearFail);
|
||||
box.appendChild(hint);
|
||||
box.appendChild(footer);
|
||||
document.documentElement.appendChild(box);
|
||||
|
||||
Reference in new issue
Block a user