// ==UserScript==
// @name 🔥优学院最牛逼脚本视频挂机 + 章节测试自动答题(优学院刷课)
// @namespace course_helper_dashboard_v62
// @version 8.9.1
// @description 优学院学习页全屏数据面板:完全隐藏原页面,只显示 章节目录 + 学习进度数据(总进度 已完成/上锁/总数、视频进度、完成情况、作者/捐赠与反馈/使用提示/课程/课程切换/版本号)。目录可展开跳转;上锁页(页面 .page-item.is-hide)识别并跳过:自动定位/主循环/手动点击均跳过上锁页,目录树灰色+🔒标记;进入课程章节页自动打开面板,返回原页面后有悬浮"返回面板"按钮;后台自动播放视频/作答章节测试/翻页,每 60s 日志报一次视频进度秒数,视频日志以章节名标识;设置卡片含视频倍速(>1倍风险提示)与最低正确率(低于阈值不自动提交);课程工作台等页面悬浮提示含"直接开始学习"按钮。v8.8.0:设置卡片新增"章节讨论自动填写(不提交)"(默认开,把 questionAnswer 接口 correctreply 里的官方参考答案填进讨论/简答输入框,日志同步打出填入内容,脚本不点提交、直接翻页,不卡在题页等人工确认)与"章节讨论自动提交"(默认关,填完自动提交并翻页)两个独立开关;视频倍速取消上限(可输入任意倍速,浏览器自身约 16x 封顶,写入前按上限收口,起播与播放中都会把倍速压回设定值)。v8.9.0:适配「视频章节内嵌答题」新题型——视频播放途中弹出的 video-question-modal 练习题不再被当成普通弹窗;自动识别题目、作答、逐题提交并补点整页提交,答完不翻页,等站点提示「答题结束」后视频自动续播;答题弹窗卡死时有兜底放行,新增「视频内嵌答题」开关(默认开)。v8.9.1:面板微调——「捐赠」卡片改为「捐赠与反馈」(跳转地址不变),作者卡片新增「联系作者」按钮(与捐赠同一页面),新增「使用提示」说明卡片。
// @tag 优学院
// @tag 答题辅助
// @tag 自动播放
// @tag 视频
// @tag 学习辅助
// @tag 优学院刷课
// @tag 优学院答题
// @match *://*.ulearning.cn/*
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-end
// @license MIT
// ==/UserScript==
(function () {
'use strict';
const $ = (typeof unsafeWindow !== 'undefined' && unsafeWindow.jQuery) || window.jQuery;
/* ========== 版本号(与 @version 保持一致) ========== */
const SCRIPT_VERSION = '8.9.1';
function scriptVersion() {
try {
if (typeof GM_info !== 'undefined' && GM_info.script && GM_info.script.version) return GM_info.script.version;
} catch (e) { }
return SCRIPT_VERSION;
}
/* ========== 配置(持久化) ========== */
const STORAGE_KEY = 'course_helper_config_v62';
const DEFAULT_CONFIG = { videoTask: true, videoRate: 1, examTask: true, minAccuracy: 100, discussFill: true, discussSubmit: false, videoQuiz: true };
function loadConfig() {
try { return Object.assign({}, DEFAULT_CONFIG, JSON.parse(GM_getValue(STORAGE_KEY, '{}'))); }
catch (e) { return Object.assign({}, DEFAULT_CONFIG); }
}
function saveConfig(k, v) {
const c = loadConfig(); c[k] = v;
try { GM_setValue(STORAGE_KEY, JSON.stringify(c)); } catch (e) { }
}
let config = loadConfig();
let isRunning = false;
let runTimer = null;
let tree = []; // 目录树: chapter > section > page
let activeEntry = null; // 当前页面条目
/* ========== 视频完成判定参数(与 yxy1 v3 一致) ========== */
const VIDEO_END_TOLERANCE = 1;
const FINISH_FALLBACK_CHECKS = 2;
const FINISH_SAFETY_CHECKS = 20;
const STALL_RETRY_MS = 8000;
const STALL_RETRY_GAP_MS = 15000;
const NEXT_CLICK_GAP_MS = 5000;
const QUIZ_HOLD_LIMIT = 2; // 章节测试同一页最多重试几帧,超过就不再刷屏并翻页
const runState = {
lastMediaCount: 0,
finishStable: {}, doneSeen: {}, finishLogged: {}, forcedLogged: {},
_nextScheduled: false, _lastNextClick: 0, _lastModal: '', _allDoneLogged: false,
_lastQuizDoneKey: null, quizHold: {},
vq: {}, // 视频内嵌答题弹窗状态(按 弹窗ID+题目集合 分桶)
};
/* ========== 工具函数 ========== */
function el(tag, cls) {
const d = document.createElement(tag);
if (cls) d.className = cls;
return d;
}
function textOf(scope, sel) {
try {
const n = scope.querySelector(sel);
return n ? n.textContent.trim() : '';
} catch (e) { return ''; }
}
function pad(n) { return String(n).padStart(2, '0'); }
function log(text, color) {
const box = document.getElementById('logBox');
if (!box) return;
const now = new Date();
const t = '[' + pad(now.getHours()) + ':' + pad(now.getMinutes()) + ':' + pad(now.getSeconds()) + '] ';
const d = el('div');
const ts = el('span'); ts.style.color = '#475569'; ts.textContent = t;
const msg = el('span'); msg.style.color = color || '#cbd5e1'; msg.textContent = text;
d.appendChild(ts); d.appendChild(msg);
box.appendChild(d);
while (box.children.length > 400) box.removeChild(box.firstChild);
box.scrollTop = box.scrollHeight;
}
function setStatus(text, color) {
const s = document.getElementById('yxStatus');
if (!s) return;
s.textContent = text;
s.style.background = color || '#64748b';
}
// 章节名(截断用于日志)
function shortName(n) {
const s = String(n || '');
return s.length > 26 ? s.slice(0, 26) + '…' : s;
}
// 视频日志前缀: 优先用当前章节/页面名, 一页多视频时附带序号
function videoTag(i, total) {
const name = (activeEntry && activeEntry.name) ? shortName(activeEntry.name) : ('视频 ' + (i + 1));
return (total && total > 1) ? ('「' + name + '」第' + (i + 1) + '个') : ('「' + name + '」');
}
/* ---- 题页识别: 页面内的章节测试/讨论页 vs 视频播放中弹出的答题弹窗 ---- */
// 页面内的题页(章节测试/章节讨论):.question-setting-panel 直接挂在页面内容里
function $pageQuizPanel() {
return $(".question-setting-panel").filter(function () {
return !$(this).closest('.modal').length;
});
}
// 视频内嵌答题弹窗:优学院视频页播放到指定时间会弹出
//
里面装 question-view。
// 兼容两种情况:class 带 in / 仅 style.display=block;以及站点换 class 但
// 弹窗内仍有 .question-setting-panel 或 .video-question-end。
function $videoQuizModal() {
const list = document.querySelectorAll('.modal');
for (let i = 0; i < list.length; i++) {
const n = list[i];
const opened = n.classList.contains('in') || (n.style && n.style.display === 'block');
if (!opened) continue;
// 有些页面关弹窗后只去掉 display 却留着 in,这里再用实际布局兜一层
if (!n.getClientRects().length) continue;
// class 是 video-question-modal 的直接认;站点换 class 时再看内容特征
if (!n.classList.contains('video-question-modal') &&
!n.querySelector('.question-setting-panel') &&
!n.querySelector('.video-question-end')) continue;
return $(n);
}
return $();
}
// 可点击的「提交」按钮(排除 disabled / .disable / .disabled / 不可见)
function findSubmitBtn($scope) {
return $scope.find('button').filter(function () {
const $b = $(this);
if (this.disabled || $b.hasClass('disable') || $b.hasClass('disabled')) return false;
if (!$b.is(':visible')) return false;
const t = $b.text().trim();
return t === '提交' || t === 'Submit';
}).eq(0);
}
/* =====================================================================
目录提取 —— 按真实 DOM 层级: .catalog-list > .chapter-item
> .section-item > .page-item > .page-name
===================================================================== */
// 读取元素上的 Knockout 绑定上下文(页面 KO 数据; 用于绕过懒渲染拿全量数据)
function koDataOf(el) {
try {
if (!el) return null;
if (window.ko && typeof window.ko.dataFor === 'function') {
const d = window.ko.dataFor(el);
if (d) return d;
}
if (window.jQuery && typeof window.jQuery.data === 'function') {
const d = window.jQuery.data(el, '__ko_data__');
if (d) return d;
}
if (el.__ko_data__) return el.__ko_data__;
} catch (e) { }
return null;
}
// 安全调用 VM 方法(observable)取字符串
function safeFn(v, fn) {
try {
if (v && typeof v[fn] === 'function') {
const r = v[fn]();
return r == null ? '' : String(r);
}
} catch (e) { }
return '';
}
// 按 id 在章节 children 里找小节
function findSecById(secs, id) {
for (let i = 0; i < secs.length; i++) {
if (secs[i].id === id) return secs[i];
}
return null;
}
// 展开原页面目录里"内容为空"的小节/章节, 驱动 KO 懒渲染(KO 展开时按需创建页面节点)
// 完成后回调 cb; 已渲染的绝不点击, 避免把已展开的收起
function expandOriginalCatalog(cb) {
let rounds = 0;
(function tick() {
let acted = false;
document.querySelectorAll('.catalog-list > .chapter-item').forEach(function (chEl) {
const secList = chEl.querySelector(':scope > .section-list');
if (!secList) return;
if (!secList.querySelector(':scope > .section-item')) {
const h = chEl.querySelector(':scope > .chapter-name');
if (h && h.__yxExpanded !== 1) {
try { h.click(); } catch (e) { }
h.__yxExpanded = 1;
acted = true;
}
return;
}
secList.querySelectorAll(':scope > .section-item').forEach(function (secEl) {
const pageList = secEl.querySelector(':scope > .page-list');
if (pageList && !pageList.querySelector(':scope > .page-item')) {
const h = secEl.querySelector(':scope > .section-name');
if (h && h.__yxExpanded !== 1) {
try { h.click(); } catch (e) { }
h.__yxExpanded = 1;
acted = true;
}
}
});
});
if (!acted || ++rounds > 12) { cb(); return; } // 轮询上限 ~3s
setTimeout(tick, 250);
})();
}
// 驱动渲染指定页所在的 小节/章节(自动执行跳转到未渲染页面时调用)
function ensurePageDom(pg) {
try {
let acted = false;
if (pg.sectionEl) {
const pageList = pg.sectionEl.querySelector(':scope > .page-list');
if (pageList && !pageList.querySelector(':scope > .page-item')) {
const h = pg.sectionEl.querySelector(':scope > .section-name');
if (h) { try { h.click(); } catch (e) { } acted = true; }
}
}
if (pg.chapterEl) {
const secList = pg.chapterEl.querySelector(':scope > .section-list');
if (secList && !secList.querySelector(':scope > .section-item')) {
const h = pg.chapterEl.querySelector(':scope > .chapter-name');
if (h) { try { h.click(); } catch (e) { } acted = true; }
}
}
return acted;
} catch (e) { return false; }
}
// 逐章节真实切换渲染: 每个章节点击章节头切换 + 点其第一个未上锁页真实跳转,
// 触发 KO 渲染出该章节全部页面节点(懒渲染), 全部章节过完后回调
function renderAllChapters(cb) {
const heads = [];
document.querySelectorAll('.catalog-list > .chapter-item').forEach(function (chEl) {
const h = chEl.querySelector(':scope > .chapter-name');
if (h) heads.push({ chEl: chEl, head: h });
});
let i = 0;
(function next() {
if (i >= heads.length) { cb(); return; }
const cur = heads[i++];
// 1) 点击章节头切换 currentChapter
try { cur.head.click(); } catch (e) { }
// 2) 轮询等待该章节出现页面节点(懒渲染), 最多 ~1.5s
let tries = 0;
(function waitPage() {
let target = null;
cur.chEl.querySelectorAll(':scope > .section-list .page-name').forEach(function (nm) {
if (target) return;
const item = nm.closest('.page-item');
if (item && !pageElLocked(item)) target = nm; // 跳过上锁页
});
if (target) {
// 3) 真实跳转到该章节第一页, 触发完整渲染
try { target.click(); } catch (e) { }
setTimeout(next, 450);
return;
}
if (++tries > 15) { setTimeout(next, 200); return; }
setTimeout(waitPage, 100);
})();
})();
}
// 渲染后刷新页面的 element 引用(原节点可能被 KO 重建)
function refreshPageElement(pg) {
try {
if (!pg || !pg.id || !pg.sectionEl) return false;
const el = pg.sectionEl.querySelector(':scope > .page-list > .page-item[id="page' + pg.id + '"] .page-name');
if (el) { pg.element = el; return true; }
} catch (e) { }
return false;
}
function extractTree() {
const data = [];
activeEntry = null;
let order = 0;
document.querySelectorAll('.catalog-list > .chapter-item').forEach(function (chEl) {
const ch = {
kind: 'chapter',
name: textOf(chEl, ':scope > .chapter-name .text'),
element: chEl.querySelector(':scope > .chapter-name'),
children: [], expanded: false,
done: 0, total: 0, domBadge: null,
};
// 1) DOM 已渲染部分
chEl.querySelectorAll(':scope > .section-list > .section-item').forEach(function (secEl) {
const sec = {
kind: 'section',
id: secEl.id ? secEl.id.replace(/^section/, '') : '',
name: textOf(secEl, ':scope > .section-name .text'),
element: secEl.querySelector(':scope > .section-name'),
chapterEl: chEl, sectionEl: secEl,
children: [], expanded: false,
};
secEl.querySelectorAll(':scope > .page-list > .page-item').forEach(function (pEl) {
const clickEl = pEl.querySelector(':scope > .page-name');
const nameEl = pEl.querySelector('span[data-bind="text: page.name()"]');
if (!clickEl || !nameEl) return;
const isComplete = clickEl.classList.contains('complete');
const isLocked = pageElLocked(pEl);
const hasIcon = !!pEl.querySelector(':scope > .page-name .page-icon i.iconfont:not(.finish)');
const pg = {
kind: 'page',
index: order++,
id: pEl.id ? pEl.id.replace(/^page/, '') : '',
name: nameEl.textContent.trim(),
element: clickEl,
chapterEl: chEl, sectionEl: secEl,
isActive: clickEl.classList.contains('active'),
isComplete: isComplete,
isLocked: isLocked,
__hasIcon: hasIcon,
icon: isComplete ? '✓' : (isLocked ? '🔒' : (hasIcon ? '▶' : '✎')),
dom: null,
};
if (pg.isActive) activeEntry = pg;
sec.children.push(pg);
});
ch.children.push(sec); // 空小节也保留(懒渲染页面由 KO 补充, 保留 sectionEl 关联)
});
// 2) KO VM 补充: 懒渲染未出现在 DOM 的 小节/页面(统计与自动定位全量)
const chVM = koDataOf(chEl);
if (chVM && typeof chVM.sections === 'function') {
let secs = [];
try { secs = chVM.sections() || []; } catch (e) { secs = []; }
secs.forEach(function (secVM, si) {
const secId = safeFn(secVM, 'id');
let sec = findSecById(ch.children, secId);
if (!sec && ch.children[si] && !ch.children[si].id) sec = ch.children[si];
if (!sec) {
sec = {
kind: 'section', id: secId,
name: safeFn(secVM, 'name'),
element: null, chapterEl: chEl, sectionEl: null,
children: [], expanded: false,
};
}
let pages = [];
try { pages = (typeof secVM.pages === 'function') ? (secVM.pages() || []) : []; } catch (e) { pages = []; }
const have = {};
sec.children.forEach(function (p) { if (p.id) have[p.id] = 1; });
pages.forEach(function (pgVM, pi) {
const pgId = safeFn(pgVM, 'id');
if (pgId && have[pgId]) return;
const name = safeFn(pgVM, 'name');
if (!name) return;
let done = false, locked = false;
try { done = !!(pgVM.record && pgVM.record() && pgVM.record().status && pgVM.record().status()); } catch (e) { }
try { locked = !!(pgVM.isHide && pgVM.isHide()); } catch (e) { }
let pEl = null;
if (sec.sectionEl) {
if (pgId) pEl = sec.sectionEl.querySelector(':scope > .page-list > .page-item[id="page' + pgId + '"]');
if (!pEl) {
const items = sec.sectionEl.querySelectorAll(':scope > .page-list > .page-item');
if (items[pi]) pEl = items[pi];
}
}
const clickEl = pEl ? pEl.querySelector(':scope > .page-name') : null;
const pg = {
kind: 'page',
index: order++,
id: pgId,
name: name,
element: clickEl,
chapterEl: chEl, sectionEl: sec.sectionEl,
isActive: !!(clickEl && clickEl.classList.contains('active')),
isComplete: done,
isLocked: locked,
__hasIcon: false,
icon: done ? '✓' : (locked ? '🔒' : '✎'),
dom: null,
};
if (pg.isActive) activeEntry = pg;
sec.children.push(pg);
});
if (!findSecById(ch.children, secId) && sec.children.length) ch.children.push(sec);
});
}
if (ch.children.length) data.push(ch);
});
return data;
}
function getFlatPages() {
const out = [];
(function walk(arr) {
arr.forEach(function (n) {
if (n.kind === 'page') out.push(n);
else if (n.children) walk(n.children);
});
})(tree);
return out;
}
/* ---- 完成状态工具: 以目录 .page-name.complete 类为准(对应 page.record().status()) ---- */
// 上锁页标记: .page-item.is-hide(绑定 page.isHide()); 兼容 lock 类 / lock 图标
function pageElLocked(itemEl) {
try {
if (!itemEl) return false;
if (itemEl.classList.contains('is-hide')) return true;
const nm = itemEl.querySelector(':scope > .page-name');
if (nm && (nm.classList.contains('is-hide') || nm.classList.contains('lock'))) return true;
if (itemEl.querySelector('.lock-icon, i.iconfont.lock')) return true;
} catch (e) { }
return false;
}
function isPageLocked(p) {
if (!p || !p.element) return !!p.isLocked;
const itemEl = p.element.parentElement; // .page-item
if (itemEl && pageElLocked(itemEl)) return true;
return !!p.isLocked;
}
function isPageDone(p) {
if (!p || !p.element) return !!p.isComplete;
return p.element.classList.contains('complete');
}
function firstIncompletePage() {
const pages = getFlatPages();
for (let i = 0; i < pages.length; i++) {
if (isPageLocked(pages[i])) continue; // 跳过已上锁页
if (!isPageDone(pages[i])) return pages[i];
}
return null;
}
function jumpFirstIncomplete(reason) {
const p = firstIncompletePage();
if (!p) {
log('所有页面均已完成,无需继续', '#34d399');
return false;
}
if (activeEntry && activeEntry === p) {
log('当前已是第一个未完成页:' + p.name, '#2dd4bf');
return true;
}
selectPage(p);
log((reason ? reason + ':' : '') + '已定位到第一个未完成页「' + p.name + '」', '#2dd4bf');
return true;
}
// 刷新完成态: 页面图标 + 专题完成数徽章 + 统计面板
function refreshCompletion() {
const pages = getFlatPages();
pages.forEach(function (p) {
if (!p.element) return;
const done = p.element.classList.contains('complete');
const locked = isPageLocked(p);
const changed = (done !== p.isComplete) || (locked !== p.isLocked);
p.isComplete = done; p.isLocked = locked;
if (changed && p.dom) {
p.icon = done ? '✓' : (locked ? '🔒' : (p.__hasIcon ? '▶' : '✎'));
const ico = p.dom.querySelector('.yx-pico');
if (ico) {
ico.textContent = p.icon;
ico.style.background = locked ? '#f1f5f9' : (done ? '#dcfce7' : (p.icon === '▶' ? '#dbeafe' : '#f3e8ff'));
ico.style.color = locked ? '#94a3b8' : (done ? '#16a34a' : (p.icon === '▶' ? '#2563eb' : '#9333ea'));
}
p.dom.classList.toggle('locked', locked);
}
});
tree.forEach(function (ch) {
let d = 0, t = 0, l = 0;
(function walk(arr) {
arr.forEach(function (n) {
if (n.kind === 'page') { t++; if (isPageLocked(n)) l++; else if (isPageDone(n)) d++; }
else if (n.children) walk(n.children);
});
})(ch.children);
ch.done = d; ch.total = t;
if (ch.domBadge) {
const ach = Math.max(0, t - l); // 可完成数 = 总数 - 上锁数
ch.domBadge.textContent = d + '/' + ach;
ch.domBadge.style.background = (ach > 0 && d >= ach) ? '#dcfce7' : '#f1f5f9';
ch.domBadge.style.color = (ach > 0 && d >= ach) ? '#16a34a' : '#64748b';
ch.domBadge.title = (l > 0 ? (l + ' 页上锁 · ') : '') + d + ' / ' + ach + ' 已完成';
}
});
}
// 展开包含当前页的 专题/小节
function markExpanded(arr, target) {
arr.forEach(function (n) {
if (!n.children) return;
const has = (function hasTarget(list) {
return list.some(function (x) { return x === target || (x.children && hasTarget(x.children)); });
})(n.children);
if (has) n.expanded = true;
markExpanded(n.children, target);
});
}
// 跟随执行位置: 自动展开包含当前页的专题/小节, 返回是否有新展开
function ensureActiveExpanded() {
if (!activeEntry) return false;
let changed = false;
tree.forEach(function (ch) {
(function walk(arr, path) {
arr.forEach(function (n) {
if (n.kind === 'page') {
if (n === activeEntry) {
path.forEach(function (anc) {
if (!anc.expanded) { anc.expanded = true; changed = true; }
});
}
} else if (n.children) walk(n.children, path.concat(n));
});
})(ch.children, [ch]);
});
return changed;
}
/* ========== 目录渲染 ========== */
function renderSidebar() {
const list = document.getElementById('chapterList');
if (!list) return;
list.innerHTML = '';
tree.forEach(function (ch) { list.appendChild(renderChapter(ch)); });
refreshCompletion();
refreshActiveHighlight();
updateProgress();
}
// 高亮当前页并滚动到可视区(不重新渲染, 避免与 ensureActiveExpanded 递归)
function refreshActiveHighlight() {
document.querySelectorAll('.yx-page').forEach(function (p) { p.classList.remove('active'); });
if (activeEntry && activeEntry.dom) {
activeEntry.dom.classList.add('active');
try { activeEntry.dom.scrollIntoView({ block: 'nearest' }); } catch (e) { }
}
}
function renderChapter(ch) {
const wrap = el('div', 'yx-ch');
const head = el('div', 'yx-ch-head');
const ar = el('span'); ar.className = 'yx-ar'; ar.textContent = ch.expanded ? '▾' : '▸';
const ico = el('span'); ico.className = 'yx-ico'; ico.textContent = '◈';
const txt = el('span'); txt.className = 'yx-txt'; txt.textContent = ch.name || '未命名专题';
const badge = el('span'); badge.className = 'yx-badge';
badge.textContent = ch.done + '/' + ch.total;
head.appendChild(ar); head.appendChild(ico); head.appendChild(txt); head.appendChild(badge);
ch.domBadge = badge;
head.onclick = function () { ch.expanded = !ch.expanded; renderSidebar(); };
wrap.appendChild(head);
if (ch.expanded) {
ch.children.forEach(function (sec) { wrap.appendChild(renderSection(sec)); });
}
return wrap;
}
function renderSection(sec) {
const wrap = el('div', 'yx-sec');
const head = el('div', 'yx-sec-head');
const ar = el('span'); ar.className = 'yx-ar'; ar.textContent = sec.expanded ? '▾' : '▸';
const txt = el('span'); txt.className = 'yx-txt'; txt.textContent = sec.name || '未命名小节';
head.appendChild(ar); head.appendChild(txt);
head.onclick = function () { sec.expanded = !sec.expanded; renderSidebar(); };
wrap.appendChild(head);
if (sec.expanded) {
sec.children.forEach(function (pg) { wrap.appendChild(renderPage(pg)); });
}
return wrap;
}
function renderPage(pg) {
const row = el('div', 'yx-page' + (pg.isActive ? ' active' : '') + (pg.isLocked ? ' locked' : ''));
pg.dom = row;
const ico = el('span'); ico.className = 'yx-pico'; ico.textContent = pg.icon;
ico.style.background = pg.isLocked ? '#f1f5f9' : (pg.isComplete ? '#dcfce7' : (pg.icon === '▶' ? '#dbeafe' : '#f3e8ff'));
ico.style.color = pg.isLocked ? '#94a3b8' : (pg.isComplete ? '#16a34a' : (pg.icon === '▶' ? '#2563eb' : '#9333ea'));
const txt = el('span'); txt.className = 'yx-txt'; txt.textContent = pg.name;
row.appendChild(ico); row.appendChild(txt);
if (pg.isLocked) {
const lockTag = el('span'); lockTag.className = 'yx-lock-tag'; lockTag.textContent = '🔒 已上锁';
row.appendChild(lockTag);
row.title = '该章节已上锁,无法学习';
row.onclick = function () { log('「' + pg.name + '」已上锁,无法进入', '#94a3b8'); };
} else {
row.onclick = function () { selectPage(pg); };
}
return row;
}
/* ========== 页面切换与高亮 ========== */
function selectPage(pg) {
if (!pg || pg.kind !== 'page') return;
if (isPageLocked(pg)) { log('「' + pg.name + '」已上锁,无法进入', '#94a3b8'); return; }
// 页面节点未渲染(懒渲染)时, 先驱动渲染再重试点击
if (!pg.element || !document.contains(pg.element)) {
const acted = ensurePageDom(pg) || refreshPageElement(pg);
if (acted) {
setTimeout(function () {
if (refreshPageElement(pg) && document.contains(pg.element)) selectPage(pg);
else log('页面节点仍未渲染,无法跳转:' + pg.name, '#f87171');
}, 350);
return;
}
log('页面节点未渲染,无法跳转:' + pg.name, '#f87171');
return;
}
try { pg.element.click(); } // 触发原页面的 Knockout selectPage(原页面在后台隐藏, 照常生效)
catch (e) { log('切换页面失败:' + e.message, '#f87171'); return; }
activeEntry = pg;
runState._allDoneLogged = false;
log('切换到:' + pg.name, '#60a5fa');
setTimeout(syncActive, 100);
setTimeout(syncActive, 800);
}
function syncActive() {
const act = document.querySelector('.page-name.active');
let found = null;
(function walk(arr) {
for (let i = 0; i < arr.length; i++) {
const n = arr[i];
if (n.kind === 'page') {
if (act && n.element === act) found = n;
} else if (n.children) walk(n.children);
}
})(tree);
if (found) activeEntry = found;
// 跟随执行位置: 当前页换了专题/小节就自动展开目录并定位
if (ensureActiveExpanded()) {
renderSidebar(); // 内部已含高亮+统计刷新
} else {
refreshActiveHighlight();
updateProgress();
}
}
function updateProgress() {
const elDone = document.getElementById('statDone');
const elTotal = document.getElementById('statTotal');
const elPct = document.getElementById('statPct');
const elPctBar = document.getElementById('statPctBar');
const elRemain = document.getElementById('statRemain');
const elCurName = document.getElementById('curPageName');
const elCurTag = document.getElementById('curPageTag');
const elVideo = document.getElementById('videoTimeText');
const elVideoBar = document.getElementById('videoBar');
const elInfo = document.getElementById('chapterInfo');
if (!elDone || !elTotal) return;
refreshCompletion();
const pages = getFlatPages();
const total = pages.length || 1;
let done = 0, locked = 0;
pages.forEach(function (p) {
if (isPageLocked(p)) locked++;
else if (isPageDone(p)) done++;
});
const ach = Math.max(0, total - locked); // 可完成页数 = 总数 - 上锁数
const pct = ach > 0 ? Math.round(done / ach * 100) : 100;
elDone.textContent = done;
const elLocked = document.getElementById('statLocked');
if (elLocked) elLocked.textContent = locked;
elTotal.textContent = total;
elPct.textContent = pct + '%';
if (elPctBar) elPctBar.style.width = pct + '%';
if (elRemain) elRemain.textContent = Math.max(0, ach - done);
if (elInfo) elInfo.textContent = '第 ' + ((activeEntry ? activeEntry.index : 0) + 1) + ' / ' + total + ' 页';
// 当前页卡
if (elCurName) elCurName.textContent = activeEntry ? activeEntry.name : '—';
if (elCurTag) {
const curDone = activeEntry ? isPageDone(activeEntry) : false;
elCurTag.textContent = curDone ? '已完成' : (activeEntry ? '未完成' : '未定位');
elCurTag.style.background = curDone ? '#dcfce7' : '#fef3c7';
elCurTag.style.color = curDone ? '#16a34a' : '#b45309';
}
// 视频进度(秒数): 未开始任务时提示"开启任务后自动获取", 开启后才读取
if (!isRunning) {
if (elVideo) {
elVideo.textContent = '开启任务后自动获取';
elVideo.style.fontSize = '12px';
elVideo.style.color = '#94a3b8';
}
if (elVideoBar) elVideoBar.style.width = '0%';
} else {
if (elVideo) { elVideo.style.fontSize = '22px'; elVideo.style.color = '#0f172a'; }
const video = document.querySelector('.file-media video');
if ($videoQuizModal().length) {
// 视频播放途中弹出的练习题:视频是暂停的,这里显示答题状态更直观
if (elVideo) { elVideo.textContent = '视频答题中'; elVideo.style.fontSize = '15px'; elVideo.style.color = '#9333ea'; }
if (elVideoBar) { elVideoBar.style.width = '100%'; elVideoBar.style.background = '#a855f7'; }
} else if (video && isFinite(video.duration) && video.duration > 0) {
const s = Math.floor(video.currentTime);
const d = Math.floor(video.duration);
const vpct = Math.min(100, video.currentTime / video.duration * 100);
if (elVideo) elVideo.textContent = s + 's / ' + d + 's';
if (elVideoBar) { elVideoBar.style.width = vpct + '%'; elVideoBar.style.background = vpct >= 99.5 ? '#34d399' : '#2dd4bf'; }
} else if (elVideo) {
if ($pageQuizPanel().length) {
elVideo.textContent = '章节测试页';
elVideo.style.fontSize = '15px';
elVideo.style.color = '#9333ea';
if (elVideoBar) elVideoBar.style.width = '100%';
} else {
elVideo.textContent = '—';
if (elVideoBar) elVideoBar.style.width = '0%';
}
}
}
}
/* ========== 设置卡片(带描述的元素框) ========== */
// 输入型卡片: 标题 + 输入控件 + 描述
function makeInputCard(title, desc, buildInput) {
const card = el('div');
card.className = 'yx-card';
const head = el('div');
head.className = 'yx-card-head';
const t = el('span');
t.className = 'yx-card-title';
t.textContent = title;
const inp = buildInput();
head.appendChild(t); head.appendChild(inp);
const d = el('div');
d.className = 'yx-card-desc';
d.textContent = desc;
card.appendChild(head); card.appendChild(d);
return card;
}
// 开关型卡片: 勾选框 + 标题 + 描述
function makeToggleCard(title, desc, checked, onchange) {
const card = el('div');
card.className = 'yx-card';
const head = el('div');
head.className = 'yx-card-head';
const cb = el('input');
cb.type = 'checkbox';
cb.checked = !!checked;
cb.onchange = function () { onchange(cb.checked); };
const t = el('span');
t.className = 'yx-card-title';
t.textContent = title;
head.appendChild(cb); head.appendChild(t);
const d = el('div');
d.className = 'yx-card-desc';
d.textContent = desc;
card.appendChild(head); card.appendChild(d);
return card;
}
/* =====================================================================
构建全屏数据面板: 完全隐藏原页面, 只显示 目录 + 学习数据
- 左侧: 章节目录树(含每专题完成徽章)
- 右侧: 顶栏控制 + 统计卡片 + 总进度条 + 当前任务 + 运行日志
===================================================================== */
function buildFullUI() {
if (document.getElementById('helperFullPage')) return;
// 先立即全屏显示面板(盖住原页面), 再在后台逐章节载入全部页面, 用户看不到原页面切换
buildFullUIImpl();
// 载入期间禁用「开始任务」按钮
const sb = document.getElementById('startBtn');
if (sb) {
sb.dataset.origText = sb.textContent;
sb.textContent = '⏳ 请等待载入结束';
sb.disabled = true;
sb.style.background = '#94a3b8';
sb.style.cursor = 'not-allowed';
sb.style.pointerEvents = 'none';
}
log('载入所有章节页进度情况,请勿触碰', '#60a5fa');
log('当前脚本版本 v' + scriptVersion() + '(面板左上角同步显示)', '#94a3b8');
flushNotices();
expandOriginalCatalog(function () {
renderAllChapters(function () {
// 全量重新提取并刷新目录/统计
tree = extractTree();
renderSidebar();
updateProgress();
log('已完成,请点击开启任务', '#34d399');
// 恢复「开始任务」按钮
const b2 = document.getElementById('startBtn');
if (b2) {
b2.textContent = b2.dataset.origText || '▶ 开始任务';
b2.disabled = false;
b2.style.background = '#2563eb';
b2.style.cursor = 'pointer';
b2.style.pointerEvents = '';
}
// 定位到第一个未完成页(用户可见执行位置)
setTimeout(function () {
if (activeEntry) jumpFirstIncomplete('已获取全部章节');
}, 300);
});
});
}
function buildFullUIImpl() {
if (document.getElementById('helperFullPage')) return;
tree = extractTree();
if (!tree.length) { console.log('课程助手:未检测到章节目录,稍后重试'); return; }
if (activeEntry) {
markExpanded(tree, activeEntry);
tree.forEach(function (ch) {
if (ch.expanded) ch.children.forEach(function (sec) { sec.expanded = true; });
});
}
// 全屏浮层(不透明, 完全盖住原页面; 原 DOM 保留在后台供自动化使用)
const page = el('div');
page.id = 'helperFullPage';
page.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;z-index:2147482000;' +
'background:#eef2f7;display:flex;color:#0f172a;' +
'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;';
// 统一样式: 目录树 + 设置卡片
const style = el('style');
style.textContent = [
'#chapterList{scrollbar-width:thin;scrollbar-color:#cbd5e1 transparent;}',
'#chapterList::-webkit-scrollbar{width:6px;}',
'#chapterList::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:3px;}',
/* 专题行 */
'.yx-ch-head{display:flex;align-items:center;gap:7px;padding:11px 14px;cursor:pointer;font-size:13px;font-weight:600;color:#1e293b;background:#f8fafc;border-bottom:1px solid #eef2f7;border-left:3px solid transparent;transition:background .15s;user-select:none;}',
'.yx-ch-head:hover{background:#eef6ff;border-left-color:#6366f1;}',
'.yx-ch-head .yx-ar{font-size:10px;color:#94a3b8;width:12px;text-align:center;flex:none;}',
'.yx-ch-head .yx-ico{color:#6366f1;font-size:12px;flex:none;}',
'.yx-ch-head .yx-txt{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
'.yx-badge{font-size:10px;font-weight:700;color:#64748b;background:#f1f5f9;border-radius:999px;padding:1px 8px;flex:none;font-variant-numeric:tabular-nums;}',
/* 小节行 */
'.yx-sec-head{display:flex;align-items:center;gap:6px;padding:8px 14px 8px 30px;cursor:pointer;font-size:12.5px;color:#475569;border-left:3px solid transparent;transition:background .15s;user-select:none;}',
'.yx-sec-head:hover{background:#f1f5f9;color:#1e293b;}',
'.yx-sec-head .yx-ar{font-size:10px;color:#cbd5e1;width:12px;text-align:center;flex:none;}',
'.yx-sec-head .yx-txt{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
/* 页面行 */
'.yx-page{display:flex;align-items:center;gap:8px;padding:7px 14px 7px 48px;cursor:pointer;font-size:12.5px;color:#475569;border-left:3px solid transparent;border-radius:0 8px 8px 0;margin:1px 8px 1px 0;transition:background .12s;user-select:none;}',
'.yx-page:hover{background:#f1f5f9;color:#0f172a;}',
'.yx-page.active{background:#eef6ff;border-left-color:#2563eb;color:#1d4ed8;font-weight:600;}',
'.yx-page .yx-txt{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}',
'.yx-pico{width:18px;height:18px;flex:none;display:inline-flex;align-items:center;justify-content:center;border-radius:5px;font-size:10px;font-weight:700;}',
/* 上锁页 */
'.yx-page.locked{opacity:.55;cursor:not-allowed;background:#f8fafc;color:#94a3b8;}',
'.yx-page.locked:hover{background:#f1f5f9;color:#94a3b8;}',
'.yx-lock-tag{margin-left:auto;flex:none;font-size:10px;color:#94a3b8;background:#f1f5f9;border:1px solid #e2e8f0;padding:1px 7px;border-radius:999px;white-space:nowrap;}',
/* 设置卡片 */
'.yx-card{display:flex;flex-direction:column;gap:5px;background:#f8fafc;border:1px solid #e2e8f0;border-radius:10px;padding:9px 12px;min-width:148px;box-shadow:0 1px 3px rgba(15,23,42,.05);}',
'.yx-card-head{display:flex;align-items:center;gap:8px;}',
'.yx-card-title{font-size:12px;font-weight:600;color:#1e293b;white-space:nowrap;}',
'.yx-card-desc{font-size:11px;color:#64748b;line-height:1.5;}',
'.yx-card input[type="number"]{width:60px;padding:3px 6px;border:1px solid #cbd5e1;border-radius:6px;text-align:center;font-size:13px;background:#fff;margin-left:auto;}',
'.yx-card input[type="checkbox"]{width:15px;height:15px;accent-color:#2563eb;cursor:pointer;}',
].join('\n');
page.appendChild(style);
/* ============ 左侧: 章节目录 ============ */
const sidebar = el('div');
sidebar.style.cssText = 'width:310px;min-width:310px;background:#fff;border-right:1px solid #e2e8f0;display:flex;flex-direction:column;overflow:hidden;box-shadow:2px 0 12px rgba(15,23,42,.06);';
const brand = el('div');
brand.style.cssText = 'background:linear-gradient(135deg,#1d4ed8,#3b82f6);color:#fff;padding:16px 16px 14px;';
const bTitle = el('div');
bTitle.style.cssText = 'font-size:16px;font-weight:700;letter-spacing:.5px;';
bTitle.textContent = '优学院最牛逼脚本视频挂机 + 章节测试自动答题(优学院刷课)';
const bSub = el('div');
bSub.style.cssText = 'font-size:11px;opacity:.8;margin-top:3px;';
bSub.textContent = '优学院学习页 · 全屏数据面板 · v' + scriptVersion();
brand.appendChild(bTitle); brand.appendChild(bSub);
sidebar.appendChild(brand);
const sHead = el('div');
sHead.style.cssText = 'padding:10px 14px;border-bottom:1px solid #f1f5f9;display:flex;align-items:center;justify-content:space-between;background:#f8fafc;';
const sTitle = el('span');
sTitle.style.cssText = 'font-size:13px;font-weight:600;color:#334155;';
sTitle.textContent = '章节目录';
const refreshBtn = el('button');
refreshBtn.textContent = '⟳ 刷新';
refreshBtn.style.cssText = 'padding:4px 10px;border:none;border-radius:6px;background:#e2e8f0;color:#334155;cursor:pointer;font-size:12px;';
refreshBtn.onclick = function () {
// 先展开原目录确保懒渲染的页面节点存在, 再重新提取全量
expandOriginalCatalog();
setTimeout(function () {
tree = extractTree();
if (activeEntry) {
markExpanded(tree, activeEntry);
tree.forEach(function (ch) {
if (ch.expanded) ch.children.forEach(function (sec) { sec.expanded = true; });
});
}
renderSidebar();
log('目录已刷新,共 ' + getFlatPages().length + ' 个页面', '#60a5fa');
}, 120);
};
sHead.appendChild(sTitle); sHead.appendChild(refreshBtn);
sidebar.appendChild(sHead);
const chapterList = el('div');
chapterList.id = 'chapterList';
chapterList.style.cssText = 'flex:1;overflow-y:auto;padding:8px 0;';
sidebar.appendChild(chapterList);
/* ============ 右侧主区 ============ */
const main = el('div');
main.style.cssText = 'flex:1;display:flex;flex-direction:column;min-width:0;overflow:hidden;';
// ---- 顶栏 ----
const bar = el('div');
bar.style.cssText = 'background:#fff;border-bottom:1px solid #e2e8f0;padding:10px 18px;display:flex;flex-wrap:wrap;gap:8px;align-items:center;';
const statusPill = el('span');
statusPill.id = 'yxStatus';
statusPill.style.cssText = 'font-size:12px;font-weight:600;color:#fff;background:#64748b;padding:4px 10px;border-radius:999px;';
statusPill.textContent = '就绪';
const startBtn = el('button');
startBtn.id = 'startBtn';
startBtn.textContent = '▶ 开始任务';
startBtn.style.cssText = 'padding:8px 18px;border:none;border-radius:8px;background:#2563eb;color:#fff;cursor:pointer;font-size:13px;font-weight:600;box-shadow:0 2px 6px rgba(37,99,235,.35);';
// 开始任务旁的说明(首个未完成按钮已隐藏, 功能并入开始任务)
const startHint = el('span');
startHint.style.cssText = 'font-size:11px;color:#64748b;max-width:150px;line-height:1.4;';
startHint.textContent = '开启任务后自动定位第一个未完成页';
const nextBtn = null; // 下一项按钮已按用户要求隐藏
const exitBtn = el('button');
exitBtn.textContent = '返回原页面';
exitBtn.style.cssText = 'padding:8px 14px;border:1px solid #cbd5e1;border-radius:8px;background:#fff;color:#334155;cursor:pointer;font-size:13px;';
exitBtn.onclick = exitFullscreen;
// 设置卡片: 视频倍速 / 最低正确率 / 视频任务 / 章节测试(带描述)
const rateCard = makeInputCard('视频倍速', '倍速不设上限(浏览器实际最高约 16x);大于1倍会被清空进度,大于2倍可能无法完成任务', function () {
const r = el('input');
r.id = 'videoRateInput';
r.type = 'number';
r.step = '0.25'; r.min = '0.5'; // 上限已取消
r.value = config.videoRate;
r.onchange = function () {
let v = parseFloat(r.value);
if (isNaN(v) || v < 0.5) v = 1;
r.value = v;
config.videoRate = v;
saveConfig('videoRate', v);
const vd = document.querySelector('.file-media video');
if (vd) setPlaybackRate(vd, v);
log('视频倍速设置为 ' + v + 'x' + (v > 16 ? '(浏览器会把 playbackRate 截到约 16x,再高无效)' : ''), '#60a5fa');
if (v > 1) log('提醒:倍速 >1 倍可能被平台清空学习进度', '#fbbf24');
};
return r;
});
const accCard = makeInputCard('最低正确率', '当脚本作答后的正确率低于这个数值时不会自动提交', function () {
const a = el('input');
a.id = 'minAccuracyInput';
a.type = 'number';
a.min = '0'; a.max = '100';
a.value = config.minAccuracy;
a.onchange = function () {
let v = parseFloat(a.value);
if (isNaN(v)) v = 100;
v = Math.max(0, Math.min(100, Math.round(v)));
a.value = v;
config.minAccuracy = v;
saveConfig('minAccuracy', v);
log('最低正确率设置为 ' + v + '%', '#60a5fa');
};
return a;
});
const videoCard = makeToggleCard('视频任务', '自动播放/静音/倍速,播完自动翻页', config.videoTask, function (v) {
config.videoTask = v; saveConfig('videoTask', v);
log('视频任务已' + (v ? '开启' : '关闭'), v ? '#34d399' : '#fbbf24');
});
// 视频播放途中弹出的练习题(video-question-modal):不答会一直卡住视频
const videoQuizCard = makeToggleCard('视频内嵌答题', '视频播放中弹出的练习题:自动作答并逐题提交,答完不翻页,等视频自己继续播放',
config.videoQuiz, function (v) {
config.videoQuiz = v; saveConfig('videoQuiz', v);
log('视频内嵌答题已' + (v ? '开启(自动作答)' : '关闭(只提交空白放行视频)'), v ? '#34d399' : '#fbbf24');
});
const examCard = makeToggleCard('章节测试', '选择/判断题:已批改读页面显示,未批改一律走 questionAnswer 接口', config.examTask, function (v) {
config.examTask = v; saveConfig('examTask', v);
log('章节测试已' + (v ? '开启' : '关闭'), v ? '#34d399' : '#fbbf24');
});
// 章节讨论(简答/讨论类文本作答):默认只填写不提交,提交要另外打开
const discussFillCard = makeToggleCard('章节讨论自动填写(不提交)', '把接口 correctreply 里的官方参考答案填进讨论/简答输入框;日志里打出填了什么,脚本不点提交、直接翻页',
config.discussFill, function (v) {
config.discussFill = v; saveConfig('discussFill', v);
log('章节讨论自动填写已' + (v ? '开启' : '关闭'), v ? '#34d399' : '#fbbf24');
});
const discussSubmitCard = makeToggleCard('章节讨论自动提交', '填写后自动点提交并翻页(需同时开启"章节讨论自动填写")',
config.discussSubmit, function (v) {
config.discussSubmit = v; saveConfig('discussSubmit', v);
log('章节讨论自动提交已' + (v ? '开启' : '关闭'), v ? '#34d399' : '#fbbf24');
});
bar.append(statusPill, startBtn, startHint, exitBtn, rateCard, accCard, videoCard, videoQuizCard, examCard, discussFillCard, discussSubmitCard);
main.appendChild(bar);
// ---- 统计卡片 ----
const cards = el('div');
cards.style.cssText = 'display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:12px;padding:16px 18px 8px;';
function statCard(title, color) {
const c = el('div');
c.style.cssText = 'background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:14px 16px;box-shadow:0 1px 4px rgba(15,23,42,.05);';
const t = el('div');
t.style.cssText = 'font-size:12px;color:#64748b;margin-bottom:8px;';
t.textContent = title;
c.appendChild(t);
return c;
}
// 卡1: 总进度(已完成 / 上锁 / 总数)
const c1 = statCard('总进度(已完成 / 上锁 / 总数)');
const c1Body = el('div');
c1Body.style.cssText = 'display:flex;align-items:baseline;gap:8px;';
const doneBig = el('span'); doneBig.id = 'statDone';
doneBig.style.cssText = 'font-size:28px;font-weight:800;color:#2563eb;font-variant-numeric:tabular-nums;';
const sl1 = el('span'); sl1.style.cssText = 'font-size:16px;color:#94a3b8;'; sl1.textContent = '/';
const lockedBig = el('span'); lockedBig.id = 'statLocked';
lockedBig.style.cssText = 'font-size:18px;font-weight:600;color:#f59e0b;font-variant-numeric:tabular-nums;';
const sl2 = el('span'); sl2.style.cssText = 'font-size:16px;color:#94a3b8;'; sl2.textContent = '/';
const totalBig = el('span'); totalBig.id = 'statTotal';
totalBig.style.cssText = 'font-size:18px;font-weight:600;color:#64748b;font-variant-numeric:tabular-nums;';
const pctBig = el('span'); pctBig.id = 'statPct';
pctBig.style.cssText = 'margin-left:auto;font-size:16px;font-weight:700;color:#0d9488;';
c1Body.append(doneBig, sl1, lockedBig, sl2, totalBig, pctBig);
const c1Bar = el('div');
c1Bar.style.cssText = 'margin-top:10px;height:8px;background:#e2e8f0;border-radius:4px;overflow:hidden;';
const c1BarIn = el('div'); c1BarIn.id = 'statPctBar';
c1BarIn.style.cssText = 'height:100%;width:0%;background:linear-gradient(90deg,#2563eb,#2dd4bf);transition:width .4s;';
c1Bar.appendChild(c1BarIn);
c1.appendChild(c1Body); c1.appendChild(c1Bar);
cards.appendChild(c1);
// 卡2: 视频进度
const c2 = statCard('当前视频进度');
const c2Body = el('div');
c2Body.style.cssText = 'display:flex;align-items:baseline;gap:6px;';
const vtime = el('span'); vtime.id = 'videoTimeText';
vtime.style.cssText = 'font-size:22px;font-weight:700;color:#0f172a;font-variant-numeric:tabular-nums;';
vtime.textContent = '—';
c2Body.appendChild(vtime);
const c2Bar = el('div');
c2Bar.style.cssText = 'margin-top:10px;height:8px;background:#e2e8f0;border-radius:4px;overflow:hidden;';
const c2BarIn = el('div'); c2BarIn.id = 'videoBar';
c2BarIn.style.cssText = 'height:100%;width:0%;background:#2dd4bf;transition:width .3s;';
c2Bar.appendChild(c2BarIn);
c2.appendChild(c2Body); c2.appendChild(c2Bar);
cards.appendChild(c2);
// 卡3: 当前页
const c3 = statCard('当前页面');
const curName = el('div'); curName.id = 'curPageName';
curName.style.cssText = 'font-size:15px;font-weight:600;color:#0f172a;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;';
curName.textContent = '—';
const curTag = el('span'); curTag.id = 'curPageTag';
curTag.style.cssText = 'display:inline-block;margin-top:8px;font-size:11px;font-weight:600;padding:2px 8px;border-radius:999px;background:#f1f5f9;color:#64748b;';
curTag.textContent = '未定位';
c3.appendChild(curName); c3.appendChild(curTag);
cards.appendChild(c3);
// 卡4: 待完成
const c4 = statCard('待完成页数');
const c4Body = el('div');
c4Body.style.cssText = 'display:flex;align-items:baseline;gap:8px;';
const remainBig = el('span'); remainBig.id = 'statRemain';
remainBig.style.cssText = 'font-size:28px;font-weight:800;color:#f59e0b;font-variant-numeric:tabular-nums;';
remainBig.textContent = '0';
const remainTxt = el('span'); remainTxt.style.cssText = 'font-size:12px;color:#64748b;';
remainTxt.textContent = '个页面待完成';
c4Body.append(remainBig, remainTxt);
c4.appendChild(c4Body);
cards.appendChild(c4);
// 卡5: 作者
const c5 = statCard('作者');
const c5Row = el('div');
c5Row.style.cssText = 'display:flex;align-items:baseline;gap:8px;';
const authorBig = el('span');
authorBig.style.cssText = 'font-size:16px;font-weight:700;color:#0f172a;';
authorBig.textContent = '十点前睡觉';
const authorSub = el('span'); authorSub.style.cssText = 'font-size:11px;color:#94a3b8;';
authorSub.textContent = '本脚本原作者';
c5Row.append(authorBig, authorSub);
const c5Body = el('div');
const contactBtn = el('a');
contactBtn.href = 'https://zy520.de5.net/juanzeng';
contactBtn.target = '_blank';
contactBtn.rel = 'noopener noreferrer';
contactBtn.textContent = '✉ 联系作者';
contactBtn.style.cssText = 'display:inline-block;margin-top:8px;padding:5px 14px;border-radius:999px;background:#2563eb;color:#fff;font-size:12px;font-weight:600;text-decoration:none;cursor:pointer;box-shadow:0 1px 5px rgba(37,99,235,.35);';
c5Body.appendChild(contactBtn);
c5.appendChild(c5Row);
c5.appendChild(c5Body);
cards.appendChild(c5);
// 卡6: 捐赠与反馈
const c6 = statCard('捐赠与反馈');
const c6Body = el('div');
c6Body.style.cssText = 'display:flex;align-items:center;';
const donateBtn = el('a');
donateBtn.href = 'https://zy520.de5.net/juanzeng';
donateBtn.target = '_blank';
donateBtn.rel = 'noopener noreferrer';
donateBtn.textContent = '☕ 捐赠 / 反馈';
donateBtn.style.cssText = 'display:inline-block;padding:6px 18px;border-radius:999px;background:#f97316;color:#fff;font-size:13px;font-weight:600;text-decoration:none;cursor:pointer;box-shadow:0 1px 5px rgba(249,115,22,.4);';
c6Body.appendChild(donateBtn);
c6.appendChild(c6Body);
cards.appendChild(c6);
// 卡7: 使用提示(纯描述)
const c7 = statCard('使用提示');
const tipText = el('div');
tipText.style.cssText = 'font-size:12px;line-height:1.7;color:#475569;';
tipText.textContent = '优学院不时更新,如果有部分功能失效请反馈,觉得好用可以推荐给同学一起使用!';
c7.appendChild(tipText);
cards.appendChild(c7);
// 卡8: 课程(网页标题)
const c8 = statCard('课程');
const c8Body = el('div');
const courseName = el('div'); courseName.id = 'statCourse';
courseName.style.cssText = 'font-size:13px;font-weight:600;color:#0f172a;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%;';
courseName.textContent = document.title || '—';
const courseSub = el('div'); courseSub.style.cssText = 'margin-top:6px;font-size:11px;color:#94a3b8;';
courseSub.textContent = '当前课程';
c8Body.append(courseName, courseSub);
c8.appendChild(c8Body);
cards.appendChild(c8);
// 卡9: 课程切换(跳转课程列表)
const c9 = statCard('课程切换');
const c9Body = el('div');
c9Body.style.cssText = 'display:flex;align-items:center;';
const switchBtn = el('button');
switchBtn.textContent = '切换课程';
switchBtn.style.cssText = 'padding:6px 16px;border:none;border-radius:999px;background:#2563eb;color:#fff;font-size:12px;font-weight:600;cursor:pointer;box-shadow:0 1px 4px rgba(37,99,235,.3);';
switchBtn.onclick = function () { location.href = 'https://courseweb.ulearning.cn/ulearning/index.html#/index/courseList'; };
c9Body.appendChild(switchBtn);
c9.appendChild(c9Body);
cards.appendChild(c9);
// 卡10: 版本号
const c10 = statCard('版本号');
const c10Body = el('div');
c10Body.style.cssText = 'display:flex;align-items:baseline;gap:8px;';
const verBig = el('span'); verBig.id = 'statVersion';
verBig.style.cssText = 'font-size:20px;font-weight:800;color:#334155;font-variant-numeric:tabular-nums;';
verBig.textContent = scriptVersion();
const verSub = el('span'); verSub.style.cssText = 'font-size:11px;color:#94a3b8;';
verSub.textContent = '脚本版本';
c10Body.append(verBig, verSub);
c10.appendChild(c10Body);
cards.appendChild(c10);
main.appendChild(cards);
// ---- 当前任务条 ----
const taskBar = el('div');
taskBar.style.cssText = 'background:#fff;border:1px solid #e2e8f0;border-radius:12px;margin:8px 18px;padding:10px 16px;display:flex;flex-wrap:wrap;align-items:center;gap:12px;box-shadow:0 1px 4px rgba(15,23,42,.05);';
const taskInfo = el('span'); taskInfo.id = 'chapterInfo';
taskInfo.style.cssText = 'font-size:12px;color:#64748b;font-variant-numeric:tabular-nums;';
taskInfo.textContent = '第 - / - 页';
const taskName = el('span'); taskName.id = 'chapterName';
taskName.style.cssText = 'font-size:13px;font-weight:600;color:#0f172a;flex:1;min-width:120px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;';
taskName.textContent = '—';
const taskTip = el('span'); taskTip.id = 'taskTip';
taskTip.style.cssText = 'font-size:11px;color:#64748b;';
taskTip.textContent = '后台自动播放 · 每 60s 报一次进度';
taskBar.append(taskInfo, taskName, taskTip);
main.appendChild(taskBar);
// ---- 运行日志 ----
const logWrap = el('div');
logWrap.id = 'logWrap';
logWrap.style.cssText = 'flex:1;min-height:0;display:flex;flex-direction:column;margin:0 18px 16px;background:#0f172a;border-radius:12px;overflow:hidden;';
const logHead = el('div');
logHead.style.cssText = 'background:#1e293b;color:#94a3b8;padding:8px 14px;font-size:12px;display:flex;align-items:center;justify-content:space-between;cursor:pointer;user-select:none;';
const logTitle = el('span'); logTitle.textContent = '运行日志(点击折叠)';
const logTools = el('span'); logTools.style.cssText = 'display:flex;gap:8px;align-items:center;';
const clearBtn = el('button');
clearBtn.textContent = '清空';
clearBtn.style.cssText = 'padding:2px 8px;border:none;border-radius:4px;background:#334155;color:#cbd5e1;cursor:pointer;font-size:11px;';
clearBtn.onclick = function (e) { e.stopPropagation(); const box = document.getElementById('logBox'); if (box) box.innerHTML = ''; };
const collapseBtn = el('span'); collapseBtn.id = 'logCollapse'; collapseBtn.textContent = '—';
logTools.append(clearBtn, collapseBtn);
logHead.append(logTitle, logTools);
const logBox = el('div');
logBox.id = 'logBox';
logBox.style.cssText = 'flex:1;overflow-y:auto;padding:10px 14px;font-family:Consolas,Monaco,"Courier New",monospace;font-size:12px;line-height:1.8;';
let logCollapsed = false;
logHead.onclick = function () {
logCollapsed = !logCollapsed;
logBox.style.display = logCollapsed ? 'none' : 'block';
collapseBtn.textContent = logCollapsed ? '▢' : '—';
logTitle.textContent = logCollapsed ? '运行日志(点击展开)' : '运行日志(点击折叠)';
};
logWrap.appendChild(logHead); logWrap.appendChild(logBox);
main.appendChild(logWrap);
page.appendChild(sidebar);
page.appendChild(main);
document.body.appendChild(page);
document.body.style.overflow = 'hidden';
document.documentElement.style.overflow = 'hidden';
// 事件
startBtn.onclick = toggleRun;
renderSidebar();
updateProgress();
log('全屏数据面板已开启,共 ' + getFlatPages().length + ' 个页面', '#60a5fa');
log('开启任务后自动定位第一个未完成页;每 60s 报一次视频进度', '#94a3b8');
// 常驻同步(高亮/统计/视频秒数)
setInterval(syncActive, 1200);
}
/* ========== 任务控制 ========== */
function toggleRun() { if (isRunning) stopRun(); else startRun(); }
function startRun() {
if (isRunning) return;
isRunning = true;
runState.quizHold = {}; // 重新开始即重置各页的"已放弃重试"标记
const btn = document.getElementById('startBtn');
if (btn) { btn.textContent = '⏸ 暂停任务'; btn.style.background = '#dc2626'; }
setStatus('运行中', '#16a34a');
log('任务开始执行', '#34d399');
startProgressLog();
// 若当前页已完成(或未知), 先顺序定位到第一个未完成页再开始轮询
const cur = activeEntry;
if (!cur || isPageDone(cur) || isPageLocked(cur)) {
const p = firstIncompletePage();
if (!p) {
const lockedCount = getFlatPages().filter(function (x) { return isPageLocked(x); }).length;
if (lockedCount > 0) log('剩余页面均已上锁,无法继续学习', '#f59e0b');
else log('所有页面均已完成,无需继续', '#34d399');
} else if (!(activeEntry && activeEntry === p)) {
selectPage(p);
log('开始任务:已定位到第一个未完成页「' + p.name + '」', '#2dd4bf');
}
setTimeout(function () {
if (isRunning) {
logic();
runTimer = setInterval(logic, 1500);
}
}, 1000);
} else {
logic();
runTimer = setInterval(logic, 1500);
}
}
function stopRun() {
isRunning = false;
clearInterval(runTimer); runTimer = null;
stopProgressLog();
const btn = document.getElementById('startBtn');
if (btn) { btn.textContent = '▶ 开始任务'; btn.style.background = '#2563eb'; }
setStatus('已暂停', '#ef4444');
log('任务已暂停', '#fbbf24');
pauseAllVideos();
}
// 每 60 秒在日志里报一次视频进度(秒数)
let progressLogTimer = null;
function startProgressLog() {
stopProgressLog();
progressLogTimer = setInterval(function () {
if (!isRunning) return;
const video = document.querySelector('.file-media video');
if ($videoQuizModal().length) {
log('当前为视频内嵌答题弹窗,正在自动作答…', '#c084fc');
} else if (video && isFinite(video.duration) && video.duration > 0) {
const pgName = (activeEntry && activeEntry.name) ? shortName(activeEntry.name) : '当前页';
log('「' + pgName + '」视频进度:' + Math.floor(video.currentTime) + 's / ' + Math.floor(video.duration) + 's(' + (video.currentTime / video.duration * 100).toFixed(1) + '%)', '#60a5fa');
} else if ($pageQuizPanel().length) {
log('当前为章节测试页,等待作答…', '#94a3b8');
}
}, 60000);
}
function stopProgressLog() {
if (progressLogTimer) { clearInterval(progressLogTimer); progressLogTimer = null; }
}
function pauseAllVideos() {
try {
let n = 0;
$(".mejs__button.mejs__playpause-button button").each(function (i, b) {
if ($(b).attr("title") === "暂停") {
$(b).click();
n++;
}
});
muteAllVideos();
if (n) log('已暂停 ' + n + ' 个视频', '#60a5fa');
} catch (e) { }
}
/* ========== 视频完成判定(yxy1 v3 核心, 以真实