// ==UserScript==
// @name 实验室安全一键速刷(盐城工学院)
// @namespace https://github.com/spottedcat2/lab-safety-t300
// @version 3.4.1.1
// @description 实验室安全学习辅助:课程视频连续播放、一键批量完成所有视频弹窗题目、错题一键自动纠正;考试支持批量作答及交卷。
// @author 吃吃饭
// @license proprietary
// @homepageURL https://scriptcat.org/zh-CN/script-show-page/8896
// @supportURL https://wpa.qq.com/msgrd?v=3&uin=746957502&site=qq&menu=yes
// @match *://sa.ycit.edu.cn/*
// @match *://ncepu.jcedutec.cn/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_deleteValue
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @connect api.labsafetyt300.ltd
// @antifeature payment
// @tag 盐城工学院
// @tag 实验室安全
// @tag 学习辅助
// @tag 课程助手
// @run-at document-end
// ==/UserScript==
/*
* ============================================================
* v3.3.0(2026-11-10)
* · 倍速滑块轨道在 2x–3x 段染色为绿色,标出推荐区间(端点按 min=1/max=6 线性折算:
* 20%–40%)。绿色段本身即标记,不新增任何控件。
* · 滑块加悬停提示「高倍速会漏进度,推荐使用建议区间内的倍速数值」,提示框跟随
* 滑块位置弹出(沿用面板统一的动态 tooltip)。
* · 染色区间来自实测:3x 以内平台收到的进度点连续;4x 以上会跳号,中途一断,
* 最后一次上报值就成了最终进度(卡在 86% 这类数字)。
* · 面板 SCRIPT_INFO.version 与头部 @version 对齐(此前一直停在 3.2.3)。
* ============================================================
*/
/*
* v3.2.3(2026-11-08)
* · 商品价格、额度、有效期与介绍接入服务端热加载。
* · 价格说明和计费说明支持在线更新,保留五折商品说明。
* · 优先显示缓存并在后台刷新商品内容。
* · 修复界面状态刷新误弹授权错误;仅在尝试调用时显示对应提示。
* · 修复全屏错误提示被主面板遮挡。
* · 统一脚本头部与面板版本为 3.2.3。
*/
/*
* ============================================================
* v2.8.5(2026-11-05)
* · 修「刷新/重载后复习模式整个哑掉:视频题弹窗不答、不关、不跳过」。
* 实测(3/3 复现):页面重载后首屏 reviewCheck 只等 800ms 就开始取课程树,
* 而选中项要 3.7~4.9s 才出现 ⇒ 永远拿到空列表并直接 return。
* 连锁:reviewCourseId 一直是空 → VideoApiAnswer.enabled() 恒 false,
* 且 reviewMode 为真把 QuestionProcessor 兜底也挡住 ⇒ 两条分支都不进。
* ⇒ ① reviewCheck 首屏改为轮询等待(≤10s)直到拿到选中项与课程列表;
* ② enabled() 在「复习模式但尚未绑定复习课程」时仍允许兜底作答;
* ③ 课程树按标题去重(平台会下发两条同 key 的重复节点,
* 会让「下一节」指向同一个节点 ⇒ 切了等于原地重播);
* ④ 补 URL 变化监听:站内切课程若走前端路由(不整页重载),init 不会再跑,
* reviewCheck 一次都不触发 ⇒「复习模式: 开,但什么都不做」。同时给
* reviewCheck 加重入锁,避免路由触发与 _gotoNode 内调用叠成两条循环。
* 注:复习模式本身没有「自动启用」功能,只有 GM 记住上次开关(默认 false)。
* ============================================================
*/
/*
* ============================================================
* v2.8.4(2026-11-05)
* · 修「复习模式开着,但初次进页面不复习,要手动开关一次才动」。
* 根因:initAutoPlay 是复习检测(reviewCheck)的唯一入口,而它的调用条件是
* 「视频自动播放」开关;开关为 false 时整条复习链路根本不启动。
* ⇒ 开启复习模式即自动打开「视频自动播放」(开关处 + init 各兜一次,
* 后者用于历史 GM 里已存 false 的老用户)。复习检测失败仍不重试,另议。
* ============================================================
*/
/*
* ============================================================
* v2.8.3(2026-11-04)
* · 修「换账号后刷新,弹提示说卡密已绑定其他账号」的迷惑现象。
* 根因:cardKey / authStatus 是浏览器级持久化,不带账号维度;
* 换账号登录后刷新,面板仍显示上一账号那张卡的「已激活 + 余额」,
* 答题时服务端按卡密绑定账号校验,直接回 ACCOUNT_MISMATCH。
* · 新增 AuthService.accountMismatch():对比「卡密绑定账号」与
* 「页面当前登录账号」,两者都有值且不同才算冲突(额度型 / 缓存缺
* account_id / 未取到登录账号时不误判)。
* · 面板授权区:冲突时显示「● 已绑定其他账号」及两边账号,不再显示
* 绿色的「已激活」与旧卡余额。
* · ensureReady:冲突时就地拦住,不发请求,提示语写明该登录哪个账号。
* · 修「展开课程树」口径下的课程清单只算到第一章:_getAllLessons() 原先
* 把第一个顶层 li 一律当根,而课程学习页的 13 个章本身就是顶层 li,
* 实测只取到第 1 章的 6 节(全树 121 节)⇒ 复习模式走完第一章就报
* 「全部完成」。现按「顶层只有一个 li 且它的孩子自己还有孩子」判定为根,
* 两页取值均正确(courseDetail 121 节 / myCourse 13 章,均在真实页面实测)。
* · 正常刷课的章节衔接不走这条路径,行为不变;ChapterExpander 未改动
* (实测两页的章节点本就是展开态,它无事可做,日志也不会出现)。
* ============================================================
*/
/*
* ============================================================
* v2.8.2(2026-11-04)
* · 补 @homepageURL / @updateURL / @downloadURL 指向脚本页与安装地址,
* 装进 Tampermonkey 的用户也能自动跟进更新;功能不变。
* ============================================================
*/
/*
* ============================================================
* v2.8.1(2026-11-04)
* · 上架分发适配:头部加 @antifeature payment 与四条 @tag,
* 支持渠道改为 QQ 临时会话(原来指私有仓库,对外是死链)。
* · @description 如实写明考试面板会一键自动作答并自动交卷。
* ============================================================
*/
/*
* ============================================================
* v2.8.0(2026-11-04)
* · 课程树导航重写:由「只点下一节」的扁平写法换成「章 / 节 / 知识点」
* 三层识别 + 范围感知的 getNextCourse,翻章不再点错层级。
* · 常规模式改为三段式、不设跳过判据:章内切下一节 → 本章末且未展开
* 课程树则提示「当前章节已刷完」并停 → 本章末且已展开则直接接下一章;
* 到树末提示「全部课程已刷完」。不再因为「没学完」中断脚本。
* · 复习模式语义不变,判据仍只在 reviewCheck;顺带修掉树选中节点误命中
* 根节点、导致当前章节状态判错的问题。
* · 新增整屏提示组件 showBigNotice:只保留完成提示,去掉黄色警告。
* · 商品由 5 档精简为 2 档:尝鲜 3.90(80 算力)与账号型 10.00
* (1420 算力 / 约 747 道 / 10 天)。购买链接继续由服务端热加载。
* · 链接配置缓存加结构版本号:档位键集一变即作废旧缓存,避免老缓存
* 里缺 account 键而被误降级成「QQ 私聊购买」。
* · 头壳与本体版本号统一(此前分别是 2.6.4 与 2.7.0)。
* ============================================================
*/
/*
* ============================================================
* v2.7.0(2026-10-24)
* · 发卡平台由卡掌柜(ekaboss,域名已失效)切换到酷发卡(kufaka)。
* · 购买链接改为「热加载」:面板创建时向授权服务 GET /api/shop-config 拉一份
* 商品链接配置(12h 本地缓存、2s 超时),换发卡站只改服务器上的 JSON,
* 不必重新混淆发版;拉不到自动回落脚本内置链接。
* · 保底:服务端标 manual 或某档链接为空时,按钮降级为「QQ 私聊购买」,
* 跳 QQ 临时会话做人工发卡。
* ============================================================
*/
/*
* ============================================================
* v2.6.1(2026-10-12)
* · 修复面板玻璃描边与圆角错位。
* · 考试相关开关每次加载默认关闭。
* ============================================================
*/
/*
* ============================================================
* v2.5.22(2026-10-08)
* · 修复高级UI(玻璃态)四角「双圆角」瑕疵:面板 ::before 描边环原写死
* border-radius:20px,而玻璃态面板本体被改成 16px,两者错位 ⇒ 四角露出
* 两层弧线。现将圆角收敛为单一 CSS 变量 --panel-radius,描边环跟随面板,
* 四角弧线完全重合。
* ============================================================
*/
/*
* ============================================================
* v2.5.21(2026-10-08)
* · 「开始考试」与「自动提交」改为会话态:默认均关闭,且不再写盘
* ⇒ 刷新页面后一律回到初始态,不继承上一轮的开启状态。
* · 新增 SESSION_CONFIG 收敛这两个键的初始值(单一来源)。
* · 其余行为不变。
* ============================================================
*/
(function() {
'use strict';
// ============================ 核心配置 ============================
const SCRIPT_INFO = {
name: '实验室安全课程AI答题助手(优化合并版)',
version: '3.4.1.1',
author: '智能学习助手'
};
// ============================ 售卖链接:热加载 + 兜底 ============================
// 【2.7.0】购买链接不再写死在源码里。脚本是混淆后发到 GitHub 的静态文件,换发卡平台 /
// 改商品链接若写死在源码,每次都得重新混淆发版;改成「面板创建时向授权服务拉一份配置」,
// 服务器上那个 JSON 改完即生效,不用重新发版。
//
// 硬约束(沿用 2026-10-13 定下的低侵入原则):
// · 只在面板创建时拉一次,12h 内复用本地缓存 —— 不参与答题主链路,不影响计费与授权;
// · 2s 超时,失败静默回落内置兜底链接,绝不阻塞 UI、绝不弹错误;
// · 拿不到链接 / 服务端标 manual => 按钮自动降级为「QQ 私聊购买」(人肉发卡兜底)。
const SHOP_CONFIG_PATH = '/api/shop-config';
const SHOP_CONFIG_CACHE_KEY = 'shopConfigCache'; // GM 存储键:{ v: 结构版本, at: 时间戳, data: 配置 }
const SHOP_CONFIG_TTL = 12 * 60 * 60 * 1000; // 本地缓存有效期(12 小时)
// 【缓存结构版本】档位键集(SHOP_FALLBACK.links 的 key)一旦增删就必须 +1:
// 旧缓存在 12h 内不会重拉,若键集已变(如新增 account),旧缓存会让新档位被判"无链接"
// 而错误降级成「QQ 私聊购买」。版本不符 ⇒ 直接丢弃缓存重新拉。
const SHOP_SCHEMA = 3;
const SHOP_CONFIG_TIMEOUT = 2000; // 拉取超时(毫秒):宁可回落兜底也不卡面板
// 内置兜底:服务端拉不到时用(= 发版当时的酷发卡链接,改动见线上 shop_config.json)
const SHOP_FALLBACK = {
manual: false,
fallbackQQ: '746957502',
links: {
shop: 'https://www.kufaka.com/item/y4agq1', // 「购买卡密」按钮:跳最低档商品页
trial: 'https://www.kufaka.com/item/y4agq1', // 尝鲜 80 算力
account: 'https://www.kufaka.com/item/2nu65k' // 账号型 1420 算力(2026-11-14 商品重建,旧码 ad6woe 已失效)
}
};
// 人肉发卡兜底:跳 QQ 临时会话(不装 QQ 也可以走网页版)
function qqBuyUrl(qq) {
const uin = encodeURIComponent(String(qq || SHOP_FALLBACK.fallbackQQ));
return 'https://wpa.qq.com/msgrd?v=3&uin=' + uin + '&site=qq&menu=yes';
}
const ShopConfig = {
data: null, // 当前生效配置:{ manual, fallbackQQ, links: {...} }
inflight: null, // 进行中的请求 Promise(防重复拉)
// 取某一档的购买链接;空值统一返回 QQ 临时会话,保证按钮永远可点、不会死链
linkFor: function(key) {
const d = this.data || SHOP_FALLBACK;
if (d.manual) return qqBuyUrl(d.fallbackQQ);
const url = ((d.links || {})[key] || '').trim();
return url || qqBuyUrl(d.fallbackQQ);
},
// 该档是否走了「人工发卡」兜底
isManual: function(key) {
const d = this.data || SHOP_FALLBACK;
if (d.manual) return true;
return !(((d.links || {})[key] || '').trim());
},
// 购买按钮文案:正常档「点击购买 ¥x」;降级后「QQ 私聊购买 ¥x」
buttonText: function(key, price) {
return (this.isManual(key) ? 'QQ 私聊购买 ' : '点击购买 ') + (price || '');
},
// 应用一份配置。字段做白名单校验:只认 http(s) 链接、只认 5~12 位数字 QQ,
// 防止服务端配置被污染后把按钮改成 javascript: 之类。
// 另有「脏响应护栏」:既没明确 manual=true、又一个有效链接都没有 ⇒ 拒绝采纳。
// (典型场景:接口还没部署时服务端回 {"detail":"Not Found"},不能让它把兜底链接冲掉)
apply: function(raw) {
if (!raw || typeof raw !== 'object') return false;
const safeUrl = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u.trim())) ? u.trim() : '';
const src = (raw.links && typeof raw.links === 'object') ? raw.links : {};
const links = {};
Object.keys(SHOP_FALLBACK.links).forEach((k) => { links[k] = safeUrl(src[k]); });
const manual = raw.manual === true;
if (!manual && !Object.keys(links).some((k) => links[k])) return false;
const qq = String(raw.fallbackQQ || '');
this.data = {
manual: manual,
fallbackQQ: /^\d{5,12}$/.test(qq) ? qq : SHOP_FALLBACK.fallbackQQ,
links: links,
products: Array.isArray(raw.products) ? raw.products.filter(p=>p&&['trial','account'].includes(p.key)).map(p=>Object.fromEntries(['key','shortName','name','badge','type','price','power','questions','validity','unitCost','fit','desc'].filter(k=>typeof p[k]==='string'&&p[k].length<=2000).map(k=>[k,p[k]]))) : [],
priceNote: typeof raw.priceNote==='string'&&raw.priceNote.length<=12000?raw.priceNote:null,
feeNote: typeof raw.feeNote==='string'&&raw.feeNote.length<=12000?raw.feeNote:null
};
return true;
},
// 生效后原地刷新已渲染的 DOM(面板不重建,只改 href 与文案)
refreshUI: function() {
document.querySelectorAll('#ai-helper-panel .intro-price-btn').forEach((a) => {
const key = a.dataset.goods;
if (!key) return;
const base = (typeof GOODS_INTRO !== 'undefined' ? GOODS_INTRO : []).find((x) => x.key === key);
const g = base ? {...base,...((this.data?.products||[]).find(p=>p.key===key)||{})} : null;
const content=document.querySelector('#ai-helper-panel .intro-sub-content[data-goods='+key+']');
if(g&&content){
const set=(selector,text)=>{const el=content.querySelector(selector);if(el)el.textContent=text;};
set('.intro-goods-name',g.name);set('.intro-badge',g.badge);set('.intro-fit',g.fit);set('.intro-desc',g.desc);
const values=[g.type,g.power,g.questions,g.validity,g.unitCost];content.querySelectorAll('table tr').forEach((row,i)=>{if(row.cells[1]&&values[i]!=null)row.cells[1].textContent=values[i];});
const tab=document.querySelector('#ai-helper-panel .intro-sub-tab[data-goods='+key+']');if(tab)tab.textContent=g.shortName;
}
a.href = this.linkFor(key);
a.textContent = this.buttonText(key, g ? g.price : '');
});
for(const [name,value] of [['price',this.data?.priceNote],['fee',this.data?.feeNote]]){
const el=document.querySelector('#ai-helper-panel .price-note-body[data-note='+name+']');
if(el&&value!==null&&value!==undefined){el.textContent=value;el.style.whiteSpace='pre-line';}
}
},
// 缓存立即显示,每次加载面板仍后台取最新公开配置。
load: function() {
if (this.inflight) return this.inflight;
let cached=false;
// ① 缓存只用于立即显示,不阻止后台刷新。
try {
const raw = GM_getValue(SHOP_CONFIG_CACHE_KEY, '');
if (raw) {
const c = JSON.parse(raw);
if (c && c.v === SHOP_SCHEMA && c.data && (Date.now() - (c.at || 0)) < SHOP_CONFIG_TTL && this.apply(c.data)) {
this.refreshUI();
cached=true;
}
}
} catch (e) { /* 缓存损坏:当作没有,继续走远程 */ }
// ② 内置兜底先顶上,UI 立刻可用(不会出现空 href 的死按钮)
if(!cached)this.apply(SHOP_FALLBACK);
this.refreshUI();
// ③ 后台拉远程配置,失败/超时一律静默保持兜底
const base = String(currentConfig.authServerUrl || '').replace(/\/+$/, '');
if (!base) return Promise.resolve(this.data);
this.inflight = new Promise((resolve) => {
GM_xmlhttpRequest({
method: 'GET',
url: base + SHOP_CONFIG_PATH,
timeout: SHOP_CONFIG_TIMEOUT,
onload: (res) => {
try {
const j = JSON.parse(res.responseText);
// 兼容两种返回:裸对象 或 { success, data:{...} }
const payload = (j && j.data && typeof j.data === 'object') ? j.data : j;
if (this.apply(payload)) {
try { GM_setValue(SHOP_CONFIG_CACHE_KEY, JSON.stringify({ v: SHOP_SCHEMA, at: Date.now(), data: payload })); } catch (e) {}
this.refreshUI();
}
} catch (e) { /* 脏响应:保持兜底 */ }
resolve(this.data);
},
onerror: () => resolve(this.data),
ontimeout: () => resolve(this.data)
});
}).then((d) => { this.inflight = null; return d; });
return this.inflight;
}
};
// 自定义提示词长度上限(防单次 AI 消耗暴涨;错题数据注入不在此限)
const PROMPT_MAX_LEN = 2000;
// 考试批量答题:滑块边界(单轮题数 / 单次提交轮数)
// 上界的工程依据:单轮题数过大 -> 单次响应变长、JSON 截断风险上升;
// 单次提交轮数过大 -> 同瞬间并发请求数上升,服务端限流/超时概率上升。
const EXAM_BATCH_SIZE_MIN = 1;
const EXAM_BATCH_SIZE_MAX = 20;
const EXAM_CONCURRENCY_MIN = 1;
const EXAM_CONCURRENCY_MAX = 8;
// 【2.5.14】这三个默认值同时也是「一键完成」的预设:预设值 / 输入框留空时的回落值 / 界面上写的
// 预设文案,全部由它们派生,不再在别处手写数字 —— 改这一处,三处同步。
const EXAM_BATCH_SIZE_DEFAULT = 10;
const EXAM_CONCURRENCY_DEFAULT = 2;
// 单批请求失败的重试:网络类错误(连不上/超时/响应解析失败/限流)重发整批
// 3 次尝试 = 首次 + 2 次重试,退避 2s / 4s;不可重试的错误(余额/卡密/拦截)不浪费额度
const EXAM_RETRY_ATTEMPTS = 3;
const EXAM_RETRY_BASE_DELAY = 2000;
// 【2.5.9】「等待超时」滑块边界(秒):单批请求最多等多久,超时即判定该批失败、不重发
// 下界依据:服务端构建 10 题批量的响应一般要十几秒,30 秒留足余量;
// 上界依据:考试限时 60 分钟,单批等 180 秒已属极端,再长会侵蚀后面的答题与补救时间。
// 默认 70 = 2.5.9 之前的硬编码值,直接可用。
const EXAM_TIMEOUT_MIN = 30;
const EXAM_TIMEOUT_MAX = 180;
const EXAM_TIMEOUT_STEP = 10;
const EXAM_TIMEOUT_DEFAULT = 70;
// 非考试路径(视频答题等)的答题请求超时,维持原值不动
const AUTH_ANSWER_TIMEOUT_MS = 70000;
// 批量答题:一次问整节课的题(AI 侧是一整批),给足时间;命中题库时秒回
const AUTH_BATCH_TIMEOUT_MS = 120000;
// 【2.5.7】调度三件套(全自动、无 UI)
// 1) 令牌桶:全池任意两次请求至少间隔 250ms,避免并发 N 时"同一瞬间打出 N 个请求"被限流
const EXAM_MIN_REQUEST_INTERVAL = 250;
// 2) 退避抖动:等待 = BASE × 2^(k-1) × (1 - JITTER + rand()×2×JITTER),默认 0.5 ⇒ 0.5~1.5 倍
// 目的:多个 worker 同时失败时错开重发,避免又在同一毫秒一起撞上去
const EXAM_JITTER = 0.5;
// 3) 自适应降级:滑块给的是上限,有效并发随窗口失败率浮动
const EXAM_ADAPT_WINDOW = 4; // 滑动观察窗口(批)
const EXAM_ADAPT_FAIL_RATIO = 0.5; // 窗口失败率超过它 ⇒ 有效并发降到 1
const EXAM_ADAPT_RECOVER_STREAK = 3; // 连续成功这么多批 ⇒ 有效并发 +1(可回升到滑块上限)
// 轻量熔断:连续这么多批"网络类"失败 ⇒ 停手报错(不做冷却/探测/半开)
// 只对网络类生效:余额不足/上游欠费类本就不重试,一批失败即返回,谈不上"连环白等"
const EXAM_BREAKER_FAILS = 3;
const EXAM_NET_CODES = ['NETWORK_ERROR', 'TIMEOUT'];
// 取值端唯一夹紧入口:非数字/越界/小数 一律拉回合法整数区间
// 【2.5.12】输入框被清空时 value 是空串,Number('') === 0 会绕过"非数字回落默认值"的本意
// ⇒ 空值单独判一次,回落默认值(而非下界 1)
function isExamBlank(value) {
return value === '' || value === null || value === undefined;
}
function clampExamBatchSize(value) {
if (isExamBlank(value)) return EXAM_BATCH_SIZE_DEFAULT;
const n = Math.round(Number(value));
if (!Number.isFinite(n)) return EXAM_BATCH_SIZE_DEFAULT;
return Math.min(EXAM_BATCH_SIZE_MAX, Math.max(EXAM_BATCH_SIZE_MIN, n));
}
function clampExamConcurrency(value) {
if (isExamBlank(value)) return EXAM_CONCURRENCY_DEFAULT;
const n = Math.round(Number(value));
if (!Number.isFinite(n)) return EXAM_CONCURRENCY_DEFAULT;
return Math.min(EXAM_CONCURRENCY_MAX, Math.max(EXAM_CONCURRENCY_MIN, n));
}
// 等待超时(秒):越界按边界夹紧,非数字回落默认值;再按步长对齐(10 秒一档)
function clampExamRequestTimeout(value) {
if (isExamBlank(value)) return EXAM_TIMEOUT_DEFAULT;
const n = Math.round(Number(value));
if (!Number.isFinite(n)) return EXAM_TIMEOUT_DEFAULT;
const clamped = Math.min(EXAM_TIMEOUT_MAX, Math.max(EXAM_TIMEOUT_MIN, n));
return EXAM_TIMEOUT_MIN + Math.round((clamped - EXAM_TIMEOUT_MIN) / EXAM_TIMEOUT_STEP) * EXAM_TIMEOUT_STEP;
}
// 【2.5.21】会话态配置:不进 GM 存储、不跨刷新存活。
// 需求:刷新后「开始考试」「自动提交」一律回到初始态(关),上一轮的开启状态不残留。
// 实现:这两个键不再走 GM_getValue/GM_setValue,只改内存 currentConfig —— 与
// 「一键完成」的一次性语义也更贴:那是本场动作,不该变成常驻设置。
const SESSION_CONFIG = {
examEnabled: false, // 开始考试:默认关闭(真值每轮重置)
examAutoSubmit: false // 自动提交:默认关闭(真值每轮重置)
};
const DEFAULT_CONFIG = {
// 【3.1.0 开关精简】「自动答题」「自动检测答题」「手动作答模式」三个开关已删除:
// 全课答题恒跑(页面加载自动 + 一键按钮),弹窗观察器恒活,手动作答链路已删。
// GM 残留值一律不读,防止老配置复活死链路。
aiAnswerEnabled: true,
autoAnswer: true,
// 「答题后自动提交」是真闸门:关 = 流水线只答题不 POST(提交条停),默认开
autoSubmit: GM_getValue('autoSubmit', true),
randomAnswer: GM_getValue('randomAnswer', true),
matchRate: GM_getValue('matchRate', 0.6),
deepseekModel: GM_getValue('deepseekModel', 'deepseek-chat'),
deepseekTemperature: GM_getValue('deepseekTemperature', 0.1),
// 授权系统:AI 走服务端代理后,不再使用自填 key
// 【正式】公网授权服务固定域名
authServerUrl: 'https://api.labsafetyt300.ltd', // GM 开发版连接现有服务端。
cardKey: GM_getValue('cardKey', ''),
authStatus: GM_getValue('authStatus', '{}'), // 本地缓存卡密状态
videoSpeed: clampVideoSpeed(GM_getValue('videoSpeed', 2.0)),
debugMode: GM_getValue('debugMode', true),
// 章节展开 + 视频自动切换配置
expandChapters: GM_getValue('expandChapters', true),
autoPlayVideo: GM_getValue('autoPlayVideo', true),
autoSwitchVideo: GM_getValue('autoSwitchVideo', true),
videoAnswerMode: GM_getValue('videoAnswerMode', 'api-ai'),
// 【3.0】接管式答题窗口:显示开关 + 手动模式(手动 = 不自动答、不自动切课,只手填后点提交)
answerWindowOn: GM_getValue('answerWindowOn', true),
manualAnswer: false, // 【3.1.0】手动作答已删除,恒 false
// 【1.2.2 同步 · 2026-11-05】已答跳过:提交成功的题号落盘,下次进同一节不再重复提交。
// 关掉它就是老行为(每次进节全量重发),只在需要「用新题库覆盖旧答案」时才关。
skipAnswered: GM_getValue('skipAnswered', true),
// 【1.2.2 同步 · 2026-11-05 实测】提交节奏:平台是滑动窗口配额(≈3 次/10 秒),
// 同一题连发到第 4 次必被拦;换不同题实测 1200/2500/3000ms 仍会拦,3500ms 全程不撞。
submitGap: GM_getValue('submitGap', 3500),
// 撞限流后的重试:3 次,退避 3/6/9 秒(实测限流后约 6 秒恢复)
submitRetry: GM_getValue('submitRetry', 3),
chapterExpandDelay: GM_getValue('chapterExpandDelay', 500),
videoLoadDelay: GM_getValue('videoLoadDelay', 2000),
// 考试模式配置
// 【2.5.21】这两项已改为会话态(见 SESSION_CONFIG),默认均为关闭且刷新不保留
examEnabled: SESSION_CONFIG.examEnabled,
// examAutoAdvance:面板开关已移除(2.5.5,批量流程一次性填全部题、无需翻题)。
// 仍保留读取:文件内已停用的旧单题流程(ExamProcessor)会引用它,避免隐式 undefined。
examAutoAdvance: GM_getValue('examAutoAdvance', true),
examAutoSubmit: SESSION_CONFIG.examAutoSubmit,
examAdvanceDelay: GM_getValue('examAdvanceDelay', 800),
// 考试批量答题:两个滑块(读取即夹紧,越界存储值不会漏到请求端)
examBatchSize: clampExamBatchSize(GM_getValue('examBatchSize', EXAM_BATCH_SIZE_DEFAULT)),
examConcurrency: clampExamConcurrency(GM_getValue('examConcurrency', EXAM_CONCURRENCY_DEFAULT)),
// 【2.5.9】「等待超时」滑块(秒):超时即报错、不拆批、不原样重发(读取即夹紧)
examRequestTimeout: clampExamRequestTimeout(GM_getValue('examRequestTimeout', EXAM_TIMEOUT_DEFAULT)),
// 开发者模式
logDetail: GM_getValue('logDetail', false), // false=精简 true=详细(含AI对话)
customPrompt: GM_getValue('customPrompt', ''), // 统一自定义System提示词(所有题型通用)
customUserPrompt: GM_getValue('customUserPrompt', ''), // 自定义User提示词(可选)
// 复习模式
// 【3.1.0】复习模式已随「一键完成课程中所有题目」移除:按钮删了、入口没了。
// 此键写死 false(不读 GM),老用户残留的 true 不会 resurrect 旧链路;
// VideoController 里的 reviewMode 分支因此全部走 false 路径,属休眠代码。
reviewMode: false,
reviewData: GM_getValue('reviewData', '{}'), // JSON: { 章节名: { 题目: 答案 } }
glassBlur: GM_getValue('glassBlur', GM_getValue('advancedUI', true)), // 默认采用当前高级 UI 外观
glassBlurAmount: GM_getValue('glassBlurAmount', 28),
panelOpacity: GM_getValue('panelOpacity', 100),
depthStrength: GM_getValue('depthStrength', 100),
tabAnimEnabled: GM_getValue('tabAnimEnabled', true), // 默认采用当前动画设置
tabRubberBand: GM_getValue('tabRubberBand', 80), // Tab 拖拽弹力(越界可拉伸距离 px),0=硬边界;预设 80
tabSpringMode: GM_getValue('tabSpringMode', 'manual'), // 弹性模式:auto=物理联动(远=慢) manual=独立调节;预设 manual
tabSpringK: GM_getValue('tabSpringK', 0.09), // 独立模式下的弹簧软硬 K(每帧逼近比例 0.02~1,越小越软越慢);预设 0.09
// 趣味物理:默认全开(首次安装即有完整彩蛋体验);关掉后可分别恢复经典手感
funJelly: GM_getValue('funJelly', true), // 按钮果冻按压
funJellySwitch: GM_getValue('funJellySwitch', true), // 开关液态小球
funInertia: GM_getValue('funInertia', false), // 默认采用当前关闭状态
funParticles: GM_getValue('funParticles', false), // 默认采用当前关闭状态
// 【2.5.21】水球彩蛋默认关闭:长按标题栏 880ms 误触概率高,且进入后是整块面板形变,
// 非预期触发会让人以为面板坏了。仍可在「开发者面板」里手动开。
funWaterBall: GM_getValue('funWaterBall', false),
};
let currentConfig = {...DEFAULT_CONFIG};
// 复习模式本地错题库匹配阈值:基于中文题干的编辑距离比率,0.8 大约容许 20 字里错 4 字;
// 低于 0.7 会把「下列说法正确的是」这类近似题混起来,故取 0.8 兼顾容错与区分度。
const LOCAL_ANSWER_MATCH_THRESHOLD = 0.8;
// 复习模式本地题库解析缓存:以 reviewData 原始字符串为 key,未变则复用索引,避免每题全量重解析
let _reviewDataCacheKey = null;
let _reviewDataCache = null;
let isAnswering = false;
let authStatusRequest = null;
let popupObserver = null;
let popupPollingId = null;
let lastQuestionText = ''; // 用于判断复用容器内题目是否更新
let chapterObserver = null;
let chapterExpandPending = false;
let videoEndListenerAttached = false;
let examProcessing = false; // 考试处理中标记
let engineStarted = false; // 引擎是否已开跑(startEngine 幂等标记)
// ============================ 注入高级样式 ============================
GM_addStyle(`
#ai-helper-panel, #dev-panel {
--panel-transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1), height 0.35s cubic-bezier(0.22, 1, 0.36, 1), padding 0.35s ease, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease, background 0.35s ease, border-color 0.35s ease, border-radius 0.3s ease, box-shadow 0.35s ease, backdrop-filter 0.35s ease, -webkit-backdrop-filter 0.35s ease;
/* 【2.5.22】面板圆角唯一真源:::before 描边环必须跟随它,否则高级UI(16px)下
描边环仍用 20px,四角露出双层弧线(双圆角瑕疵)。 */
--panel-radius: 20px;
}
#ai-helper-panel {
position: fixed;
top: 120px;
right: 20px;
width: 340px;
background: #fff;
border-radius: var(--panel-radius, 20px);
padding: 20px;
z-index: 9999999;
font-size: 14px;
user-select: none;
/* 收起/展开只动视觉层(transform/opacity),不动布局 → tab 平移读数永远稳定 */
transition: var(--panel-transition);
box-sizing: border-box;
overflow: hidden;
border: 1px solid rgba(0,0,0,0.08);
box-shadow: 0 2px 12px rgba(0,0,0,0.12);
color: #1a1a1a;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
will-change: transform;
}
/* 高级UI开启:毛玻璃 + 物理质感 */
#ai-helper-panel.panel-glass {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(16px) saturate(200%);
-webkit-backdrop-filter: blur(16px) saturate(200%);
border: none;
box-shadow: 0 0 0 1px rgba(255,255,255,0.2), 0 8px 32px rgba(0,0,0,0.2), inset 0 2px 0 rgba(255,255,255,0.3);
will-change: transform;
}
#ai-helper-panel::before {
content: '';
position: absolute;
inset: 0;
border-radius: var(--panel-radius, 20px); /* 【2.5.22】跟随面板,杜绝双圆角 */
padding: 1px;
background: linear-gradient(135deg, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0.2) 50%, rgba(0,0,0,0.1) 100%);
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
pointer-events: none;
z-index: 10;
opacity: 0;
}
#ai-helper-panel.panel-glass::before {
opacity: 1;
}
#ai-helper-panel.mini {
/* 收起:真正的圆形按钮,不保留完整面板的长宽比例。 */
width: 50px;
height: 50px;
transform: none !important;
border-radius: 50%;
--panel-radius: 50%; /* 【2.5.22】mini 圆球:描边环同步为圆 */
padding: 0; /* 球心定位基准干净 */
cursor: pointer;
}
/* mini 态内容整体渐隐(不删 DOM、不 display:none,避免布局抖动)
只隐藏 head 内的兄弟元素(标题 span、⚙ 按钮),toggle 所在按钮组 div 保持 opacity:1,
这样 #panel-toggle 不会被父级 opacity 合成压没,mini 态 ✨ 能正常显形 */
#ai-helper-panel.mini .head > span,
#ai-helper-panel.mini #dev-toggle-btn,
#ai-helper-panel.mini .panel-tabs,
#ai-helper-panel.mini .panel-tab-view {
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s ease;
pointer-events: none;
}
/* mini 态高亮光斑禁用(防小球残影) */
#ai-helper-panel.mini #panel-highlight {
opacity: 0 !important;
}
/* mini 态收起按钮变身居中的 ✨ 圆钮 */
#ai-helper-panel.mini #panel-toggle {
position: absolute;
inset: 0;
margin: auto;
width: 50px;
height: 50px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
padding: 0;
transform: none;
background: #1890ff;
color: #fff;
box-shadow: 0 4px 16px rgba(24,144,255,0.4);
}
#panel-highlight {
position: absolute;
width: 200px;
height: 200px;
background: radial-gradient(circle, rgba(255,255,255,0.6) 0%, transparent 70%);
border-radius: 50%;
pointer-events: none;
z-index: 5;
opacity: 0;
transition: opacity 0.3s ease;
mix-blend-mode: overlay;
}
/* 高级UI关闭(白色面板)时不渲染光斑 */
#ai-helper-panel:not(.panel-glass) #panel-highlight {
display: none;
}
#ai-helper-panel .head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
cursor: inherit;
padding-bottom: 10px;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
/* 整个面板可拖提示:统一抓手(悬停grab,拖动中grabbing),控件区域恢复默认 */
#ai-helper-panel, #dev-panel { cursor: grab; }
#ai-helper-panel.dragging, #dev-panel.dragging { cursor: grabbing !important; }
#ai-helper-panel input, #ai-helper-panel button, #ai-helper-panel textarea, #ai-helper-panel select, #ai-helper-panel label, #ai-helper-panel a,
#dev-panel input, #dev-panel button, #dev-panel textarea, #dev-panel select, #dev-panel label, #dev-panel a { cursor: default; }
#ai-helper-panel .head span {
font-weight: bold;
font-size: 16px;
color: #333;
}
#ai-helper-panel .item {
margin: 10px 0;
display: flex;
justify-content: space-between;
align-items: center;
}
#ai-helper-panel label {
font-weight: 500;
}
/* 【2.5.21】.item 是 flex 容器,label 与右侧控件同为一行的 flex item:
中文标签默认 min-width:auto + 可折行,右侧控件一宽(如「填入答案 + 提交本次考试 + 开关」)
就把 label 挤成竖排(实测「手动提交」折成「手动提/交」两行)。
标签是定长文案,一律不折、不被压缩;要收缩就压右侧的弹性内容。 */
#ai-helper-panel .item > label {
flex-shrink: 0;
white-space: nowrap;
}
#ai-helper-panel input[type="text"], #ai-helper-panel select {
width: 150px;
padding: 6px 10px;
border: 1px solid rgba(0,0,0,0.1);
border-radius: 8px;
background: rgba(255,255,255,0.5);
font-size: 13px;
outline: none;
transition: border 0.2s;
}
#ai-helper-panel input[type="text"]:focus, #ai-helper-panel select:focus {
border-color: #1890ff;
background: rgba(255,255,255,0.8);
}
#ai-helper-panel input[type="checkbox"] {
accent-color: #1890ff;
width: 16px;
height: 16px;
}
#ai-helper-panel button {
background: #1890ff;
color: #fff;
border: none;
border-radius: 999px;
padding: 6px 14px;
cursor: pointer;
transition: all 0.2s ease;
font-weight: 500;
}
#ai-helper-panel button:hover {
background: #40a9ff;
transform: translateY(-1px);
}
#ai-helper-panel .btn-group {
display: flex;
gap: 10px;
margin-top: 15px;
}
#ai-helper-panel .btn-group button {
flex: 1;
padding: 10px 0;
}
/* iOS 风格开关(复选框 → 开关按钮) */
#ai-helper-panel .switch-wrap, #dev-panel .switch-wrap {
display: inline-flex;
align-items: center;
cursor: pointer;
position: relative;
width: 42px;
height: 24px;
}
#ai-helper-panel .switch-wrap input[type="checkbox"], #dev-panel .switch-wrap input[type="checkbox"] {
appearance: none;
-webkit-appearance: none;
width: 42px;
height: 24px;
border-radius: 999px;
background: rgba(0,0,0,0.18);
margin: 0;
position: absolute;
z-index: 1;
opacity: 0;
outline: none;
cursor: pointer;
}
#ai-helper-panel .switch-wrap .switch-track, #dev-panel .switch-wrap .switch-track {
width: 42px;
height: 24px;
border-radius: 999px;
background: rgba(0,0,0,0.18);
position: relative;
display: inline-block;
transition: background 0.25s;
pointer-events: none;
}
#ai-helper-panel .switch-wrap .switch-track .switch-knob, #dev-panel .switch-wrap .switch-track .switch-knob {
position: absolute;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 3px rgba(0,0,0,0.3);
transition: left 0.25s;
}
#ai-helper-panel .switch-wrap .switch-track.on, #dev-panel .switch-wrap .switch-track.on {
background: #1890ff;
}
#ai-helper-panel .switch-wrap .switch-track.on .switch-knob, #dev-panel .switch-wrap .switch-track.on .switch-knob {
left: 20px;
}
/* 视频倍速进度条(主面板 + 开发者面板统一样式) */
#ai-helper-panel input[type="range"],
#dev-panel input[type="range"] {
-webkit-appearance: none;
appearance: none;
width: 100%;
box-sizing: border-box;
height: 20px;
background: transparent;
border: none;
outline: none;
margin: 0;
padding: 0;
}
#ai-helper-panel input[type="range"]::-webkit-slider-runnable-track,
#dev-panel input[type="range"]::-webkit-slider-runnable-track {
height: 4px;
border-radius: 999px;
background: #e5e6eb;
margin-top: 8px;
}
#ai-helper-panel input[type="range"]::-webkit-slider-thumb,
#dev-panel input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: #fff;
border: 2px solid #1890ff;
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
cursor: pointer;
margin-top: -7px;
}
/* 【3.3.0】倍速滑块「推荐区间」染色:轨道在 2x–3x 段填绿。
区间端点按 min=1 / max=6 线性折算 —— 2x ⇒ 20%,3x ⇒ 40%;
其余段保持原浅灰,绿色段本身就是推荐标记,不额外加控件。
(特异性 2 个 id,压过上面 input[type="range"] 那条 #e5e6eb) */
#ai-helper-panel #video-speed::-webkit-slider-runnable-track,
#dev-panel #video-speed::-webkit-slider-runnable-track {
background: linear-gradient(90deg,
#e5e6eb 0%, #e5e6eb 20%,
#52c41a 20%, #52c41a 40%,
#e5e6eb 40%, #e5e6eb 100%);
}
/* 面板 tab 栏(分段控件风格:整条浅灰底 + 蓝色胶囊滑块) */
#ai-helper-panel .panel-tabs {
position: relative;
display: flex;
gap: 4px;
margin-bottom: 14px;
background: rgba(0,0,0,0.05);
padding: 3px;
border-radius: 999px;
}
#ai-helper-panel .panel-tab-indicator {
position: absolute;
top: 3px;
bottom: 3px;
left: 3px;
width: 0;
border-radius: 999px;
background: #1890ff;
box-shadow: 0 2px 8px rgba(24,144,255,0.4);
transition: left 0.7s cubic-bezier(0.22, 1, 0.36, 1), width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
z-index: 0;
pointer-events: none;
}
#ai-helper-panel .panel-tab {
position: relative;
z-index: 1;
flex: 1;
padding: 7px 0;
font-size: 12px;
font-weight: 600;
background: transparent;
color: #666;
border: none;
border-radius: 999px;
cursor: pointer;
transition: background 0.25s, color 0.25s, transform 0.25s;
}
#ai-helper-panel .panel-tab.active {
color: #0b1f3a;
transform: scale(1.12);
}
#ai-helper-panel .panel-tabs .panel-tab,
#ai-helper-panel .panel-tabs .panel-tab:hover {
background: transparent;
}
#ai-helper-panel .panel-tabs .panel-tab:hover:not(.active) {
background: rgba(24,144,255,0.12);
}
#ai-helper-panel .panel-tab:hover:not(.active) {
background: rgba(24,144,255,0.12);
color: #1890ff;
}
/* 介绍子 tab(分段控件,独立于主 tab;胶囊 indicator + 内容平移 + 拖动吸附) */
#ai-helper-panel .intro-sub-tabs {
position: relative;
display: flex;
gap: 4px;
margin-bottom: 10px;
background: rgba(0,0,0,0.05);
padding: 3px;
border-radius: 999px;
}
#ai-helper-panel .intro-indicator {
position: absolute;
top: 3px;
bottom: 3px;
left: 3px;
width: 0;
border-radius: 999px;
background: #1890ff;
box-shadow: 0 2px 6px rgba(24,144,255,0.4);
transition: left 0.7s cubic-bezier(0.22, 1, 0.36, 1), width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
z-index: 0;
pointer-events: none;
}
#ai-helper-panel .intro-sub-tab {
position: relative;
z-index: 1;
flex: 1;
padding: 5px 0;
font-size: 11px;
font-weight: 600;
background: transparent;
color: #666;
border: none;
border-radius: 999px;
cursor: pointer;
transition: color 0.25s;
white-space: nowrap;
}
/* 覆盖通用 button:hover 蓝色:介绍子 tab 自身 hover 保持透明,仅非激活 tab 显示浅蓝(与主 tab / dev tab 同款修复) */
#ai-helper-panel .intro-sub-tabs .intro-sub-tab,
#ai-helper-panel .intro-sub-tabs .intro-sub-tab:hover {
background: transparent;
transform: none;
}
#ai-helper-panel .intro-sub-tabs .intro-sub-tab:hover:not(.active) {
background: rgba(24,144,255,0.12);
}
#ai-helper-panel .intro-sub-tab:hover:not(.active) {
background: rgba(24,144,255,0.12);
color: #1890ff;
}
#ai-helper-panel .intro-sub-tab.active {
color: #fff;
}
/* 介绍内容视口:横向 carousel 平移(无滚动条,内容自然高度) */
#ai-helper-panel .intro-sub-view {
position: relative;
overflow: hidden;
}
#ai-helper-panel .intro-sub-track {
display: flex;
}
#ai-helper-panel.tab-anim .intro-sub-track {
transition: transform 0.5s cubic-bezier(0.22,1,0.36,1);
}
#ai-helper-panel .intro-sub-content {
flex: 0 0 100%;
min-width: 100%;
box-sizing: border-box;
overflow: hidden; /* 将购买胶囊及其阴影限制在所属页内,避免邻页边缘漏色。 */
}
#ai-helper-panel .intro-goods-name {
font-size: 14px;
font-weight: 700;
color: #333;
}
#ai-helper-panel .intro-price-btn {
display: inline-flex;
align-items: center;
padding: 3px 10px;
font-size: 12px;
font-weight: 700;
color: #fff;
background: #1890ff;
border-radius: 999px;
text-decoration: none;
box-shadow: 0 2px 6px rgba(24,144,255,0.3);
transition: filter 0.2s, transform 0.2s;
white-space: nowrap;
}
#ai-helper-panel .intro-price-btn:hover {
filter: brightness(1.1);
transform: translateY(-1px);
color: #fff;
background: #1890ff;
}
#ai-helper-panel .intro-badge {
display: inline-block;
margin: 4px 0 6px;
padding: 1px 8px;
font-size: 11px;
color: #1890ff;
background: rgba(24,144,255,0.1);
border-radius: 999px;
}
#ai-helper-panel .intro-spec {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
#ai-helper-panel .intro-spec td {
padding: 5px 8px;
border-bottom: 1px dashed rgba(0,0,0,0.08);
}
#ai-helper-panel .intro-spec td:first-child {
color: #888;
width: 76px;
white-space: nowrap;
}
#ai-helper-panel .intro-spec td:last-child {
font-weight: 600;
color: #333;
}
#ai-helper-panel .intro-fit {
margin-top: 8px;
padding: 6px 8px;
font-size: 12px;
color: #333;
background: rgba(24,144,255,0.08);
border-radius: 8px;
line-height: 1.5;
}
#ai-helper-panel .intro-desc {
margin-top: 8px;
font-size: 12px;
color: #666;
line-height: 1.6;
}
/* Tab 内容切换动画:整页平移 */
#ai-helper-panel .panel-tab-view {
position: relative; overflow: hidden;
}
#ai-helper-panel .panel-tab-track {
display: flex;
}
#ai-helper-panel .panel-tab-content {
flex: 0 0 100%; min-width: 100%; box-sizing: border-box;
padding: 0 10px;
}
#ai-helper-panel #tab-answer.answer-locked { position:relative; cursor:not-allowed; }
#ai-helper-panel #tab-answer.answer-locked > * { opacity:.35; filter:grayscale(1); pointer-events:none; }
#ai-helper-panel #tab-answer.answer-locked::after { content:''; position:absolute; inset:0; }
#ai-helper-panel.tab-anim .panel-tab-track {
transition: transform 0.5s cubic-bezier(0.22,1,0.36,1);
}
#ai-helper-panel.tab-anim:not(.mini) .panel-tab-view {
transition: height 0.5s cubic-bezier(0.22,1,0.36,1);
}
/* 复习模式悬停提示 */
.review-info-btn {
display: inline-flex; align-items: center; justify-content: center;
width: 16px; height: 16px; border-radius: 50%;
background: rgba(24,144,255,0.15); color: #1890ff;
font-size: 11px; font-weight: bold; cursor: help;
position: relative;
}
.review-info-btn::after {
content: attr(data-tooltip);
position: absolute; top: 100%; right: 0; z-index: 99999;
width: 220px; padding: 8px 10px; border-radius: 8px;
background: rgba(0,0,0,0.85); color: #fff; font-size: 11px;
line-height: 1.5; font-weight: normal; text-align: left;
opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s;
pointer-events: none; white-space: normal;
}
.review-info-btn:hover::after {
opacity: 1; visibility: visible;
}
/* 考试提交槽位:开关常驻(关闭态也不消失,随时可切回);【2.5.16】手动态两枚按钮(填入答案 / 提交本次考试)
仅在关闭自动提交时淡入,自动态一起淡出,开关位置不动 */
#ai-helper-panel .exam-submit-slot {
display: flex; align-items: center; justify-content: flex-end; gap: 8px;
min-height: 26px;
/* 【2.5.21】不让槽位反向压缩左侧标签(配合 .item > label 的 nowrap);
空间不足时由槽位内部换行,而不是把「手动提交」挤成竖排。 */
flex-shrink: 0;
}
#ai-helper-panel .exam-submit-slot .exam-manual-submit-btn {
padding: 4px 12px; border: none; border-radius: 8px;
background: #1890ff; color: #fff; font-size: 12px; font-weight: bold;
cursor: pointer; white-space: nowrap; line-height: 18px;
transition: opacity 0.25s ease, transform 0.25s ease;
/* 【2.5.21】按钮文案也定长,不被压窄(压窄会折行) */
flex-shrink: 0;
}
/* 【2.5.16】「填入答案」与「提交本次考试」并排:同为实心蓝,靠深浅区分(浅一档 = 填入)。
必须写在这里 —— 与 [data-empty="1"] / [data-state=...] 打平时靠先后顺序定胜负,
排在它们前面,灰态与各状态色才能照常生效 */
#ai-helper-panel .exam-submit-slot .exam-manual-submit-btn.exam-fill-btn {
background: #40a9ff;
}
#ai-helper-panel .exam-submit-slot .exam-manual-submit-btn.exam-fill-btn[data-state="idle"]:hover:not([data-empty="1"]) {
background: #69c0ff;
}
/* 无答案时不用 disabled(Chromium 不给 disabled 控件派发鼠标事件,悬停提示会失效),
改用 data-empty 视觉 + cursor:help,点击时由 JS 告警拦截 */
#ai-helper-panel .exam-submit-slot .exam-manual-submit-btn[data-state="idle"]:hover:not([data-empty="1"]) {
background: #40a9ff;
}
#ai-helper-panel .exam-submit-slot .exam-manual-submit-btn[data-empty="1"] {
background: rgba(0,0,0,0.12); color: rgba(0,0,0,0.35); cursor: help;
}
#ai-helper-panel .exam-submit-slot .exam-manual-submit-btn[data-state="submitting"] {
background: rgba(24,144,255,0.65); cursor: default;
}
/* 【2.5.19】取消 [data-state="done"] 成功态、[data-state="failed"] 失败态:
按钮点击后一律回常态(idle),成败只在 toast 里说;失败想再试直接再点一次就行,
不必让按钮变色喊「重试填入 / 重试提交」 */
/* 自动态:按钮淡出右移并让出指针(visibility 延迟到淡出结束才隐藏),开关始终在位 */
#ai-helper-panel .exam-submit-slot.is-auto .exam-manual-submit-btn {
opacity: 0; transform: translateX(6px); pointer-events: none; visibility: hidden;
transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}
.ai-toast {
position: fixed;
right: 20px;
padding: 12px 20px;
border-radius: 8px;
color: white;
font-weight: bold;
z-index: 10000000;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
animation: slideIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
/* 联系开发者留言弹窗(与主面板/开发者面板统一风格;高级UI开=毛玻璃) */
#feedback-overlay {
position: fixed; inset: 0;
background: rgba(0,0,0,0.45);
z-index: 9999999;
display: flex; align-items: center; justify-content: center;
}
#feedback-overlay .feedback-modal {
width: min(440px, 90vw);
background: #fff;
border: 1px solid rgba(0,0,0,0.08);
box-shadow: 0 8px 30px rgba(0,0,0,0.25);
border-radius: 20px;
padding: 20px 22px;
font-size: 13px;
color: #333;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
#feedback-overlay .feedback-modal.panel-glass {
background: rgba(255,255,255,0.15);
backdrop-filter: blur(16px) saturate(200%);
-webkit-backdrop-filter: blur(16px) saturate(200%);
border: none;
box-shadow: 0 0 0 1px rgba(255,255,255,0.2), 0 8px 32px rgba(0,0,0,0.2), inset 0 2px 0 rgba(255,255,255,0.3);
}
#feedback-overlay .feedback-modal input,
#feedback-overlay .feedback-modal textarea {
width: 100%;
box-sizing: border-box;
border: 1px solid rgba(0,0,0,0.1);
border-radius: 8px;
background: rgba(255,255,255,0.5);
padding: 8px;
font-size: 13px;
font-family: inherit;
color: #333;
outline: none;
transition: border 0.2s;
}
#feedback-overlay .feedback-modal input:focus,
#feedback-overlay .feedback-modal textarea:focus {
border-color: #1890ff;
background: rgba(255,255,255,0.8);
}
#feedback-overlay .feedback-modal button {
background: #1890ff;
color: #fff;
border: none;
border-radius: 999px;
padding: 8px 18px;
cursor: pointer;
transition: all 0.2s ease;
font-weight: 500;
font-size: 13px;
}
#feedback-overlay .feedback-modal button:hover {
background: #40a9ff;
transform: translateY(-1px);
}
#feedback-overlay .feedback-modal .fb-title {
font-size: 15px; font-weight: bold; color: #333;
}
/* 说明区:遇到问题 / 每日限额 两行统一为淡蓝底黑色字提示条(背景微蓝,文字黑色) */
#feedback-overlay .feedback-modal .fb-desc {
color: #333;
background: rgba(24,144,255,0.08);
border: 1px solid rgba(24,144,255,0.2);
padding: 8px 10px;
border-radius: 8px;
font-size: 12px;
line-height: 1.6;
margin-bottom: 6px;
font-weight: 500;
}
#feedback-overlay .feedback-modal .fb-limit {
color: #333;
background: rgba(24,144,255,0.08);
border: 1px solid rgba(24,144,255,0.2);
padding: 6px 10px;
border-radius: 8px;
font-size: 12px;
line-height: 1.5;
margin-bottom: 10px;
font-weight: 500;
}
/* 购买卡密/测试连接/联系开发者按钮悬停提示:已改为 JS 动态 tooltip(挂 body,见 createPanel 内绑定) */
#ai-helper-panel #buy-btn,
#ai-helper-panel #test-api-btn,
#ai-helper-panel #contact-btn {
position: relative;
z-index: 100;
}
#ai-helper-panel .auth-actions {
flex-wrap: nowrap;
}
#ai-helper-panel .auth-actions button {
flex: 1 1 0;
min-width: 0;
white-space: nowrap;
padding: 4px 6px !important;
font-size: 12px;
}
/* 底部说明折叠条(计费说明 / 价格说明,左对齐,收起态提示点击展开) */
#ai-helper-panel .price-note-toggle {
display: block;
width: 100%;
margin: 4px 0 0;
padding: 3px 0;
font-size: 10px;
color: #aaa;
background: transparent;
border: none;
cursor: pointer;
text-align: left;
}
#ai-helper-panel .price-note-toggle:hover {
color: #1890ff;
background: transparent;
transform: none;
}
#ai-helper-panel .price-note-body, #dev-panel .price-note-body {
display: none;
margin-top: 4px;
padding: 6px 8px;
font-size: 10px;
color: #888;
line-height: 1.6;
text-align: left;
background: rgba(0,0,0,0.03);
border-radius: 8px;
}
#ai-helper-panel .price-note-body.open, #dev-panel .price-note-body.open {
display: block;
}
/* 【2.5.11】标题行内的紧凑折叠按钮(参数行「ⓘ 说明」),不占独立一行 */
#ai-helper-panel .price-note-toggle.inline-note, #dev-panel .price-note-toggle.inline-note {
display: inline-block;
width: auto;
margin: 0;
padding: 0;
font-size: 10px;
line-height: 1;
white-space: nowrap;
}
/* 【2.5.12】考试参数由滑块改为数字输入框:省掉滑块本体与量程行,数值直接可改 */
#ai-helper-panel .exam-num-input {
width: 52px;
margin: 0;
padding: 2px 6px;
border: 1px solid rgba(24,144,255,0.35);
border-radius: 6px;
background: #fff;
color: #1890ff;
font-size: 12px;
font-weight: bold;
line-height: 18px;
text-align: center;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
/* 数字微调箭头在 52px 宽度下会挤掉数字,去掉;微调走键盘上/下或直接输入 */
#ai-helper-panel .exam-num-input::-webkit-outer-spin-button,
#ai-helper-panel .exam-num-input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
#ai-helper-panel .exam-num-input:focus {
border-color: #1890ff;
box-shadow: 0 0 0 2px rgba(24,144,255,0.15);
}
#ai-helper-panel .exam-param-unit {
font-size: 12px;
font-weight: bold;
color: #1890ff;
white-space: nowrap;
}
/* 【2.5.12】考试操作行:开始考试 / 一键完成,同宽并排 */
#ai-helper-panel .exam-action-row {
display: flex;
gap: 8px;
}
#ai-helper-panel .exam-act-btn {
flex: 1;
padding: 6px 8px;
border: none;
border-radius: 999px;
font-size: 12px;
font-weight: bold;
cursor: pointer;
white-space: nowrap;
transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}
/* 【2.5.13】两枚按钮统一蓝色调:状态只用蓝色深浅区分,不引入绿/红等异色 */
/* 「开始考试·未开始」主蓝实心 */
#ai-helper-panel .exam-act-btn.exam-act-start[data-on="0"] {
background: #1890ff; color: #fff;
}
#ai-helper-panel .exam-act-btn.exam-act-start[data-on="0"]:hover {
background: #40a9ff;
}
/* 「开始考试·已开始」浅蓝底 + 蓝字(点击即停),与实心态仅靠色深区分 */
#ai-helper-panel .exam-act-btn.exam-act-start[data-on="1"] {
background: rgba(24,144,255,0.14); color: #1890ff;
}
#ai-helper-panel .exam-act-btn.exam-act-start[data-on="1"]:hover {
background: rgba(24,144,255,0.26); color: #096dd9;
}
/* 「一键完成」比主蓝浅一档的实心蓝,与「开始考试」并排仍可区分 */
#ai-helper-panel .exam-act-btn.exam-act-oneclick {
background: #40a9ff; color: #fff;
}
#ai-helper-panel .exam-act-btn.exam-act-oneclick:hover {
background: #69c0ff;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }
/* 开发者独立悬浮窗 —— 与主面板统一风格 */
#dev-panel {
position: fixed;
top: 120px;
left: 20px;
width: 300px;
min-height: 280px;
background: #ffffff;
border-radius: var(--panel-radius, 20px);
padding: 20px;
z-index: 10000000;
font-size: 14px;
user-select: none;
display: none;
flex-direction: column;
overflow: hidden;
border: 1px solid rgba(0,0,0,0.08);
box-shadow: 0 2px 12px rgba(0,0,0,0.12);
color: #1a1a1a;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
transition: var(--panel-transition);
}
#dev-panel.panel-glass {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(16px) saturate(200%);
-webkit-backdrop-filter: blur(16px) saturate(200%);
border: none;
box-shadow: 0 0 0 1px rgba(255,255,255,0.2), 0 8px 32px rgba(0,0,0,0.2), inset 0 2px 0 rgba(255,255,255,0.3);
}
#dev-panel::before {
content: '';
position: absolute; inset: 0;
border-radius: var(--panel-radius, 20px); /* 【2.5.22】跟随面板,杜绝双圆角 */
padding: 1px;
background: linear-gradient(135deg, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0.2) 50%, rgba(0,0,0,0.1) 100%);
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: xor; mask-composite: exclude;
pointer-events: none; z-index: 10;
opacity: 0;
transition: opacity 0.3s ease;
}
#dev-panel.panel-glass::before {
opacity: 1;
}
#dev-panel:not(.panel-glass) .dev-highlight {
display: none;
}
#dev-panel.open { display: flex; }
#dev-panel { transform-origin: top left; }
#dev-panel.dev-morphing {
min-height: 0;
padding: 0 !important;
transition: none !important;
}
#dev-panel.dev-morphing::before { border-radius: inherit; }
#dev-panel.dev-measuring, #dev-panel.dev-measuring * {
transition: none !important;
}
#dev-panel .dev-morph-content {
display: flex;
flex-direction: column;
flex-shrink: 0;
box-sizing: border-box;
}
#dev-panel .dev-morph-icon {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: #fff;
pointer-events: none;
}
#dev-panel .dev-highlight {
position: absolute; width: 180px; height: 180px;
background: radial-gradient(circle, rgba(255,255,255,0.6) 0%, transparent 70%);
border-radius: 50%; pointer-events: none; z-index: 5;
opacity: 0; transition: opacity 0.3s ease; mix-blend-mode: overlay;
}
#dev-panel .dev-head {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 12px; padding-bottom: 8px;
border-bottom: 1px solid rgba(0,0,0,0.1);
cursor: inherit; font-weight: bold; font-size: 16px; color: #333;
position: relative; z-index: 11;
}
#dev-panel .dev-body {
position: relative; z-index: 11;
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
#dev-panel .dev-tabs {
position: relative;
display: flex; gap: 4px; margin-bottom: 12px;
background: rgba(0,0,0,0.05); padding: 3px; border-radius: 999px;
}
/* dev 面板胶囊滑块(与主面板一致) */
#dev-panel .dev-tab-indicator {
position: absolute;
top: 3px; bottom: 3px; left: 3px;
width: 0;
border-radius: 999px;
background: #1890ff;
box-shadow: 0 2px 8px rgba(24,144,255,0.4);
transition: left 0.7s cubic-bezier(0.22, 1, 0.36, 1), width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
z-index: 0;
pointer-events: none;
}
#dev-panel .dev-tab-btn {
position: relative;
z-index: 1;
flex: 1; padding: 7px 0; font-size: 12px; font-weight: 600;
background: transparent; color: #666; border: none; border-radius: 999px;
cursor: pointer; box-shadow: none; text-align: center;
transition: background 0.25s, color 0.25s, transform 0.25s;
}
#dev-panel .dev-tab-btn.active {
color: #0b1f3a; font-weight: 600;
transform: scale(1.12);
}
/* 覆盖通用 button:hover 蓝色:dev tab 自身 hover 保持透明,仅非激活 tab 显示浅蓝 */
#dev-panel .dev-tabs .dev-tab-btn,
#dev-panel .dev-tabs .dev-tab-btn:hover {
background: transparent;
}
#dev-panel .dev-tabs .dev-tab-btn:hover:not(.active) {
background: rgba(24,144,255,0.12);
}
#dev-panel .dev-tab-btn:hover:not(.active) {
background: rgba(24,144,255,0.12); color: #1890ff;
}
#dev-panel .dev-tab-view { position: relative; overflow: hidden; }
#dev-panel .dev-tab-track { display: flex; }
#dev-panel .dev-tab-view { max-height: calc(100vh - 180px); overflow-y: auto; }
#dev-panel #exam-advanced-controls .item { display:flex; align-items:center; justify-content:space-between; gap:8px; margin:8px 0; }
#dev-panel #exam-advanced-controls input[type="number"] { width:64px; box-sizing:border-box; }
#ai-helper-panel #tab-exam .exam-submit-slot { min-width:0; flex-shrink:1; flex-wrap:wrap; }
#ai-helper-panel #tab-exam progress { box-sizing:border-box; max-width:100%; }
#dev-panel .dev-tab-content { flex: 0 0 100%; min-width: 100%; box-sizing: border-box; display: block; padding: 0 8px; }
/* dev 面板 tab 内容切换动画(与主面板同步,整页平移) */
#dev-panel.tab-anim .dev-tab-track {
transition: transform 0.5s cubic-bezier(0.22,1,0.36,1);
}
#dev-panel.tab-anim .dev-tab-view {
transition: height 0.5s cubic-bezier(0.22,1,0.36,1);
}
#dev-panel .dev-ui-sub-tabs {
position: relative; display: flex; gap: 4px; margin: 2px 0 10px;
background: rgba(0,0,0,0.05); padding: 3px; border-radius: 999px;
}
#dev-panel .dev-ui-sub-indicator {
position: absolute; top: 3px; bottom: 3px; left: 3px; width: 0;
border-radius: 999px; background: rgba(24,144,255,0.85);
transition: left 0.5s cubic-bezier(0.22,1,0.36,1), width 0.5s cubic-bezier(0.22,1,0.36,1);
pointer-events: none;
}
#dev-panel .dev-ui-sub-tab {
position: relative; z-index: 1; flex: 1; padding: 5px 0; border: 0;
border-radius: 999px !important; background: transparent; color: #666; font-size: 11px; font-weight: 600;
box-shadow: none; text-align: center; transition: background 0.25s, color 0.25s;
}
#dev-panel .dev-ui-sub-tab.active { color: #fff; }
#dev-panel .dev-ui-sub-tabs .dev-ui-sub-tab,
#dev-panel .dev-ui-sub-tabs .dev-ui-sub-tab:hover {
border-radius: 999px !important; background: transparent; box-shadow: none; transform: none;
}
#dev-panel .dev-ui-sub-tabs .dev-ui-sub-tab:hover:not(.active) {
background: rgba(24,144,255,0.12); color: #1890ff;
}
#dev-panel .dev-ui-sub-view { position: relative; overflow: hidden; }
#dev-panel .dev-ui-sub-track { display: flex; }
#dev-panel .dev-ui-sub-content { flex: 0 0 100%; min-width: 100%; box-sizing: border-box; padding: 0 5px; }
#dev-panel.tab-anim .dev-ui-sub-track { transition: transform 0.5s cubic-bezier(0.22,1,0.36,1); }
#dev-panel.tab-anim .dev-ui-sub-view { transition: height 0.5s cubic-bezier(0.22,1,0.36,1); }
#dev-panel #tab-log.dev-tab-content { display: flex; flex-direction: column; overflow: hidden; }
#dev-panel textarea {
width: 100%; height: 44px; padding: 4px 6px; border: 1px solid rgba(0,0,0,0.1);
border-radius: 8px; font-size: 12px; resize: vertical; background: rgba(255,255,255,0.5);
font-family: inherit; outline: none;
box-sizing: border-box; /* 防止 100%+padding 溢出到相邻 tab 页 */
}
#dev-panel textarea:focus { border-color: #1890ff; background: rgba(255,255,255,0.8); }
#log-view {
width: 100%; flex: 0 1 auto; height: 200px; min-height: 100px; max-height: 600px;
resize: vertical; padding: 6px 8px; border: 1px solid rgba(0,0,0,0.1);
border-radius: 8px; font-size: 12px; font-family: Consolas, "Courier New", monospace;
background: rgba(0,0,0,0.04); color: #333; overflow: auto;
white-space: pre-wrap; word-break: break-all; outline: none;
box-sizing: border-box;
}
#dev-panel button {
background: #1890ff; color: #fff; border: none;
border-radius: 999px; padding: 6px 14px; cursor: pointer;
transition: all 0.2s ease; font-weight: 500;
}
#dev-panel button:hover {
background: #40a9ff; transform: translateY(-1px);
}
#dev-panel .mini-btn { padding: 2px 8px; font-size: 11px; box-shadow: none; }
#dev-panel .section-title { font-size: 12px; color: #999; margin: 6px 0 3px; font-weight: bold; }
#dev-panel .close-btn {
background: rgba(24,144,255,0.15) !important; color: #1890ff; font-size: 16px;
cursor: pointer; padding: 2px 8px; box-shadow: none !important; line-height: 1;
}
#dev-panel .close-btn:hover { color: #ff4d4f; }
#dev-panel .item { margin: 8px 0; display: flex; justify-content: space-between; align-items: center; }
#dev-panel label { font-weight: 500; font-size: 13px; }
#dev-panel input[type="checkbox"] { accent-color: #1890ff; width: 16px; height: 16px; }
/* ============ 物理系彩蛋 UI ============ */
/* 1. 按钮果冻按压(欠阻尼回弹) */
#ai-helper-panel button, #dev-panel button { transform-origin: center; will-change: transform; }
#ai-helper-panel button.pressed, #dev-panel button.pressed {
transform: scale(0.86) !important;
transition: transform 0.07s ease !important;
}
#ai-helper-panel button.jelly-pop, #dev-panel button.jelly-pop {
animation: ui-btn-jelly-pop 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes ui-btn-jelly-pop {
0% { transform: scale(0.86); }
45% { transform: scale(1.08); }
70% { transform: scale(0.96); }
100% { transform: scale(1); }
}
/* 2. 开关液态小球(overshoot + 按压拉伸) */
#ai-helper-panel.fun-jelly-switch .switch-wrap .switch-track .switch-knob,
#dev-panel.fun-jelly-switch .switch-wrap .switch-track .switch-knob {
transition: left 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#ai-helper-panel.fun-jelly-switch .switch-wrap:active .switch-track .switch-knob,
#dev-panel.fun-jelly-switch .switch-wrap:active .switch-track .switch-knob {
transform: scaleX(1.35) scaleY(0.8);
}
/* 3. 面板撞墙压缩回弹 */
#ai-helper-panel.squash, #dev-panel.squash {
animation: ui-panel-squash 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes ui-panel-squash {
0% { transform: scale(1, 1); }
30% { transform: scale(0.96, 1.05); }
60% { transform: scale(1.03, 0.96); }
100% { transform: scale(1, 1); }
}
/* 4. 水球模式(长按标题栏触发):面板变果冻水晶球 */
#ai-helper-panel.water-ball {
width: 96px !important;
height: 96px !important;
padding: 0 !important;
border-radius: 50% !important;
overflow: visible !important;
cursor: grab;
background: linear-gradient(135deg, rgba(120,200,255,0.9) 0%, rgba(24,144,255,0.92) 45%, rgba(0,76,153,0.95) 100%);
box-shadow: 0 0 0 1px rgba(255,255,255,0.35), 0 12px 40px rgba(24,144,255,0.45), inset 0 -8px 16px rgba(0,0,0,0.15), inset 0 6px 10px rgba(255,255,255,0.4);
animation: ui-water-ball-pulse 2.4s ease-in-out infinite;
}
@keyframes ui-water-ball-pulse {
0%, 100% { transform: scale(1); border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
30% { transform: scale(1.05, 0.97); border-radius: 46% 54% 48% 52% / 54% 46% 52% 48%; }
60% { transform: scale(0.98, 1.04); border-radius: 54% 46% 52% 48% / 46% 54% 48% 52%; }
}
#ai-helper-panel .water-ball-core {
display: none;
}
#ai-helper-panel.water-ball > * { display: none !important; }
#ai-helper-panel.water-ball .water-ball-core {
display: flex !important;
position: absolute;
inset: 0;
align-items: center;
justify-content: center;
font-size: 44px;
filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
animation: ui-water-core-float 2.4s ease-in-out infinite;
}
@keyframes ui-water-core-float {
0%, 100% { transform: translateY(0) rotate(-6deg); }
50% { transform: translateY(-6px) rotate(6deg); }
}
#ai-helper-panel.water-ball #panel-highlight { opacity: 1 !important; }
/* 5. 拖拽粒子尾迹 */
#ui-particle-layer {
position: fixed; inset: 0;
pointer-events: none;
z-index: 9999998;
overflow: hidden;
}
#ui-particle-layer .uip {
position: absolute;
border-radius: 50%;
pointer-events: none;
animation: ui-particle-fly var(--dur, 0.7s) cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
}
@keyframes ui-particle-fly {
0% { transform: translate(0, 0) scale(1); opacity: var(--o, 0.9); }
100% { transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(0); opacity: 0; }
}
/* 乳白磨砂:保留鼠标倾斜与 Tab 滑块,压低其他视觉噪声。 */
#ai-helper-panel.panel-glass, #dev-panel.panel-glass {
background: rgba(248, 250, 253, calc(0.72 * var(--panel-opacity, 1)));
backdrop-filter: blur(var(--glass-blur, 28px)) saturate(125%);
-webkit-backdrop-filter: blur(var(--glass-blur, 28px)) saturate(125%);
border: 1px solid rgba(255,255,255,0.92);
box-shadow: 0 12px 36px rgba(28,42,66,0.12), 0 0 0 1px rgba(28,42,66,0.06);
color: #273244;
}
/* 拖动浮层时暂停背景采样,避免文字底图在合成层重绘中闪烁。 */
#ai-helper-panel.panel-glass:not(.mini):not(.water-ball), #dev-panel.panel-glass {
padding: 16px;
border-radius: 16px;
--panel-radius: 16px; /* 【2.5.22】同步描述边环,与面板圆角保持一致 */
}
/* 与主面板共用外观过渡;文字布局属性也必须有可插值的起止值。 */
#dev-panel { box-sizing: border-box; }
#dev-panel .dev-head {
line-height: 1.4; letter-spacing: 0; font-weight: 600;
transition: padding 0.35s ease, font-size 0.35s ease, letter-spacing 0.35s ease, color 0.35s ease;
}
#dev-panel .item {
line-height: 1.4; gap: 0;
transition: padding 0.35s ease, font-size 0.35s ease, line-height 0.35s ease, gap 0.35s ease;
}
#ai-helper-panel.panel-glass .head, #dev-panel.panel-glass .dev-head {
margin-bottom: 12px;
padding-bottom: 12px;
border-bottom-color: rgba(28,42,66,0.07);
}
#ai-helper-panel.panel-glass .head span, #dev-panel.panel-glass .dev-head {
font-size: 14px;
font-weight: 600;
letter-spacing: 0.2px;
color: #273244;
}
#ai-helper-panel.panel-glass .item, #dev-panel.panel-glass .item {
margin: 8px 0;
gap: 10px;
font-size: 12px;
line-height: 1.6;
}
#dev-panel.panel-glass #tab-ui .item .item { padding: 4px 0; }
#ai-helper-panel.panel-glass button:not(.panel-tab):not(.intro-sub-tab),
#dev-panel.panel-glass button:not(.dev-tab-btn) {
border-radius: 8px;
box-shadow: none;
transition: background 150ms ease, transform 120ms ease;
}
#ai-helper-panel.panel-glass button:hover, #dev-panel.panel-glass button:hover {
transform: none;
}
#ai-helper-panel.panel-glass button:active, #dev-panel.panel-glass button:active {
transform: scale(0.97);
}
#ai-helper-panel.panel-glass .panel-tabs, #ai-helper-panel.panel-glass .intro-sub-tabs,
#dev-panel.panel-glass .dev-tabs { background: rgba(28,42,66,0.045); }
#ai-helper-panel.panel-glass .panel-tab.active, #dev-panel.panel-glass .dev-tab-btn.active {
color: #fff;
transform: none;
}
#ai-helper-panel.panel-glass .panel-tab-indicator, #dev-panel.panel-glass .dev-tab-indicator {
box-shadow: 0 2px 5px rgba(24,144,255,0.18);
}
#ai-helper-panel.panel-glass input[type="text"], #dev-panel.panel-glass textarea {
background: rgba(255,255,255,0.8);
border-color: rgba(28,42,66,0.1);
}
#ai-helper-panel.panel-glass #test-api-btn,
#ai-helper-panel.panel-glass #buy-btn,
#ai-helper-panel.panel-glass #contact-btn,
#ai-helper-panel.panel-glass #dev-toggle-btn {
background: #e9eff7 !important;
color: #45617f !important;
}
#ai-helper-panel .panel-tab-track, #dev-panel .dev-tab-track,
#dev-panel .dev-ui-sub-track { align-items: flex-start; }
/* 导航和内容共用一个透视平面,内部 carousel 继续各自裁切。 */
#ai-helper-panel .panel-depth-layer, #dev-panel .panel-depth-layer {
display: flex;
flex-direction: column;
min-width: 0;
transition: transform 0.18s ease-out;
}
#ai-helper-panel .head > span, #dev-panel .dev-head > span {
transition: translate 0.18s ease-out, transform 0.18s ease-out;
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
#ai-helper-panel.panel-glass:not(.mini):not(.water-ball):not(.dragging),
#dev-panel.panel-glass:not(.dragging):not(.dev-morphing) {
box-shadow: calc(var(--depth-x, 0) * -5px) calc(12px - var(--depth-y, 0) * 4px) 36px rgba(28,42,66,0.12),
0 0 0 1px rgba(28,42,66,0.06);
}
#ai-helper-panel.panel-glass:not(.mini):not(.water-ball):not(.dragging) .head > span,
#dev-panel.panel-glass:not(.dragging):not(.dev-morphing) .dev-head > span {
translate: calc(var(--depth-x, 0) * 2.5px) calc(var(--depth-y, 0) * 2.5px);
}
#ai-helper-panel.panel-glass:not(.mini):not(.water-ball):not(.dragging) .head > span,
#dev-panel.panel-glass:not(.dragging):not(.dev-morphing) .dev-head > span,
#ai-helper-panel.panel-glass:not(.mini):not(.water-ball):not(.dragging) .panel-depth-layer,
#dev-panel.panel-glass:not(.dragging):not(.dev-morphing) .panel-depth-layer {
transform: perspective(1000px) rotateX(calc(var(--depth-y, 0) * -2.6deg)) rotateY(calc(var(--depth-x, 0) * 3.2deg));
}
}
#ai-helper-panel button:focus-visible, #dev-panel button:focus-visible,
#ai-helper-panel .switch-wrap:has(input:focus-visible), #dev-panel .switch-wrap:has(input:focus-visible) {
outline: 2px solid #1890ff;
outline-offset: 3px;
}
`);
// ============================ 工具函数 ============================
const utils = {
resetPanelDepth: function(panel) {
panel.style.setProperty('--depth-x', 0);
panel.style.setProperty('--depth-y', 0);
const highlight = panel.querySelector('#panel-highlight, .dev-highlight');
if (highlight) highlight.style.opacity = '0';
},
bindPanelDepth: function(panel) {
const highlight = panel.querySelector('#panel-highlight, .dev-highlight');
const motion = window.matchMedia('(hover: hover) and (prefers-reduced-motion: no-preference)');
let frame = null, clientX = 0, clientY = 0;
const reset = () => {
if (frame !== null) cancelAnimationFrame(frame);
frame = null;
utils.resetPanelDepth(panel);
};
panel.addEventListener('mousemove', event => {
clientX = event.clientX;
clientY = event.clientY;
if (frame !== null) return;
frame = requestAnimationFrame(() => {
frame = null;
if (!motion.matches || !currentConfig.depthStrength || !panel.classList.contains('panel-glass')
|| panel.matches('.mini, .water-ball, .dragging, .dev-morphing')
|| panel.contains(document.activeElement) && document.activeElement.matches('input, textarea, select')) {
reset();
return;
}
const rect = panel.getBoundingClientRect();
const x = clientX - rect.left, y = clientY - rect.top;
const normalized = (position, size) => Math.max(-1, Math.min(1, position / size * 2 - 1)) * currentConfig.depthStrength / 100;
panel.style.setProperty('--depth-x', normalized(x, rect.width));
panel.style.setProperty('--depth-y', normalized(y, rect.height));
highlight.style.opacity = '1';
highlight.style.left = (x - highlight.offsetWidth / 2) + 'px';
highlight.style.top = (y - highlight.offsetHeight / 2) + 'px';
});
});
['mouseleave', 'mousedown', 'keydown', 'focusin'].forEach(event => panel.addEventListener(event, reset));
motion.addEventListener('change', reset);
},
similarity: function(s1, s2) {
if (!s1 || !s2) return 0;
if (s1 === s2) return 1;
const s1Lower = s1.toLowerCase();
const s2Lower = s2.toLowerCase();
if (s1Lower.includes(s2Lower) || s2Lower.includes(s1Lower)) return 0.9;
const matrix = [];
for (let i = 0; i <= s1Lower.length; i++) matrix[i] = [i];
for (let j = 0; j <= s2Lower.length; j++) matrix[0][j] = j;
for (let i = 1; i <= s1Lower.length; i++) {
for (let j = 1; j <= s2Lower.length; j++) {
const cost = s1Lower[i-1] === s2Lower[j-1] ? 0 : 1;
matrix[i][j] = Math.min(matrix[i-1][j] + 1, matrix[i][j-1] + 1, matrix[i-1][j-1] + cost);
}
}
return 1 - matrix[s1Lower.length][s2Lower.length] / Math.max(s1Lower.length, s2Lower.length);
},
fuzzyMatchIndex: function(options, answers, matchRate = 0.6) {
const matchArr = [];
if (!answers || !Array.isArray(answers)) return matchArr;
answers.forEach(answer => {
options.forEach((option, index) => {
if (this.similarity(option.text || option, answer) > matchRate && !matchArr.includes(index)) matchArr.push(index);
});
});
return matchArr;
},
wait: ms => new Promise(resolve => setTimeout(resolve, ms)),
removeHtml: html => html ? html.replace(/<[^>]*>/g, '') : '',
cleanText: text => text ? text.replace(/\s+/g, ' ').trim() : '',
clickAndVerify: async function(option) {
if (!option || !option.element) return false;
option.element.click();
for (let i = 0; i < 10; i++) {
await this.wait(100);
const isCheckedClass = option.element.className.includes('-checked');
const isInputChecked = option.inputElement && option.inputElement.checked;
if (isCheckedClass || isInputChecked) {
return true;
}
if (i === 2) {
option.element.click();
if (option.inputElement) {
option.inputElement.click();
}
}
}
return false;
},
log: (...args) => { if (currentConfig.debugMode) console.log(`[${SCRIPT_INFO.name}]`, ...args); },
showMessage: function(message, type = 'info', duration = 3000) {
const colors = { success: '#52c41a', error: '#ff4d4f', warning: '#faad14', info: '#1890ff' };
const msgDiv = document.createElement('div');
msgDiv.className = 'ai-toast';
msgDiv.style.background = colors[type] || colors.info;
msgDiv.innerHTML = message;
// 垂直堆叠:统计当前可见提示数,每条下移52px
const existing = document.querySelectorAll('.ai-toast:not(.ai-toast-out)').length;
msgDiv.style.top = (20 + existing * 52) + 'px';
document.body.appendChild(msgDiv);
const ttl = (type === 'error' || type === 'warning') ? (duration || 5000) : (duration || 3000);
setTimeout(() => {
msgDiv.classList.add('ai-toast-out');
msgDiv.style.animation = 'slideOut 0.3s cubic-bezier(0.22, 1, 0.36, 1) forwards';
setTimeout(() => msgDiv.remove(), 300);
}, ttl);
},
// 大号居中的醒目提示(半透明遮罩 + 大字主文案 + 可选小字副文案),
// 常驻显示,点击屏幕任意处关闭(不自动消失)。
showBigNotice: function(message, subtitle, type = 'success', dismissible = true) {
const colors = { success: '#52c41a', error: '#ff4d4f', warning: '#faad14', info: '#1890ff' };
const overlay = document.createElement('div');
overlay.style.cssText = 'position:fixed;inset:0;z-index:10000002;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0.55);';
const box = document.createElement('div');
box.style.cssText = `background:${colors[type] || colors.success};color:#fff;padding:40px 64px;border-radius:18px;box-shadow:0 16px 60px rgba(0,0,0,0.45);text-align:center;user-select:none;max-width:90vw;`;
const big = document.createElement('div');
big.style.cssText = 'font-size:32px;font-weight:700;line-height:1.4;';
big.textContent = message;
box.appendChild(big);
if (subtitle) {
const small = document.createElement('div');
small.style.cssText = 'margin-top:14px;font-size:15px;font-weight:400;opacity:0.9;line-height:1.5;';
small.textContent = subtitle;
box.appendChild(small);
}
box.animate([{ transform: 'scale(0.5)', opacity: 0 }, { transform: 'scale(1)', opacity: 1 }], { duration: 300, easing: 'cubic-bezier(.22,1,.36,1)' });
overlay.appendChild(box);
document.body.appendChild(overlay);
if (dismissible) overlay.addEventListener('click', () => {
box.animate([{ transform: 'scale(1.05)', opacity: 1 }, { transform: 'scale(1.05)', opacity: 0 }], { duration: 250, easing: 'ease' }).onfinish = () => overlay.remove();
});
return overlay;
},
findSubmitButton: function(popup) {
const submitSelectors = ['.ant-modal-footer .ant-btn-primary', '.ant-modal-footer button:last-child', 'button.ant-btn-primary', 'button:contains("提交")', 'button:contains("确定")'];
let submitBtn = null;
for (const selector of submitSelectors) {
try {
submitBtn = popup.querySelector(selector);
if (submitBtn && !submitBtn.disabled && submitBtn.offsetParent) break;
} catch (e) {}
}
if (!submitBtn) {
const allButtons = popup.querySelectorAll('button');
for (const btn of allButtons) {
if ((btn.textContent.includes('提交') || btn.textContent.includes('确定')) && !btn.disabled && btn.offsetParent) { submitBtn = btn; break; }
}
}
return submitBtn;
},
triggerButtonClick: function(btn) {
if (!btn) return false;
try {
btn.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
btn.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
btn.dispatchEvent(new MouseEvent('click', { bubbles: true }));
btn.click();
return true;
} catch (e) { return false; }
},
// 果冻按钮:mousedown 压扁 / mouseup 欠阻尼回弹 / 中途取消恢复
jellyPress: function(btn) {
if (!btn) return;
const down = () => {
if (!currentConfig.funJelly) return;
btn.classList.remove('jelly-pop');
btn.classList.add('pressed');
};
const up = () => {
btn.classList.remove('pressed');
if (!currentConfig.funJelly) return;
btn.classList.add('jelly-pop');
setTimeout(() => btn.classList.remove('jelly-pop'), 520);
};
const cancel = () => {
btn.classList.remove('pressed');
};
btn.addEventListener('mousedown', down);
btn.addEventListener('mouseup', up);
btn.addEventListener('mouseleave', cancel);
return { down, up, cancel };
},
// 拖拽粒子尾迹(快速甩面板时撒粒子)
emitParticles: function(x, y, count) {
if (!currentConfig.funParticles) return;
const layer = utils.ensureParticleLayer();
count = Math.max(1, Math.min(48, count || 0));
const colors = ['#1890ff', '#40a9ff', '#69c0ff', '#91d5ff', '#bae7ff'];
for (let i = 0; i < count; i++) {
const p = document.createElement('span');
p.className = 'uip';
const size = 4 + Math.random() * 8;
const angle = Math.random() * Math.PI * 2;
const dist = 30 + Math.random() * 80;
const dur = 0.5 + Math.random() * 0.5;
p.style.left = (x - size / 2) + 'px';
p.style.top = (y - size / 2) + 'px';
p.style.width = size + 'px';
p.style.height = size + 'px';
p.style.background = colors[(Math.random() * colors.length) | 0];
p.style.setProperty('--dx', (Math.cos(angle) * dist) + 'px');
p.style.setProperty('--dy', (Math.sin(angle) * dist) + 'px');
p.style.setProperty('--dur', dur + 's');
p.style.setProperty('--o', (0.6 + Math.random() * 0.4).toFixed(2));
layer.appendChild(p);
setTimeout(() => p.remove(), dur * 1000 + 100);
}
},
ensureParticleLayer: function() {
let layer = document.getElementById('ui-particle-layer');
if (!layer) {
layer = document.createElement('div');
layer.id = 'ui-particle-layer';
document.body.appendChild(layer);
}
return layer;
},
// 面板抛掷 + 撞墙回弹循环:松手后按末速度继续滑行/撞墙/回弹直到静止
launchPanelPhysics: function(panel, getVx, getVy) {
if (!currentConfig.funInertia) return;
if (panel.dataset.__physicsRunning === '1') return;
const vinit = Math.hypot(getVx(), getVy());
if (vinit < 40) return; // 太慢直接吸附位置,不玩物理
panel.dataset.__physicsRunning = '1';
const W = window.innerWidth, H = window.innerHeight;
let vx = getVx(), vy = getVy();
let fx = panel.offsetLeft, fy = panel.offsetTop;
const REST_SCALE = 0.22; // 每次撞墙速度保留系数
const FRICTION = 0.94; // 每帧空气摩擦,低速时快速停下
const SPEED_EPS = 40; // 低于此速度即停止(px/s)
let lastT = performance.now();
const step = (now) => {
// 用户在物理循环中重新按住拖动 → 交给拖拽逻辑接管
if (panel.dataset.__physicsRunning !== '1') return;
const dt = Math.min(0.032, (now - lastT) / 1000);
lastT = now;
const pw = panel.offsetWidth, ph = panel.offsetHeight;
// 记录反弹前速度,用于撞墙装惯性/碰撞点计算
const preVx = vx, preVy = vy;
fx += preVx * dt;
fy += preVy * dt;
panel.style.left = fx + 'px';
panel.style.top = fy + 'px';
panel.style.right = 'auto';
let hit = false, hitX = null, hitY = null, impactSpeed = Math.hypot(preVx, preVy);
if (fx <= 0 && preVx < 0) { fx = 0; vx = -preVx * REST_SCALE; hit = true; hitX = 0; hitY = fy + ph * 0.5; }
else if (fx + pw >= W && preVx > 0) { fx = W - pw; vx = -preVx * REST_SCALE; hit = true; hitX = W - pw; hitY = fy + ph * 0.5; }
else if (fx <= 0) { fx = 0; vx = 0; }
else if (fx + pw >= W) { fx = W - pw; vx = 0; }
if (fy <= 0 && preVy < 0) { fy = 0; vy = -preVy * REST_SCALE; hit = true; if (hitX === null) { hitX = fx + pw * 0.5; hitY = 0; } }
else if (fy + ph >= H && preVy > 0) { fy = H - ph; vy = -preVy * REST_SCALE; hit = true; if (hitX === null) { hitX = fx + pw * 0.5; hitY = H - ph; } }
else if (fy <= 0) { fy = 0; vy = 0; }
else if (fy + ph >= H) { fy = H - ph; vy = 0; }
// 撞墙粒子:撞击速度越快撒越多(100px/s 起撒,最多 48 粒)
if (hit && impactSpeed >= 100) {
const n = Math.min(48, Math.round((impactSpeed - 90) / 12));
if (n > 0) utils.emitParticles(hitX, hitY, n);
}
// 空气摩擦:防止低速时漂移过久
vx *= FRICTION;
vy *= FRICTION;
if (hit && Math.hypot(vx, vy) > SPEED_EPS) {
panel.style.left = fx + 'px';
panel.style.top = fy + 'px';
panel.classList.remove('squash');
void panel.offsetWidth; // 强制 reflow 重启动画
panel.classList.add('squash');
}
if (Math.hypot(vx, vy) < SPEED_EPS) {
panel.style.left = fx + 'px';
panel.style.top = fy + 'px';
panel.dataset.__physicsRunning = '';
panel.classList.remove('squash');
return;
}
requestAnimationFrame(step);
};
requestAnimationFrame(step);
},
isInteractiveEl: function(e) {
const el = e && e.target;
if (!el || !(el instanceof Element)) return false;
return !!el.closest('input, button, textarea, select, label, a, [data-tab], [data-goods]');
},
// 橡皮筋阻尼:超出边界后越拖阻力越大,位移渐进逼近软上限(真正的弹簧手感)
// 边界处 1:1 跟手,拖得越远增幅越小,最终饱和在 OVER 像素内;OVER=0 时硬边界(不可越界)
rubberBand: function(value, min, max) {
const OVER = Math.max(0, Number(currentConfig.tabRubberBand) || 0);
if (OVER === 0) return Math.min(max, Math.max(min, value));
if (value < min) return min - OVER * (1 - Math.exp(-(min - value) / OVER));
if (value > max) return max + OVER * (1 - Math.exp(-(value - max) / OVER));
return value;
},
// 弹簧软硬 K:auto 模式与 OVER 物理联动(软=远+慢,硬=近+快);manual 模式读独立滑条
springK: function() {
if (currentConfig.tabSpringMode === 'manual') {
return Math.max(0.02, Math.min(1, Number(currentConfig.tabSpringK) || 0.25));
}
const OVER = Math.max(0, Number(currentConfig.tabRubberBand) || 0);
return 1 / (1 + OVER / 120);
},
// 弹簧跟随器:模拟「恒定拉力 + 理想弹簧 + 粘性阻尼」——位移朝目标逐帧逼近,
// 剩余位移 e 指数衰减(越来越短),最终停在目标(= 力平衡点),不再线性跟手。
// applyScore: 每帧把当前显示位移写回 DOM(如 indicator.style.left)
createSpringFollower: function(applyScore) {
const EPS = 0.35; // 收敛阈值(px),小于该值直接吸附到目标
let target = null, value = null, rafId = null;
const loop = () => {
rafId = null;
const diff = target - value;
const K = utils.springK(); // 每帧实时读取(滑条可动态调)
if (Math.abs(diff) < EPS) {
value = target; // 收敛:精确归位
} else {
value += diff * K; // 剩余位移按比例衰减(指数逼近,恒定拉力+阻尼的解)
}
applyScore(value);
if (value !== target) rafId = requestAnimationFrame(loop);
};
return {
reset: function (v) {
if (rafId !== null) { cancelAnimationFrame(rafId); rafId = null; }
target = value = v;
},
seek: function (t) {
target = t;
if (rafId === null) rafId = requestAnimationFrame(loop);
},
stop: function () {
if (rafId !== null) { cancelAnimationFrame(rafId); rafId = null; }
}
};
}
};
// ============================ 日志系统 ============================
const Logger = {
MAX_ENTRIES: 100,
buffer: [],
add: function(type, message, detail) {
const entry = {
time: new Date().toLocaleTimeString(),
type: type, // 'info' | 'success' | 'error' | 'ai' | 'milestone'
message: message,
detail: detail || null // 详细模式下才展示的附加内容
};
this.buffer.push(entry);
if (this.buffer.length > this.MAX_ENTRIES) {
this.buffer.shift(); // 丢弃最旧的
}
// 同步刷到答题面板的日志文本框(AnswerWindow 尚未初始化时静默跳过,防 TDZ)
try { AnswerWindow.pushLog(); } catch (e) { /* 启动早期还没建窗口 */ }
// 同时输出到控制台(debug模式)
if (currentConfig.debugMode) {
const prefix = { ai: '🤖', milestone: '◆', success: '✅', error: '❌', info: 'ℹ️' }[type] || '·';
console.log(`[LOG ${entry.time}] ${prefix} ${message}`, detail || '');
}
},
// 里程碑记录(精简模式下显示)
milestone: function(msg) { this.add('milestone', msg); },
// AI对话记录(详细模式下显示)
ai: function(msg, detail) { this.add('ai', msg, detail); },
// 获取日志文本
getText: function() {
if (this.buffer.length === 0) return '暂无日志';
return this.buffer.map(e => {
const prefix = { ai: '[AI]', milestone: '[·]', success: '[✓]', error: '[✗]', info: '[i]' }[e.type] || '[·]';
let line = `${e.time} ${prefix} ${e.message}`;
if (currentConfig.logDetail && e.detail) {
line += '\n' + e.detail.split('\n').map(l => ' ' + l).join('\n');
}
return line;
}).join('\n');
},
clear: function() { this.buffer = []; }
};
const AccountGuard = {
account: '',
resetting: false,
check: function() {
if (this.resetting) return true;
const current = String(AuthService.getCurrentAccountId() || '').trim();
if (!current) return false;
const previous = String(GM_getValue('scriptAccountId', '') || '');
if (previous && previous !== current) {
this.resetting = true;
GM_listValues().forEach(key => GM_deleteValue(key));
GM_setValue('scriptAccountId', current);
location.reload();
return true;
}
if (this.account && this.account !== current) {
this.resetting = true; // 另一标签页已重置存储,本页仍需丢弃旧账号的内存状态。
location.reload();
return true;
}
if (!previous) GM_setValue('scriptAccountId', current);
this.account = current;
return false;
}
};
// ============================ 授权服务(卡密验证/答题代理) ============================
const AuthService = {
// 从页面提取当前登录账号标识(学号):localStorage 的 pro__Login_Userinfo
getCurrentAccountId: function() {
try {
const raw = localStorage.getItem('pro__Login_Userinfo');
if (raw) {
const parsed = JSON.parse(raw);
const info = (parsed && parsed.value) || parsed;
return info.username || info.workNo || info.id || '';
}
} catch (e) {}
return '';
},
// 设备指纹(本地持久化,激活时携带)
getDeviceFp: function() {
let fp = GM_getValue('deviceFp', '');
if (!fp) {
fp = 'dev-' + Math.random().toString(36).slice(2, 10);
GM_setValue('deviceFp', fp);
}
return fp;
},
getCachedStatus: function() {
try { return JSON.parse(currentConfig.authStatus) || null; } catch (e) { return null; }
},
setCachedStatus: function(status) {
currentConfig.authStatus = JSON.stringify(status || {});
GM_setValue('authStatus', currentConfig.authStatus);
if (ControlPanel.updateAnswerAccess) ControlPanel.updateAnswerAccess();
},
// 【2.8.3】当前登录账号 vs 卡密绑定账号 是否不一致。
// 为什么需要:本地缓存的 cardKey / authStatus 是按浏览器持久化的,不含账号维度;
// 换账号登录后刷新,面板仍会显示上一个账号那张卡的「已激活 + 余额」,
// 而服务端 /api/answer、/api/activate 是按「卡密绑定账号」校验的,
// 于是直接回 ACCOUNT_MISMATCH「该卡密已绑定其他账号」——用户看到的就是这句莫名提示。
// 这里提前在客户端判定,把「卡密是别人的」讲清楚。
// 返回 null 表示无冲突或信息不足(额度型、缓存无 account_id、未取到当前账号)。
accountMismatch: function() {
const st = this.getCachedStatus();
if (!st || !st.card_key || st.card_key !== currentConfig.cardKey.trim()) return null;
if (st.type !== 'bind') return null;
const cached = String(st.account_id == null ? '' : st.account_id).trim(); // 卡密绑定账号
const current = String(this.getCurrentAccountId() || '').trim(); // 页面当前登录账号
if (!cached || !current || cached === current) return null;
return { cached: cached, current: current };
},
billingScope: async function(graphId) {
const bytes = new TextEncoder().encode(JSON.stringify([currentConfig.cardKey.trim(), this.getCurrentAccountId(), String(graphId)]));
const digest = await crypto.subtle.digest('SHA-256', bytes);
return Array.from(new Uint8Array(digest), b => b.toString(16).padStart(2, '0')).join('');
},
// 本地缓存是否还有余额(用于区分「余额不足」与「上游失效」)
hasBalance: function() {
const st = this.getCachedStatus();
if (!st) return false;
const b = st.balance_cent;
return typeof b === 'number' && b > 0;
},
// 上游类失败错误码:服务端侧问题(上游未配置/禁用/调用失败),与用户余额无关
isUpstreamFailure: function(code) {
return code === 'UPSTREAM_ERROR' || code === 'UPSTREAM_DISABLED' || code === 'SERVER_NOT_CONFIGURED';
},
cardFailure: function(code, message) {
const titles={INSUFFICIENT_BALANCE:'卡密余额不足',CARD_NOT_FOUND:'卡密不存在或已移除',CARD_DISABLED:'卡密已禁用',CARD_EXPIRED:'卡密已过期',ACCOUNT_MISMATCH:'卡密已绑定其他账号',CARD_NOT_ACTIVATED:'卡密尚未激活',CARD_REQUIRED:'请先填写卡密',ACCOUNT_REQUIRED:'尚未取得当前账号'};
if (!titles[code]) return false;
if (!this.cardFailureNotice || !this.cardFailureNotice.isConnected) {
this.cardFailureNotice=utils.showBigNotice(titles[code], (message||'授权校验未通过。')+'\n请在授权页激活有效卡密,或点击“查看余额”;已获取答案保留。', 'error');
}
return true;
},
// POST 封装(GM_xmlhttpRequest,绕过 CORS)
request: function(path, body, timeout = 15000) {
return new Promise((resolve) => {
GM_xmlhttpRequest({
method: 'POST',
url: currentConfig.authServerUrl.replace(/\/+$/, '') + path,
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify(body),
timeout,
onload: (res) => {
try {
const data=JSON.parse(res.responseText);
if (!data.success && path.startsWith('/api/answer') && body.card_key===currentConfig.cardKey.trim() && this.cardFailure(data.code,data.msg)) {
if (ExamBatchProcessor.running) ExamBatchProcessor.stopForInsufficientBalance(data.msg,data.code);
}
resolve(data);
}
catch (e) { resolve({ success: false, code: 'BAD_RESPONSE', msg: '服务响应解析失败' }); }
},
onerror: () => resolve({ success: false, code: 'NETWORK_ERROR', msg: '无法连接授权服务,请检查服务器地址' }),
// 【2.5.9】超时不再并入 NETWORK_ERROR:单独标 TIMEOUT 并带上等待秒数,
// 这样它就不会被当成"可重试的网络抖动"原样重发同一批(最坏白等 216 秒)
ontimeout: () => resolve({ success: false, code: 'TIMEOUT', msg: `授权服务超时(等待 ${Math.round(timeout / 1000)} 秒无响应)` })
});
});
},
// 激活卡密
activate: async function() {
const cardKey = currentConfig.cardKey.trim();
if (!cardKey) { utils.showMessage('请先填入卡密', 'warning'); return false; }
const accountId = this.getCurrentAccountId();
utils.showMessage('正在激活卡密...', 'info');
const res = await this.request('/api/activate', {
card_key: cardKey, account_id: accountId, device_fp: this.getDeviceFp()
});
if (currentConfig.cardKey.trim() !== cardKey) return false;
if (res.success) {
this.setCachedStatus(res.data);
ExamBatchProcessor.recoverAuthorization();
Logger.milestone(`卡密激活成功:类型=${res.data.type} 余额=${res.data.balance_cent}分`);
utils.showMessage('✅ 卡密激活成功', 'success');
return true;
} else {
this.cardFailure(res.code, res.msg);
utils.showMessage('激活失败:' + res.msg, 'error');
Logger.add('error', '卡密激活失败', res.code + ' - ' + res.msg);
return false;
}
},
// 实时刷新卡密状态
refreshStatus: async function() {
const cardKey = currentConfig.cardKey.trim();
if (!cardKey) return null;
if (authStatusRequest && authStatusRequest.cardKey===cardKey) return authStatusRequest;
const request=this.request('/api/status',{card_key:cardKey}).then(res=>{
if(currentConfig.cardKey.trim()!==cardKey)return null;
if(res.success){this.setCachedStatus(res.data);ExamBatchProcessor.recoverAuthorization();return res.data;}
this.cardFailure(res.code,res.msg);return null;
}).finally(()=>{if(authStatusRequest===request)authStatusRequest=null;});
request.cardKey=cardKey;authStatusRequest=request;return request;
},
// 答题前只使用本地状态预检;/api/answer 仍会执行最终授权和余额校验。
ensureReady: function(paid = false) {
const result=this.checkReady(paid);
if(!result.ok){
const code=result.code||(/余额|额度不足/.test(result.error)?'INSUFFICIENT_BALANCE':/过期/.test(result.error)?'CARD_EXPIRED':/不一致/.test(result.error)?'ACCOUNT_MISMATCH':!currentConfig.cardKey.trim()?'CARD_REQUIRED':'CARD_NOT_ACTIVATED');
result.code=code;this.cardFailure(code,result.error);
}
return result;
},
checkReady: function(paid = false) {
if (AccountGuard.check() || !this.getCurrentAccountId()) return { ok: false, error: '账号变化或尚未加载,请等待页面重新加载' };
const cardKey = currentConfig.cardKey.trim();
if (!cardKey) return { ok: false, error: '未激活卡密:请在面板填入并激活授权卡密' };
let st = this.getCachedStatus();
if (!st || !st.card_key || st.card_key !== cardKey) {
return { ok: false, error: '请先激活卡密,或点击“查看余额”同步已有卡密' };
}
if (st.status !== 'bound') return { ok:false,code:st.status==='disabled'?'CARD_DISABLED':'CARD_NOT_ACTIVATED',error:st.status==='disabled'?'卡密已被禁用,请更换有效卡密':'请先激活卡密' };
// 【2.8.3】先查账号一致性:缓存里那张卡是别的账号绑定的,就地拦住,
// 不发请求(否则服务端只会回一句「该卡密已绑定其他账号」,用户看不懂)。
const mm = this.accountMismatch();
if (mm) {
return { ok: false, code: 'ACCOUNT_MISMATCH', error: `卡密已绑定其他账号(${mm.cached}):请登录该账号,或换用当前账号的卡密` };
}
// 有效期检查:bind 与 quota 通用。quota 自 2026-10-13 起也有时限(服务端首次激活时定格,
// 默认 90 天≈3 个月);未激活过的卡 expires_at 为 null,即不限期,照常放行。
if (st.expires_at && new Date(String(st.expires_at).replace(' ', 'T')) < new Date()) {
return { ok: false, error: '卡密已过期,请续费' };
}
if (!paid && st.type === 'bind') {
// 统一额度模型:bind 也有余额,扣完即停
if (st.balance_cent == null || st.balance_cent <= 0) {
return { ok: false, code: 'INSUFFICIENT_BALANCE', error: '额度不足:余额已用完,请购买新卡密' };
}
} else if (!paid && st.balance_cent <= 0) {
return { ok: false, code: 'INSUFFICIENT_BALANCE', error: '本地余额不足;如已充值,请点击“查看余额”同步额度' };
}
return { ok: true, status: st };
},
// 答题代理:messages 已构建好,发到服务端调用 AI 并扣费
// 【2.5.9】timeout 参数化:考试批量路径传「等待超时」滑块值,其余路径沿用原 70 秒
answer: async function(messages, timeout = AUTH_ANSWER_TIMEOUT_MS) {
return this.request('/api/answer', {
card_key: currentConfig.cardKey.trim(),
account_id: this.getCurrentAccountId(),
messages: messages,
model: currentConfig.deepseekModel
}, timeout);
},
// 【3.0】批量题库答题:一次把本课全部题发过去,服务端负责查库/入库/未命中调 AI。
// 返回 { answers:[{seq,answer,source}], balance_cent, cost_cent, lib_hits, asked_ai }
answerBatch: async function(graphId, questions, timeout = AUTH_BATCH_TIMEOUT_MS, exam = false) {
return this.request(exam ? '/api/answer/exam' : '/api/answer', {
card_key: currentConfig.cardKey.trim(),
account_id: this.getCurrentAccountId(),
model: currentConfig.deepseekModel,
graph_id: String(graphId || ''),
questions: questions
}, timeout);
},
// 【3.0】上报平台参考答案(错题采集产出)→ 服务端题库 corrected。
// 服务端不调 AI、不扣费,只校验卡密有效性;失败静默,不影响本地采集结果。
reportQuestionBank: async function(graphId, items, timeout = AUTH_BATCH_TIMEOUT_MS) {
return this.request('/api/qbank/report', {
card_key: currentConfig.cardKey.trim(),
account_id: this.getCurrentAccountId(),
graph_id: String(graphId || ''),
items: items
}, timeout);
},
// 联系开发者:弹出留言框,提交到 /api/feedback(服务端推 Termux 通知到 Pad)
openFeedbackModal: function() {
const overlay = document.createElement('div');
overlay.id = 'feedback-overlay';
const box = document.createElement('div');
box.className = 'feedback-modal' + (currentConfig.glassBlur ? ' panel-glass' : '');
box.innerHTML = `
💬 联系开发者
遇到问题(如「上游算力用尽」)可以直接留言,开发者会尽快处理。服务端一般几分钟内就能收到通知。
每个卡密每天最多留言 5 条,超出请明天再试
`;
overlay.appendChild(box);
document.body.appendChild(overlay);
// esc 关闭 / 点遮罩关闭
const close = () => overlay.remove();
const onKey = (e) => { if (e.key === 'Escape') close(); };
document.addEventListener('keydown', onKey);
overlay.addEventListener('click', (e) => { if (e.target === overlay) close(); });
box.querySelector('#fb-close').addEventListener('click', close);
// 发送:需已激活卡密(服务端也会强制校验+每日限流);成功不关弹窗
box.querySelector('#fb-send').addEventListener('click', async () => {
const content = box.querySelector('#fb-content').value.trim();
const msgEl = box.querySelector('#fb-msg');
if (!currentConfig.cardKey.trim()) {
msgEl.textContent = '请先填入并激活授权卡密,再联系开发者(防滥用)';
msgEl.style.color = '#ff4d4f';
return;
}
if (!content) { msgEl.textContent = '请先填写留言内容'; msgEl.style.color = '#ff4d4f'; return; }
msgEl.textContent = '发送中...'; msgEl.style.color = '#999';
const res = await AuthService.request('/api/feedback', {
name: '', contact: box.querySelector('#fb-contact').value.trim(),
content: content, card_key: currentConfig.cardKey.trim()
});
if (res && res.success) {
msgEl.textContent = '✅ 留言已提交,开发者会尽快处理'; msgEl.style.color = '#52c41a';
box.querySelector('#fb-content').value = '';
box.querySelector('#fb-contact').value = '';
} else {
msgEl.textContent = '❌ 提交失败:' + ((res && res.msg) || '请检查服务器连接'); msgEl.style.color = '#ff4d4f';
}
});
}
};
// ============================ DeepSeek API模块 ============================
const DeepSeekService = {
// 提示词注入审核:检测常见越狱/指令注入模式,返回命中的风险名称列表
checkInjection: function(text) {
if (!text) return [];
const patterns = [
{ re: /忽略\s*(?:上面|以上|之前|前面|前述|此前)?\s*(?:的)?\s*(?:指令|提示|要求|内容|规则|设定|所有)/, name: '忽略指令注入' },
{ re: /ignore\s+(?:previous|all|above|prior|everything|instructions)/i, name: '忽略指令注入(英文)' },
{ re: /忘记\s*(?:之前|上面|以上|所有)\s*(?:的)?\s*(?:指令|设定|规则|提示)/, name: '忘记指令注入' },
{ re: /你\s*(?:现在|开始|被)?\s*(?:要|是)?\s*(?:帮我)?\s*(?:扮演|当成|装作|假装)/, name: '角色伪装注入' },
{ re: /jailbreak|developer mode|dev mode|DAN/i, name: '越狱关键词' },
{ re: /system\s*prompt/i, name: '系统提示词探询' },
{ re: /重新\s*(?:编写|生成|设置|设计)\s*(?:你)?\s*(?:的)?\s*(?:指令|提示词|规则)/i, name: '重写指令注入' },
{ re: /─{10,}|━━{3,}/, name: '伪装分隔符' },
];
return patterns.filter(p => p.re.test(text)).map(p => p.name);
},
getAnswerFromDeepSeek: async function(question, options, questionType, hintData) {
const systemPrompt = this.buildSystemPrompt(questionType);
const userPrompt = this.buildUserPrompt(question, options, questionType);
// 提示词审核:检测注入风险,命中则阻止发送并提示
const injection = this.checkInjection(systemPrompt + '\n' + userPrompt);
if (injection.length > 0) {
Logger.milestone(`⚠️ 检测到提示词注入风险(${injection.join('、')}),已阻止本次AI调用`);
utils.showMessage(`⚠️ 检测到提示词注入风险(${injection.join('、')}),已阻止AI调用`, 'warning');
return [];
}
// 授权校验(卡密)
const ready = await AuthService.ensureReady();
if (!ready.ok) {
utils.showMessage(ready.error, 'warning');
Logger.add('error', '授权校验未通过', ready.error);
return [];
}
Logger.ai('调用AI(代理)', 'System: ' + systemPrompt + '\nUser: ' + userPrompt);
const res = await AuthService.answer([
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
]);
if (!res.success) {
// 服务端是余额最终来源;拒绝后更新本地显示,不额外触发状态请求。
if (res.code === 'INSUFFICIENT_BALANCE') {
const cached = AuthService.getCachedStatus();
if (cached) { cached.balance_cent = 0; AuthService.setCachedStatus(cached); }
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
utils.showMessage(res.msg, 'error');
} else if (AuthService.isUpstreamFailure(res.code) && AuthService.hasBalance()) {
// 上游失效/未配置/禁用(服务端问题,非用户余额问题)
utils.showMessage('上游算力用尽,请联系开发者', 'error');
} else {
utils.showMessage('AI请求失败:' + res.msg, 'error');
}
Logger.add('error', 'AI代理请求失败', res.code + ' - ' + res.msg);
return [];
}
try {
const raw = (res.data && res.data.content || '').trim();
const answer = this.parseAIResponse(raw, questionType, options);
Logger.ai('AI响应(代理)', '原始: ' + raw + '\n解析: ' + JSON.stringify(answer));
// 同步本地缓存的余额,并实时刷新主页面「授权」余额显示
if (res.data && res.data.balance_cent !== undefined) {
const cached = AuthService.getCachedStatus();
if (cached) { cached.balance_cent = res.data.balance_cent; AuthService.setCachedStatus(cached); }
}
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
return answer;
} catch (e) {
Logger.add('error', 'AI解析失败', e.message);
return [];
}
},
refreshAuthStatus: async function() {
if (!currentConfig.cardKey.trim()) { utils.showMessage('请先填入卡密', 'warning'); return false; }
utils.showMessage('正在刷新授权状态...', 'info');
const status = await AuthService.refreshStatus();
if (status) {
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
const power = status.power != null ? status.power : (status.balance_cent || 0);
const est = status.est_questions != null ? status.est_questions : '';
utils.showMessage(`授权状态已刷新(${status.type === 'bind' ? '绑定账号型' : '额度型'},算力 ${power} 分${est !== '' ? ' · 约 ' + est + ' 道' : ''})`, 'success');
return true;
} else {
utils.showMessage('刷新授权状态失败,请检查网络或卡密', 'error');
return false;
}
},
testPrompt: async function(question, options, questionType) {
// 用当前生效的提示词实际调用AI一次,返回完整 prompt 与原始回复
if (!currentConfig.cardKey.trim()) { utils.showMessage('请先填入并激活卡密', 'warning'); return null; }
const systemPrompt = this.buildSystemPrompt(questionType);
const userPrompt = this.buildUserPrompt(question, options, questionType);
// 提示词审核:命中注入则拦截,不发请求
const injection = this.checkInjection(systemPrompt + '\n' + userPrompt);
if (injection.length > 0) {
Logger.milestone(`⚠️ 提示词测试:检测到注入风险(${injection.join('、')}),未发送`);
return { systemPrompt, userPrompt, raw: `⚠️ 已拦截:检测到提示词注入风险(${injection.join('、')})`, status: 'blocked' };
}
const res = await AuthService.answer([
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
]);
if (!res.success) {
// 有余额但上游全部失效:raw 直接显示修正文案(开发面板 AI 回复框可读)
const msg = (AuthService.isUpstreamFailure(res.code) && AuthService.hasBalance())
? '上游算力用尽,请联系开发者'
: res.msg;
return { systemPrompt, userPrompt, raw: msg, status: res.code };
}
const raw = (res.data && res.data.content || '').trim();
Logger.ai('提示词测试', 'System: ' + systemPrompt + '\nUser: ' + userPrompt + '\nAI回复: ' + raw);
// 同步余额缓存 + 刷新主页面授权余额显示(测试也会扣费)
if (res.data && res.data.balance_cent !== undefined) {
const cached = AuthService.getCachedStatus();
if (cached) { cached.balance_cent = res.data.balance_cent; AuthService.setCachedStatus(cached); }
}
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
return { systemPrompt, userPrompt, raw, status: 'ok' };
},
buildSystemPrompt: function(questionType) {
const defaults = {
'judgment': '你是实验室安全课程专家,判断以下陈述是否正确,仅回答"正确"或"错误",不要解释。',
'single': '你是实验室安全课程专家,回答以下单选题,仅返回选项字母(如A、B),不要解释。',
'multiple': '你是实验室安全课程专家,回答以下多选题,返回所有正确选项字母(如A,B,C),不要解释。',
'default': '你是实验室安全课程专家,准确回答以下问题,直接给出答案。'
};
// 复习模式:禁止自定义提示词,强制用题型默认(避免与错题数据注入冲突)
if (currentConfig.reviewMode) {
return defaults[questionType] || defaults['default'];
}
// 统一自定义提示词:填了所有题型都用它,否则按题型用默认
const custom = currentConfig.customPrompt;
return (custom && custom.trim()) ? custom.trim() : (defaults[questionType] || defaults['default']);
},
buildUserPrompt: function(question, options, questionType, hintData) {
let prompt = '';
// 用户自定义 User 提示词(可选):复习模式下禁用(避免与错题注入冲突)
if (!currentConfig.reviewMode && currentConfig.customUserPrompt && currentConfig.customUserPrompt.trim()) {
prompt += currentConfig.customUserPrompt.trim() + '\n\n';
}
prompt += `题目:${question}\n`;
if (options && options.length > 0) {
prompt += '选项:\n';
options.forEach((opt, idx) => prompt += `${String.fromCharCode(65 + idx)}. ${opt}\n`);
}
return prompt + '\n请直接给出答案:';
},
parseAIResponse: function(aiResponse, questionType, options) {
if (!aiResponse) return [];
aiResponse = aiResponse.trim();
if (questionType === 'judgment') {
if (aiResponse.includes('正确') || aiResponse.includes('对') || aiResponse === 'A') return ['正确'];
if (aiResponse.includes('错误') || aiResponse.includes('错') || aiResponse === 'B') return ['错误'];
}
if (questionType === 'single') {
const match = aiResponse.match(/[A-D]/);
if (match && options && options.length > 0) {
const index = match[0].charCodeAt(0) - 65;
if (index >= 0 && index < options.length) return [options[index]];
}
return [aiResponse];
}
if (questionType === 'multiple') {
let answers = [];
const matches = aiResponse.match(/[A-D]/g);
if (matches) {
matches.forEach(letter => {
const index = letter.charCodeAt(0) - 65;
if (index >= 0 && index < options.length && !answers.includes(options[index])) answers.push(options[index]);
});
}
return answers.length > 0 ? answers : [aiResponse];
}
return [aiResponse];
}
};
// ============================ 商品介绍数据(与酷发卡上架档位对应) ============================
// 注意:这里**不再存 buyUrl** —— 购买链接由 ShopConfig.linkFor(key) 热加载提供(见文件头
// SHOP_FALLBACK / /api/shop-config),换发卡站不必改源码。
const GOODS_INTRO = [
{
key: 'trial', shortName: '尝鲜款', name: '尝鲜款 · 绑定型',
badge: '绑定账号型', type: '绑定账号型(一人一码)',
price: '¥0.50', power: '80 算力', questions: '约 42 道',
validity: '10 天(激活起算)', unitCost: '≈0.012 元/道',
fit: '最低门槛体验:先花小钱试水完整 AI 功能',
desc: '激活时绑定当前登录账号,卡密专属该账号使用,不可更换。适合想低成本体验 AI 自动答题 / 自动播放效果,确认可用后再买账号型。'
},
{
key: 'account', shortName: '账号型', name: '账号型 · 绑定型',
badge: '绑定账号型', type: '绑定账号型(一人一码)',
price: '¥5.00', power: '1420 算力', questions: '约 747 道',
validity: '10 天(激活起算)', unitCost: '≈0.007 元/道',
fit: '单账号 10 天内把课程与考试一次刷完',
desc: '绑定当前登录账号,一人一码。1420 算力约可答 747 道,覆盖单个账号完整的课程 + 考试量,10 天有效期;单价成本最低,买一份基本够一个号刷完。'
}
];
// ============================ UI面板构建与交互 ============================
const ControlPanel = {
powerView: 'ball', // 算力显示模式:'ball' 余额 / 'total' 总量,点击切换
createPanel: function() {
if (document.getElementById('ai-helper-panel')) return;
const panel = document.createElement('div');
panel.id = 'ai-helper-panel';
// 商品介绍:子 tab 数量由 GOODS_INTRO 决定(当前 2 档:尝鲜 / 账号型),数据驱动渲染
const introSubTabsHtml = GOODS_INTRO.map(g =>
``
).join('');
const introSubContentsHtml = GOODS_INTRO.map(g => `
${g.badge}
| 卡密类型 | ${g.type} |
| 算力额度 | ${g.power} |
| 约可答题 | ${g.questions} |
| 有效期 | ${g.validity} |
| 单题成本 | ${g.unitCost} |
🎯 ${g.fit}
${g.desc}
`).join('');
panel.innerHTML = `
实安课程 · v${SCRIPT_INFO.version}
未激活
● 已抓取● 待抓取
未开始
● 题库● AI● 失败● 待答
算力按 AI 的 token 消耗计费(模型的思考过程不计费),提示词越长或错题参考数据越多,单次消耗会相应增加。面板显示的是本地缓存快照,不是实时值;要同步最新余额请点「查看余额」(只查询、不扣费)
价格已下调(2026-11-14 起):尝鲜款降至 ¥0.50(80 算力,约 42 道),账号型维持 ¥5.00(1420 算力,约 747 道,原价 ¥10.00 五折)。
题库在持续自增长——同一道题被答过一次后,后续再遇到可直接从题库取答案,不必再调一次大模型,
AI 调用成本随之下降,这部分省下来的钱直接让给用户。
价格主要覆盖以下几块成本:
· AI 模型调用费:每一次答题都真实调用大模型 API,按 token 消耗计费,这是最大头(题库命中越多,这部分越低);
· 中转 + 服务器 + 域名费:免去自己配置 API Key 的麻烦,卡密校验、答案代理、额度结算都跑在独立服务器上,填卡密即可直接调用 AI,含带宽与域名续费;
· 脚本开发投入:脚本诞生过程中开发调试、功能联调产生了大量真实 AI 调用,这部分成本也分摊在了价格里。
按实际消耗扣算力:用多少、扣多少。
`;
document.body.appendChild(panel);
const examAdvanced = document.createElement('div');
examAdvanced.id = 'exam-advanced-controls';
examAdvanced.hidden = true;
examAdvanced.innerHTML = `
`;
panel.appendChild(examAdvanced);
// 高级UI(默认关=白色面板;开=毛玻璃+物理效果)
if (currentConfig.glassBlur) panel.classList.add('panel-glass');
// Tab 切换动画
if (currentConfig.tabAnimEnabled) panel.classList.add('tab-anim');
this.bindEvents(panel);
// 售卖链接热加载:上面的 HTML 已按「本地缓存 / 内置兜底」渲染出可用链接,
// 这里再拉一次远程配置,拿到后原地刷新按钮(失败静默保持兜底,不打扰用户)
ShopConfig.load();
},
bindEvents: function(panel) {
const highlight = panel.querySelector('#panel-highlight');
const toggleBtn = panel.querySelector('#panel-toggle');
// 水球模式核心光球(CSS .water-ball 时显示)
let waterCore = panel.querySelector('.water-ball-core');
if (!waterCore) {
waterCore = document.createElement('div');
waterCore.className = 'water-ball-core';
waterCore.textContent = '💧';
panel.appendChild(waterCore);
}
// 折叠逻辑:mini 态改为真实 50px 圆形,避免缩放后保留椭圆外框。
const togglePanel = () => {
const willMini = !panel.classList.contains('mini');
if (willMini) {
// 方案B:3D 高光已作用在内容视图 tabView;收起前清楚残留倾斜,面板本体由 CSS .mini transform:none 兜底
tabView.style.transform = '';
panel.classList.add('mini');
toggleBtn.textContent = '✨';
highlight.style.opacity = '0';
// mini 态 mousemove 高光已禁用;若面板本体仍有残留 inline,rAF 兜底清空
requestAnimationFrame(() => { if (panel.classList.contains('mini')) panel.style.transform = ''; });
} else {
// 展开:移除 mini class,恢复正常面板尺寸。
panel.classList.remove('mini');
toggleBtn.textContent = '收起';
// 收起时窄宽度会把内容撑高;展开后清掉旧高度并按正常宽度重测。
const refreshExpandedHeight = () => {
const tabView = panel.querySelector('.panel-tab-view');
const activeTab = panel.querySelector('.panel-tab.active');
if (tabView) tabView.style.height = '';
if (activeTab) switchTab(activeTab.dataset.tab);
};
// 宽高过渡约 350ms,等过渡结束后再测量,避免按 50px 窄宽度计算。
setTimeout(refreshExpandedHeight, 400);
}
};
toggleBtn.addEventListener('click', e => { e.stopPropagation(); if (!dragMoved) togglePanel(); });
panel.addEventListener('click', () => { if (panel.classList.contains('mini') && !dragMoved) togglePanel(); });
// ===== 果冻按钮:面板内所有 button 欠阻尼按压回弹 =====
panel.querySelectorAll('button').forEach(b => utils.jellyPress(b));
// ===== 彩蛋:长按标题栏 880ms 进入水球模式;水球态长按面板退出 =====
(function(){
const head = panel.querySelector('.head');
if (!head) return;
let wbTimer = null;
// 按下启动计时;弹起取消(仅当计时尚未触发);触发后切换一次
const wbArm = (e) => {
if (!currentConfig.funWaterBall) return;
if (panel.classList.contains('mini')) return;
const isWB = panel.classList.contains('water-ball');
if (!isWB) {
// 进入:必须按在标题栏上
if (e.target !== head && !head.contains(e.target)) return;
} else {
// 退出:不能按在交互元素上
if (utils.isInteractiveEl(e)) return;
}
if (wbTimer) { clearTimeout(wbTimer); wbTimer = null; }
wbTimer = setTimeout(() => {
wbTimer = null;
if (!currentConfig.funWaterBall) return;
panel.classList.toggle('water-ball');
utils.log('💧 水球模式:' + (panel.classList.contains('water-ball') ? '开(长按水球退出)' : '关'));
}, 880);
};
const wbDisarm = () => {
if (wbTimer) { clearTimeout(wbTimer); wbTimer = null; }
};
head.addEventListener('mousedown', wbArm);
panel.addEventListener('mousedown', wbArm);
// 弹起/移出都打断未完成的长按;若计时已触发(timer=null)则不影响
document.addEventListener('mouseup', wbDisarm);
panel.addEventListener('mouseleave', wbDisarm);
})();
// 内容包装(carousel 两层:固定视口 + 平移 track)
const tabView = document.createElement('div');
tabView.className = 'panel-tab-view';
const tabTrack = document.createElement('div');
tabTrack.className = 'panel-tab-track';
panel.querySelectorAll('.panel-tab-content').forEach(c => { c.style.display = 'block'; tabTrack.appendChild(c); });
tabView.appendChild(tabTrack);
panel.querySelector('.panel-tabs').after(tabView);
const depthLayer = document.createElement('div');
depthLayer.className = 'panel-depth-layer';
const navigation = panel.querySelector('.panel-tabs');
navigation.before(depthLayer);
depthLayer.append(navigation, tabView);
// tab 栏切换(胶囊滑块跟随激活 tab)
const tabBtns = panel.querySelectorAll('.panel-tab');
const tabIndicator = panel.querySelector('.panel-tab-indicator');
const updateTabIndicator = () => {
const active = panel.querySelector('.panel-tab.active');
if (!tabIndicator || !active) return;
tabIndicator.style.left = active.offsetLeft + 'px';
tabIndicator.style.width = active.offsetWidth + 'px';
};
const switchTab = (name) => {
const curBtn = panel.querySelector('.panel-tab[data-tab="' + name + '"]');
const curIdx = curBtn ? Array.from(tabBtns).indexOf(curBtn) : 0;
tabBtns.forEach(t => t.classList.toggle('active', t.dataset.tab === name));
if (tabTrack && tabView) {
tabTrack.style.transform = 'translateX(' + (-curIdx * 100) + '%)';
const content = panel.querySelector('#tab-' + name);
if (content) tabView.style.height = content.offsetHeight + 'px';
}
updateTabIndicator();
// 【2.5.20】进考试页签就重算一次提交槽位:按钮可用性以「卷面有没有答案」为准,
// 而卷面可能在面板开着期间变化(自己在页面上作答 / 清过数据),不能只在初始化时算一次
if (name === 'exam') {
try { ExamBatchProcessor.syncSubmitUI(); } catch (error) { /* 面板初始化不该被它拖垮 */ }
}
};
let justDragged = false;
tabBtns.forEach(t => t.addEventListener('click', () => {
if (justDragged) { justDragged = false; return; }
switchTab(t.dataset.tab);
}));
switchTab('auth');
// 按当前页内容定高,避免被相邻长页撑出空白;异步状态更新后同步高度。
const contentResize = new ResizeObserver(() => {
if (panel.classList.contains('mini')) return;
const active = panel.querySelector('.panel-tab.active');
if (active) switchTab(active.dataset.tab);
updateIntroIndicator();
});
panel.querySelectorAll('.panel-tab-content').forEach(content => contentResize.observe(content));
// 介绍子 tab:胶囊 indicator + 内容 carousel 平移 + 拖动吸附(对齐主 tab 交互)
const introBtns = panel.querySelectorAll('.intro-sub-tab');
const introIndicator = panel.querySelector('.intro-indicator');
const introTrack = panel.querySelector('.intro-sub-track');
const introView = panel.querySelector('.intro-sub-view');
const updateIntroIndicator = () => {
const active = panel.querySelector('.intro-sub-tab.active');
if (!introIndicator || !active) return;
introIndicator.style.left = active.offsetLeft + 'px';
introIndicator.style.width = active.offsetWidth + 'px';
};
const switchIntroTab = (key) => {
const curBtn = panel.querySelector('.intro-sub-tab[data-goods="' + key + '"]');
const curIdx = curBtn ? Array.from(introBtns).indexOf(curBtn) : 0;
introBtns.forEach(b => b.classList.toggle('active', b.dataset.goods === key));
if (introTrack && introView) {
introTrack.style.transform = 'translateX(' + (-curIdx * 100) + '%)';
}
updateIntroIndicator();
};
let justDraggedIntro = false;
introBtns.forEach(btn => {
btn.addEventListener('click', () => {
if (justDraggedIntro) { justDraggedIntro = false; return; }
switchIntroTab(btn.dataset.goods);
});
});
// 子 tab 胶囊拖动(弹簧跟随器,与主 tab 同款手感)
const introTabsEl = panel.querySelector('.intro-sub-tabs');
const introFollow = utils.createSpringFollower(v => { introIndicator.style.left = v + 'px'; });
let dragIntro = false, introDragMoved = false, introDragStartX = 0, introDragStartLeft = 0;
introTabsEl.addEventListener('mousedown', (e) => {
dragIntro = true; introDragMoved = false;
introDragStartX = e.clientX;
introDragStartLeft = parseFloat(introIndicator.style.left) || introIndicator.offsetLeft || 0;
introFollow.reset(introDragStartLeft);
});
document.addEventListener('mousemove', (e) => {
if (!dragIntro) return;
const dx = e.clientX - introDragStartX;
if (!introDragMoved && Math.abs(dx) > 5) {
introDragMoved = true;
introIndicator.style.transition = 'none';
}
if (introDragMoved) {
const target = introDragStartLeft + dx;
const minL = 0;
const maxL = introTabsEl.clientWidth - introIndicator.offsetWidth;
introFollow.seek(utils.rubberBand(target, minL, maxL));
}
});
document.addEventListener('mouseup', () => {
if (!dragIntro) return;
dragIntro = false;
if (!introDragMoved) return;
introDragMoved = false;
introFollow.stop();
introIndicator.style.transition = '';
const indCenter = introIndicator.offsetLeft + introIndicator.offsetWidth / 2;
let nearest = 0, best = Infinity;
introBtns.forEach((b, i) => {
const cx = b.offsetLeft + b.offsetWidth / 2;
const d = Math.abs(cx - indCenter);
if (d < best) { best = d; nearest = i; }
});
justDraggedIntro = true;
setTimeout(() => { justDraggedIntro = false; }, 200);
switchIntroTab(introBtns[nearest].dataset.goods);
});
switchIntroTab(GOODS_INTRO[0].key);
// ===== 滑块拖拽:按住可拖动,越界用弹簧跟随器逼近,松手落在最近 tab =====
const tabsEl = panel.querySelector('.panel-tabs');
const tabFollow = utils.createSpringFollower(v => { tabIndicator.style.left = v + 'px'; });
let draggingTab = false, tabDragMoved = false, dragStartX = 0, dragStartLeft = 0;
tabsEl.addEventListener('mousedown', (e) => {
draggingTab = true; tabDragMoved = false;
dragStartX = e.clientX;
dragStartLeft = parseFloat(tabIndicator.style.left) || tabIndicator.offsetLeft || 0;
tabFollow.reset(dragStartLeft);
});
document.addEventListener('mousemove', (e) => {
if (!draggingTab) return;
const dx = e.clientX - dragStartX;
if (!tabDragMoved && Math.abs(dx) > 5) {
tabDragMoved = true;
tabIndicator.style.transition = 'none';
}
if (tabDragMoved) {
const target = dragStartLeft + dx;
const minL = 0;
const maxL = tabsEl.clientWidth - tabIndicator.offsetWidth;
tabFollow.seek(utils.rubberBand(target, minL, maxL));
}
});
document.addEventListener('mouseup', () => {
if (!draggingTab) return;
draggingTab = false;
if (!tabDragMoved) return;
tabDragMoved = false;
tabFollow.stop();
tabIndicator.style.transition = '';
const indCenter = tabIndicator.offsetLeft + tabIndicator.offsetWidth / 2;
let nearest = 0, best = Infinity;
tabBtns.forEach((t, i) => {
const cx = t.offsetLeft + t.offsetWidth / 2;
const d = Math.abs(cx - indCenter);
if (d < best) { best = d; nearest = i; }
});
justDragged = true;
setTimeout(() => { justDragged = false; }, 200);
switchTab(tabBtns[nearest].dataset.tab);
});
// 拖拽逻辑(性能优化:rAF 节流 + 拖拽中禁 transition,解决拖动卡顿)
let dragging = false, offsetX = 0, offsetY = 0, dragRafId = null;
let dragMoved = false, startClientX = 0, startClientY = 0;
let lastPX = 0, lastPY = 0, lastPT = 0, vX = 0, vY = 0;
// 整个面板可拖,排除输入框/按钮/复选框/下拉框/textarea/标签等交互元素
const isInteractiveEl = (el) => !!el.closest('input, button, textarea, select, label, a, [data-tab]');
const endDrag = () => {
dragging = false;
if (dragRafId) { cancelAnimationFrame(dragRafId); dragRafId = null; }
panel.classList.remove('dragging');
panel.style.transition = '';
document.removeEventListener('mousemove', onDragMove);
document.removeEventListener('mouseup', endDrag);
// 松手抛掷:速度够快才玩物理,否则吸附当前位置
const speed = Math.hypot(vX, vY);
if (dragMoved && speed >= 60) {
if (speed >= 200) utils.emitParticles(lastPX, lastPY, Math.round((speed - 170) / 12));
utils.launchPanelPhysics(panel, () => vX, () => vY);
}
vX = vY = 0;
setTimeout(() => { dragMoved = false; }, 0);
};
const onDragMove = (e) => {
if (!dragging) return;
e.preventDefault();
const now = performance.now();
if (!dragMoved && (Math.abs(e.clientX - startClientX) > 5 || Math.abs(e.clientY - startClientY) > 5)) {
dragMoved = true;
lastPX = e.clientX; lastPY = e.clientY; lastPT = now;
}
if (!dragMoved) return;
// 末速度估计:最近两帧位置差分,指数平滑消除抖动
if (now - lastPT > 16) {
const dt = Math.max(1, now - lastPT);
vX = vX * 0.7 + ((e.clientX - lastPX) / dt * 1000) * 0.3;
vY = vY * 0.7 + ((e.clientY - lastPY) / dt * 1000) * 0.3;
lastPX = e.clientX; lastPY = e.clientY; lastPT = now;
}
if (dragRafId) return;
dragRafId = requestAnimationFrame(() => {
dragRafId = null;
panel.style.left = (e.clientX - offsetX) + 'px';
panel.style.top = (e.clientY - offsetY) + 'px';
panel.style.right = 'auto';
});
};
panel.addEventListener('mousedown', e => {
if (!panel.classList.contains('mini') && isInteractiveEl(e.target)) return;
panel.dataset.__physicsRunning = ''; // 打断惯性循环,交给拖拽接管
panel.classList.remove('squash');
dragging = true;
panel.classList.add('dragging');
// 用布局偏移(offsetLeft/offsetTop 不受 transform 缩放/3D 旋转影响,
// 与拖拽写入的 style.left/top 同坐标系)→ mini 态缩成球或高光 transform 残留时拖动不再跳变
offsetX = e.clientX - panel.offsetLeft;
offsetY = e.clientY - panel.offsetTop;
startClientX = e.clientX;
startClientY = e.clientY;
dragMoved = false;
vX = vY = 0;
lastPX = e.clientX; lastPY = e.clientY; lastPT = performance.now();
panel.style.transition = 'none';
document.addEventListener('mousemove', onDragMove);
document.addEventListener('mouseup', endDrag);
});
utils.bindPanelDepth(panel);
// 算力显示切换:点击「余额/总量」在余额↔总量间切换
const authStatusEl = panel.querySelector('#auth-status-text');
if (authStatusEl) {
authStatusEl.addEventListener('click', (e) => {
if (e.target.closest('[data-power-toggle]')) {
this.powerView = this.powerView === 'total' ? 'ball' : 'total';
this.updateAuthStatusUI();
}
});
}
// 卡密输入框实时同步:输入框为唯一真源,清空时清除旧卡缓存,避免「空输入框但旧卡状态残留」
const cardKeyInput = panel.querySelector('#card-key');
if (cardKeyInput) {
cardKeyInput.addEventListener('input', () => {
currentConfig.cardKey = cardKeyInput.value.trim();
GM_setValue('cardKey', currentConfig.cardKey);
if (!currentConfig.cardKey) {
AuthService.setCachedStatus({});
Logger.add('info', '卡密输入框已清空,清除本地状态缓存');
}
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
});
}
// 业务按键绑定:激活卡密 + 刷新状态
panel.querySelector('#activate-btn').addEventListener('click', async () => {
const input = panel.querySelector('#card-key');
currentConfig.cardKey = input.value.trim();
GM_setValue('cardKey', currentConfig.cardKey);
await AuthService.activate();
this.updateAuthStatusUI();
});
// 手动刷新授权状态;不调用 AI、不扣费。
panel.querySelector('#test-api-btn').addEventListener('click', () => {
// 始终以输入框当前值为准,避免残留内存旧卡
const input = panel.querySelector('#card-key');
if (input) { currentConfig.cardKey = input.value.trim(); GM_setValue('cardKey', currentConfig.cardKey); }
DeepSeekService.refreshAuthStatus();
});
// 购买卡密:切换到面板内的商品介绍与购买页。
panel.querySelector('#buy-btn').addEventListener('click', () => {
switchTab('intro');
});
// 联系开发者:弹出留言框,提交到服务端 /api/feedback(Pad 收 Termux 通知)
panel.querySelector('#contact-btn').addEventListener('click', () => {
AuthService.openFeedbackModal();
});
// 按钮悬停提示(JS 独立 tooltip,挂 body 避免面板 overflow:hidden 裁剪左侧)
panel.querySelectorAll('[data-tooltip]').forEach((el) => {
el.addEventListener('mouseenter', function () {
const tip = document.createElement('div');
tip.className = 'ai-tooltip-dyn';
tip.textContent = this.dataset.tooltip || '';
// 【2026-10-09】悬停提示配色统一:一律使用原 data-tooltip-tone="blue" 的蓝色调
// (原 default 深灰调已废弃;data-tooltip-tone 属性保留但不再参与判断)
tip.dataset.tone = 'blue';
tip.style.cssText = 'position:fixed;z-index:10000000;background:rgba(9,88,217,0.96);color:#fff;border:1px solid rgba(255,255,255,0.22);padding:6px 8px;border-radius:6px;font-size:11px;line-height:1.5;box-shadow:0 4px 12px rgba(9,88,217,0.35);pointer-events:none;max-width:260px;word-break:break-word;white-space:normal;';
if (this.dataset.tooltipWarning) {
const warning = document.createElement('div');
warning.textContent = this.dataset.tooltipWarning;
warning.style.cssText = 'color:#ffd666;margin-top:5px;font-weight:600;';
tip.appendChild(warning);
}
document.body.appendChild(tip);
const rect = this.getBoundingClientRect();
let left = rect.left;
let top = rect.top - tip.offsetHeight - 8;
// 超出视口左侧/上方时翻转
if (left + tip.offsetWidth > window.innerWidth) left = rect.right - tip.offsetWidth;
if (left < 0) left = 0;
if (top < 0) top = rect.bottom + 8;
tip.style.left = left + 'px';
tip.style.top = top + 'px';
this._dynTip = tip;
});
el.addEventListener('mouseleave', function () {
if (this._dynTip) { this._dynTip.remove(); this._dynTip = null; }
});
});
// 【2.5.10】折叠说明条(底部计费/价格 + 三个考试参数的说明,通用绑定)
// 标题优先取 data-label,未标注时回退到旧的「计费/价格」两档文案
panel.querySelectorAll('.price-note-toggle').forEach((btn) => {
btn.addEventListener('click', () => {
const note = btn.dataset.note;
const body = btn.closest('#exam-advanced-controls, #ai-helper-panel').querySelector('.price-note-body[data-note="' + note + '"]');
if (!body) return;
const open = body.classList.toggle('open');
const label = btn.dataset.label || (note === 'fee' ? '💡 计费说明' : '💰 价格说明');
// 带 data-label-open 的是标题行紧凑按钮:收起态用短标题,展开态换成另一短标题
const openLabel = btn.dataset.labelOpen || null;
btn.textContent = open
? (openLabel || label + '(点击收起)')
: (openLabel ? label : label + '(点击展开)');
});
});
// 「已答跳过」按钮(1.2.2 同步):账本记在本机,切换不影响已答记录
const skipBtn = panel.querySelector('#skip-answered-btn');
const syncSkipBtn = () => {
const on = !!currentConfig.skipAnswered;
const n = (() => { try { return AnsweredStore.count(); } catch (e) { return 0; } })();
skipBtn.textContent = `跳过已答: ${on ? '开' : '关'}` + (on && n ? ` (${n})` : '');
skipBtn.style.background = on ? '#173f82' : 'rgba(0,0,0,0.06)';
skipBtn.style.color = on ? '#fff' : '#666';
skipBtn.style.fontWeight = on ? 'bold' : 'normal';
};
syncSkipBtn();
skipBtn.addEventListener('click', async (ev) => {
if (ev && ev.shiftKey) {
AnsweredStore.clear();
try { CourseProgress.reset(); } catch (e) {}
syncSkipBtn();
utils.showMessage('已清空「已答账本」:下次进节会重新提交全部题目', 'success', 4000);
Logger.milestone('清空已答账本');
return;
}
if (FullCourseRunner._running || CollectTrip.busy) {
utils.showMessage('请先停止答题或等待采集结束,再切换跳过已答', 'warning');
return;
}
if (currentConfig.skipAnswered) {
skipBtn.disabled = true;
let confirmed;
try {
confirmed = await confirmCourseAction("确定关闭“跳过已答”?","“已答”指本机脚本提交后,平台接口返回成功并记录的题目。关闭后,每次重新启动答题(包括刷新网页后再次启动)都会全量重新答题、提交,消耗大量额度。",'保留开启','确认关闭');
} finally { skipBtn.disabled = false; }
if (!confirmed) return;
}
currentConfig.skipAnswered = !currentConfig.skipAnswered;
CourseProgress.paint();
CourseProgress.paintAnswer();
GM_setValue('skipAnswered', currentConfig.skipAnswered);
syncSkipBtn();
utils.showMessage(currentConfig.skipAnswered
? '已答跳过:开(提交成功的题下次不再重发)'
: '已答跳过:关(恢复每次进节全量重发)', 'info', 4000);
Logger.milestone('已答跳过 = ' + (currentConfig.skipAnswered ? '开' : '关'));
});
// 一键完成课程中所有题目:抓题 → 答题 → 提交 一条龙(账本命中自动跳过,重跑即补失败)
// 跑动中按钮变「停止本轮」:点击即停,当前这题走完即止
panel.querySelector('#one-key-btn').addEventListener('click', () => {
if (FullCourseRunner._running) {
FullCourseRunner.stop();
utils.showMessage('收到停止指令:当前这题走完即止,已取答案保留在盘', 'info');
return;
}
FullCourseRunner._rounds = 0; // 手动点击允许重跑
FullCourseRunner.start('一键完成');
});
// 开关状态同步:checkbox → switch-track 圆点
const syncSwitchState = () => {
panel.querySelectorAll('.switch-wrap input[type="checkbox"]').forEach(el => {
const track = el.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', el.checked);
});
};
syncSwitchState();
// 复选框即时保存:改动即写入 GM,刷新后保持
const checkboxBindings = [
{ id: 'auto-submit-switch', key: 'autoSubmit' },
{ id: 'answer-window-switch', key: 'answerWindowOn' },
{ id: 'expand-chapters-switch', key: 'expandChapters' },
{ id: 'auto-play-switch', key: 'autoPlayVideo' },
{ id: 'auto-switch-video-switch', key: 'autoSwitchVideo' },
];
checkboxBindings.forEach(({ id, key }) => {
const el = panel.querySelector('#' + id);
if (!el) return;
el.addEventListener('change', () => {
currentConfig[key] = el.checked;
// 【2.5.21】考试两键为会话态:只改内存、不写盘,刷新即回默认(关)
if (key !== 'examEnabled' && key !== 'examAutoSubmit') GM_setValue(key, el.checked);
// 实时副作用
if (key === 'expandChapters') {
el.checked ? ChapterExpander.startChapterObserver() : ChapterExpander.stopChapterObserver();
VideoController._allDone = false; // 范围变了 → 解除收工锁,允许继续
}
if (key === 'autoPlayVideo') {
el.checked ? VideoController.startNoPauseGuard() : VideoController.stopNoPauseGuard();
}
if (key === 'autoPlayVideo' && el.checked) {
Pusher.start(); // 3.0:开关打开即由推进器接管(旧的 initAutoPlay 不再参与自动切课)
}
if (key === 'answerWindowOn') {
AnswerWindow.setOn(el.checked);
}
if (key === 'autoSubmit') {
// 提交闸门:submit worker 在暂停态每 500ms 查一次这里,开 = 自动继续交
Logger.milestone('自动提交已' + (el.checked ? '打开(继续交卷)' : '关闭(只答题不提交,答案落盘保留)'));
}
if (key === 'examAutoSubmit') {
ExamBatchProcessor.syncSubmitUI();
}
syncSwitchState();
utils.showMessage('已保存', 'info');
});
});
// 考试提交槽位:自动提交开关 ↔ 两枚手动按钮(填入答案 / 提交本次考试,同一 250ms 交叉过渡)
const examFillBtn = panel.querySelector('#exam-fill-btn');
if (examFillBtn) {
examFillBtn.addEventListener('click', async () => {
if (examFillBtn.dataset.state === 'submitting') return;
if (!ExamBatchProcessor.answers || !ExamBatchProcessor.answers.size) {
utils.showMessage('暂无已获取的答案(可先跑一轮批量答题)', 'warning');
return;
}
examFillBtn.dataset.state = 'submitting';
ExamBatchProcessor.syncSubmitUI();
let ok = false;
try {
ok = await ExamBatchProcessor.manualFill();
} catch (error) {
Logger.add('error', '填入答案异常: ' + (error.message || error));
utils.showMessage('填入答案异常:' + (error.message || error), 'error');
}
examFillBtn.dataset.state = 'idle';
ExamBatchProcessor.syncSubmitUI();
// 【2.5.19】成败都不改按钮外观 —— 成功、失败一律回常态,只留 toast
if (ok) utils.showMessage('答案已填入考试页面(未提交)', 'success');
});
}
const examManualSubmitBtn = panel.querySelector('#exam-manual-submit-btn');
if (examManualSubmitBtn) {
examManualSubmitBtn.addEventListener('click', async () => {
if (examManualSubmitBtn.dataset.state === 'submitting') return;
examManualSubmitBtn.dataset.state = 'submitting';
ExamBatchProcessor.syncSubmitUI();
let result = false;
try {
result = await ExamBatchProcessor.manualSubmit();
} catch (error) {
Logger.add('error', '手动提交异常: ' + (error.message || error));
utils.showMessage('手动提交异常:' + (error.message || error), 'error');
}
// true=已提交;'blocked'=被前置条件拦下(没真提交);false=提交失败
// 【2.5.19】成败都不改按钮外观 —— 一律回常态,只留 toast
examManualSubmitBtn.dataset.state = 'idle';
ExamBatchProcessor.syncSubmitUI();
if (result === true) utils.showMessage('考试已确认提交', 'success');
});
}
ExamBatchProcessor.syncExamModeUI();
// 【2.5.18】重试未答出题目:只把上一轮没拿到答案的题再跑一遍(已答出的不再重复请求、不重复扣费)
const examRetryMissingBtn = panel.querySelector('#exam-retry-missing-btn');
if (examRetryMissingBtn) {
examRetryMissingBtn.addEventListener('click', () => {
ExamBatchProcessor.retryMissing();
});
}
// 【2.5.7】清除考试数据:一键清掉本机保存的答案 / 批次进度 / 统计读数
const examClearStoreBtn = panel.querySelector('#exam-clear-store-btn');
if (examClearStoreBtn) {
examClearStoreBtn.addEventListener('click', () => {
ExamBatchProcessor.clearStoredData();
});
}
const speedSelect=panel.querySelector('#video-speed'),speedLabel=panel.querySelector('#video-speed-label');
if(speedSelect){
let accepted=clampVideoSpeed(currentConfig.videoSpeed),confirming=false;
const preview=()=>{if(speedLabel)speedLabel.textContent=clampVideoSpeed(speedSelect.value)+'x';};
const apply=value=>{currentConfig.videoSpeed=value;GM_setValue('videoSpeed',value);VideoController.setSpeed(value);speedSelect.value=value;preview();};
preview();speedSelect.addEventListener('input',preview);
speedSelect.addEventListener('change',async()=>{
if(confirming)return;
const value=clampVideoSpeed(speedSelect.value);
if(value===accepted)return;
if(value<2||value>3){
confirming=true;speedSelect.disabled=true;
let yes=false;
try{yes=await confirmCourseAction('确定使用 '+value+'× 倍速?','建议使用 2×–3×。高倍速可能导致平台学习进度漏记,视频播放完毕后仍需补看。','返回建议区间','仍使用此倍速');}
finally{confirming=false;speedSelect.disabled=false;}
if(!yes){apply(accepted>=2&&accepted<=3?accepted:3);accepted=currentConfig.videoSpeed;return;}
}
apply(value);accepted=value;
utils.showMessage('倍速已设为 '+value+'x','info');
});
}
// 【2.5.12】考试参数由滑块改为数字输入框:失焦 / 回车即夹紧写盘。
// clamp 是唯一取值入口,非法或越界输入一律回填成合法值(不做「确认」二次交互)
const examNumberBindings = [
{ id: 'exam-batch-size', key: 'examBatchSize', clamp: clampExamBatchSize, unit: '题', name: '单轮题数' },
{ id: 'exam-concurrency', key: 'examConcurrency', clamp: clampExamConcurrency, unit: '轮', name: '单次提交轮数' },
{ id: 'exam-timeout', key: 'examRequestTimeout', clamp: clampExamRequestTimeout, unit: '秒', name: '等待超时' }
];
examNumberBindings.forEach(({ id, key, clamp, unit, name }) => {
const input = panel.querySelector('#' + id);
if (!input) return;
const commit = (announce) => {
const value = clamp(input.value);
const changed = value !== currentConfig[key];
currentConfig[key] = value;
GM_setValue(key, value);
input.value = value;
if (typeof ExamBatchProcessor !== 'undefined' && ExamBatchProcessor.refreshPlanUI) ExamBatchProcessor.refreshPlanUI();
if (announce && changed) utils.showMessage(`${name}已设为 ${value} ${unit}`, 'info');
};
input.addEventListener('change', () => commit(true));
input.addEventListener('blur', () => commit(false));
input.addEventListener('keydown', event => {
if (event.key === 'Enter') { commit(true); input.blur(); }
});
});
// 【2.5.12】「开始考试」按钮 —— 原「考试模式」开关的按钮形态,语义不变(是否处理考试的总闸门)
// 【2.5.23】补「就地起跑」分支:此前这里只翻转开关,对「已经打开的这场考试」无能为力,
// 用户必须先点「开始考试」再打开考试,或只能点「一键完成」才能起跑。
// 现在开启闸门的同时若能找到进行中的考试,就直接开跑(不套预设、不开自动提交,保持本按钮语义)。
const examStartBtn = panel.querySelector('#exam-start-btn');
if (examStartBtn) {
examStartBtn.addEventListener('click', () => {
const willEnable = !currentConfig.examEnabled;
currentConfig.examEnabled = willEnable;
// 【2.5.21】会话态:不写盘,刷新后回到关闭
ExamBatchProcessor.syncExamModeUI();
if (!willEnable) {
++ExamBatchProcessor.runId;
ExamBatchProcessor.aborted = true;
ExamBatchProcessor.running = false;
ExamBatchProcessor.runningBatches = 0;
ExamBatchProcessor.abortReason = '考试答题已暂停';
ExamBatchProcessor.persist();
ExamBatchProcessor.updateStatus('考试答题已暂停');
utils.showMessage('已停止考试模式:不再自动处理新的考试', 'info');
return;
}
// 开启闸门时:若此刻已在进行中的考试里,就地起跑(与「一键完成」第 4 步同源)
const vm = ExamBatchProcessor.findActiveExamVm();
const recordId = vm ? String(vm.recordId || '') : '';
if (vm && recordId) {
if (ExamBatchProcessor.running) {
utils.showMessage('考试模式已开启;已在答题中,无需重复起跑', 'info');
return;
}
const saved = ExamStore.read();
const alreadySubmitted = (saved && String(saved.recordId) === recordId && saved.submitted) || ExamBatchProcessor.submitted;
if (alreadySubmitted) {
utils.showMessage('考试模式已开启
检测到本场考试已提交过;如需重跑请先「清除考试数据」', 'warning', 8000);
return;
}
// 起跑前置条件(3.1.0 开关精简后只剩考试开关本身)
Logger.milestone('开始考试:检测到进行中的考试,立即开始答题');
utils.showMessage('检测到进行中的考试,立即开始答题', 'success', 6000);
ExamBatchProcessor.run(vm.records, recordId).catch(error => {
ExamBatchProcessor.running = false;
ExamBatchProcessor.errors.push(`批量答题异常:${error.message || error}`);
ExamBatchProcessor.updateStatus('运行失败');
});
return;
}
utils.showMessage('已开启考试模式:进入考试即自动答题' + (currentConfig.examAutoSubmit ? '并自动提交' : ';答完请到面板手动提交'), 'info');
});
}
// 【2.5.12】「一键完成」:套用推荐参数 + 开自动提交 + 开考试模式;已在考场则立即起跑
const examOneClickBtn = panel.querySelector('#exam-oneclick-btn');
if (examOneClickBtn) {
examOneClickBtn.addEventListener('click', () => { ExamBatchProcessor.oneClickComplete(); });
}
// 「一键完成课程中所有题目」「采集错题」等按钮绑定(旧的 全课抓题/全课提交/处理当前题目 已并入一键)
startCourseButtonParticles(panel.querySelector('#one-key-btn'));
panel.querySelector('#collect-mistakes-btn').addEventListener('click', () => CollectTrip.start());
panel.querySelector('#clear-review-data-btn').addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation();
if (FullCourseRunner._running || CollectTrip.busy) {
utils.showMessage('请先等待采集或答题结束,再清空错题数据', 'warning');
return;
}
if (!confirm('确定清空本地错题数据?服务端题库和已答记录不受影响。')) return;
currentConfig.reviewData = '{}';
GM_setValue('reviewData', '{}');
_reviewDataCacheKey = null;
_reviewDataCache = null;
this.updateReviewDebug();
Logger.milestone('本地错题数据已清空');
utils.showMessage('本地错题数据已清空', 'success');
});
// ⚙ 按钮:切换独立开发者面板
panel.querySelector('#tutorial-toggle-btn').addEventListener('click', e => { e.stopPropagation(); CourseTutorial.toggle(); });
panel.querySelector('#dev-toggle-btn').addEventListener('click', (e) => {
e.stopPropagation();
DevPanel.setOpen(!DevPanel.isOpen);
});
},
startPopupObserver: function() {
if (popupObserver) return;
// 找到页面上可见的、未处理过的答题弹窗(视频+考试)
const findUnprocessedPopup = () => {
const allPopups = document.querySelectorAll('.ant-modal-wrap');
for (const popup of allPopups) {
const style = window.getComputedStyle(popup);
if (style.display === 'none' || style.visibility === 'hidden') continue;
if (popup.getBoundingClientRect().width === 0) continue;
// 情况A:考试弹窗(依赖 .ant-form + 第X题格式)
if (currentConfig.examEnabled && ExamProcessor.isExamModal(popup)) {
if (examProcessing) continue; // 上一题还在处理中
const form = popup.querySelector('.ant-form');
const row1 = form.children[1];
const currentText = row1 ? row1.textContent.trim() : '';
if (currentText === lastQuestionText && lastQuestionText !== '') continue;
return { popup, titleText: currentText, isExam: true };
}
// 情况B:视频弹窗(依赖 .sub-title)
const titleEl = popup.querySelector('.sub-title');
if (!titleEl) continue;
const popupText = popup.textContent;
if (!popupText.includes('判断题') && !popupText.includes('单选题') && !popupText.includes('多选题')) continue;
const currentText = titleEl.textContent.trim();
if (currentText === lastQuestionText && lastQuestionText !== '') continue;
return { popup, titleText: currentText, isExam: false };
}
return null;
};
// 统一的处理入口
const tryProcess = () => {
const result = findUnprocessedPopup();
if (result) {
lastQuestionText = result.titleText;
const label = result.isExam ? '考试弹窗' : '答题弹窗';
utils.log(`检测到${label},自动处理:`, result.titleText.substring(0, 30));
setTimeout(() => {
const s = window.getComputedStyle(result.popup);
if (s.display !== 'none' && s.visibility !== 'hidden') {
if (result.isExam) {
// 单题考试流程已停用:考试题目一律交给 ExamBatchProcessor 批量处理
// if (!ExamBatchProcessor.isActive()) ExamProcessor.processExamQuestion(result.popup);
utils.log('考试弹窗已交由批量答题处理(单题流程停用)');
} else if (VideoApiAnswer.enabled()) {
// 【3.1.0 解耦】视频弹窗不再触发「本节答题」。
// 答题已由 FullCourseRunner 按章接管(抓题 → 逐章取答案 → 逐章提交),
// 本节弹窗只做两件事:关掉、让视频继续播,避免两套提交逻辑抢同一个题号。
Logger.add('info', '视频弹窗:答题已由全课流程接管,本节弹窗直接关闭');
VideoApiAnswer.closeVideoModal();
} else if (!currentConfig.reviewMode) {
Logger.milestone('开始处理视频弹窗题目');
QuestionProcessor.processQuestion(result.popup);
}
}
}, 500);
}
};
// 方案A:MutationObserver 监听新增节点 + 属性变化
popupObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
// childList:新弹窗容器被插入DOM(首次弹窗)
if (mutation.addedNodes.length > 0) {
for (const node of mutation.addedNodes) {
if (node.nodeType === 1 && (node.classList.contains('ant-modal-wrap') || node.querySelector('.ant-modal-wrap'))) {
tryProcess();
return;
}
}
}
// attributes:已有容器从隐藏变为可见(后续弹窗复用)
if (mutation.type === 'attributes' && mutation.target.nodeType === 1) {
const wrap = mutation.target.closest?.('.ant-modal-wrap') || mutation.target;
if (wrap.classList?.contains('ant-modal-wrap') || wrap.querySelector?.('.ant-modal-wrap')) {
tryProcess();
return;
}
}
}
});
popupObserver.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class']
});
// 方案B:轮询兜底(每2秒扫描一次,应对Observer漏掉的场景)
popupPollingId = setInterval(tryProcess, 2000);
utils.log('答题弹窗监听已启动(Observer + 轮询)');
},
stopPopupObserver: function() {
if (popupObserver) { popupObserver.disconnect(); popupObserver = null; }
if (popupPollingId) { clearInterval(popupPollingId); popupPollingId = null; }
},
// 更新面板授权状态显示
updateReviewDebug: function() {
const box = document.querySelector('#review-debug-data pre');
if (!box) return;
try { box.textContent = JSON.stringify(JSON.parse(currentConfig.reviewData || '{}'), null, 2); }
catch (e) { box.textContent = '错题数据格式异常'; }
},
updateAnswerAccess: function() {
const tab = document.getElementById('tab-answer');
if (!tab) return;
const locked = !AuthService.checkReady().ok;
tab.classList.toggle('answer-locked', locked);
tab.title = locked ? '激活卡密可用' : '';
tab.querySelectorAll('button, input').forEach(el => { el.disabled = locked; });
if (locked) AnswerWindow.hide();
},
updateAuthStatusUI: function() {
this.updateAnswerAccess();
const el = document.getElementById('auth-status-text');
if (!el) return;
const st = AuthService.getCachedStatus();
if (!st || !st.card_key || st.card_key !== currentConfig.cardKey.trim()) {
el.innerHTML = '未激活
';
return;
}
// 【2.8.3】换账号后缓存里的卡是别人的:不要继续显示绿色「已激活 + 余额」,
// 否则用户会以为授权还在,一答题就被服务端顶回来。
const mm = AuthService.accountMismatch();
if (mm) {
el.innerHTML = ''
+ '● 已绑定其他账号
'
+ ''
+ '卡密绑定:' + mm.cached + '
当前登录:' + mm.current
+ '
请登录绑定账号,或换用当前账号的卡密
';
return;
}
const isBind = st.type === 'bind';
// 状态 + 类型(bind 带账号)
let head = ''
+ '● 已激活'
+ '' + (isBind ? '绑定账号型' : '额度型')
+ (isBind && st.account_id ? '(' + st.account_id + ')' : '') + '
';
// 算力 + 约可答(bind 与 quota 都有);「算力」标签与「授权卡密」label 完全一致(13px/500/#555),单位分跟随
// 点击可切换:余额(默认)↔ 总量
const power = st.power != null ? st.power : (st.balance_cent || 0);
const est = st.est_questions != null ? st.est_questions : '';
const totalPower = st.total_power != null ? st.total_power : (power + (st.total_used_cent || 0));
// 总量题数:优先用后端字段;旧缓存缺字段时用相同口径 1.9 分/道 兜底计算
const totalEst = st.total_est_questions != null ? st.total_est_questions : Math.floor(totalPower / 1.9);
const viewBall = this.powerView !== 'total';
const viewPower = viewBall ? power : totalPower;
const viewEst = viewBall ? est : totalEst;
const viewLabel = viewBall ? '余额' : '总量';
let rows = ''
+ '' + viewLabel + ''
+ '' + viewPower + ' 分' + (viewEst !== '' ? ' · 约 ' + viewEst + ' 道' : '') + ' ⇄
';
// 到期行:bind 与 quota 通用(quota 自 2026-10-13 起也是限时卡,服务端激活时定格 90 天)。
// 未激活过的卡 expires_at 为空 ⇒ 不渲染该行(与「不限期的旧额度卡」一致)。
if (st.expires_at) {
rows += ''
+ '到期'
+ '' + (st.expires_at || '').slice(0, 10) + '
';
}
// 上游状态(服务端返回:rich=富裕 / warn=告急 / none=正常,作为独立一行)
let up = '';
if (st.upstream_status === 'warn') {
up = ''
+ '上游'
+ '⚠️ 告急
';
} else if (st.upstream_status === 'rich') {
up = ''
+ '上游'
+ '富裕
';
}
el.innerHTML = head + rows + up;
}
};
/* ===== 【临时停用 2026-11-05 19:15】开屏(启动门)模块整体注释掉,后续再调。
恢复方法:删掉本段起止的块注释符号,并在 init() 末尾把 startEngine() 换回 StartupGate.show()。
// ============================ 启动门(全屏遮罩 + 粒子太阳) ============================
// 【3.0.0】进入页面先过一道门:整屏压暗,控制面板与 CTA 浮在暗层之上。
// "开始刷课"= 打开自动播放+自动答题并开跑;"先不了"= 只关这两个开关。
const StartupGate = {
mask: null, // 遮罩 div:position:fixed; inset:0,z-index 低于面板,clip-path 挖洞
canvas: null, // 粒子 canvas:pointer-events:none 全屏,z-index 高于遮罩、低于面板
cta: null, // 主 CTA 卡片(含「开始刷课?」与「先不了」),位于面板正下方
ctx: null, // canvas 2d 上下文
rafId: null, // requestAnimationFrame 句柄,门关时置空
particles: [], // 当前在飞的粒子数组(sunEffect 关闭时恒为空)
resizeObs: null, // 监听面板尺寸变化(含开发者面板开合)
mutObs: null, // 监听面板 class/style 变化(拖拽结束、展开收起、开合)
onResize: null, // window resize 回调引用(便于移除)
// 粒子环带:从面板外沿向外辐射
bandInner: 18,
bandOuter: 160,
// 太阳粒子特效:bdm 2026-11-05 判定视觉不佳,先关;改 true 即恢复(画布/动画整套会跟着建或跳过)
sunEffect: false,
// 显示启动门:建遮罩 / canvas / CTA,启动动画,挂重算监听
show: function() {
if (this.mask) return; // 已显示则不再重复建(刷新即新实例,天然每窗口独立)
const panel = document.getElementById('ai-helper-panel');
if (!panel) return;
// 遮罩:整屏压暗并吃掉点击(面板与 CTA 层级更高,照常可交互)
this.mask = document.createElement('div');
this.mask.id = 'startup-gate-mask';
this.mask.style.cssText = 'position:fixed;inset:0;z-index:9999997;'
+ 'background:rgba(6,8,16,0.66);';
document.body.appendChild(this.mask);
// 粒子画布:覆盖全屏,仅画在环带内,不拦截任何点击(特效关闭时整块不建)
if (this.sunEffect) {
this.canvas = document.createElement('canvas');
this.canvas.id = 'startup-gate-canvas';
this.canvas.style.cssText = 'position:fixed;inset:0;z-index:9999998;pointer-events:none;';
this.ctx = this.canvas.getContext('2d');
document.body.appendChild(this.canvas);
}
// 主 CTA 卡片:面板正下方、居中于面板;整块(除「先不了」)点击 = 开始刷课
this.cta = document.createElement('div');
this.cta.id = 'startup-gate-cta';
this.cta.style.cssText = 'position:fixed;z-index:9999999;cursor:pointer;'
+ 'background:rgba(22,26,40,0.94);border:1px solid rgba(120,170,255,0.45);'
+ 'border-radius:16px;padding:14px 22px;text-align:center;color:#fff;'
+ 'font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;'
+ 'box-shadow:0 10px 32px rgba(0,0,0,0.45),0 0 0 1px rgba(0,0,0,0.2);user-select:none;box-sizing:border-box;';
this.cta.innerHTML =
'开始刷课?
'
+ '点击以开始
'
+ '';
document.body.appendChild(this.cta);
// 事件:整块 CTA 点击 = 开始刷课(「先不了」按钮单独拦下)
this.cta.addEventListener('click', (e) => {
if (e.target && e.target.id === 'startup-gate-decline') return;
this.start();
});
this.cta.querySelector('#startup-gate-decline').addEventListener('click', (e) => {
e.stopPropagation();
this.decline();
});
// CTA 跟随面板:面板拖拽结束 / 展开收起 / 开发者面板开合 / 窗口 resize 都触发
// —— 事件驱动,不轮询页面状态。
this.resizeObs = new ResizeObserver(() => this.recompute());
this.resizeObs.observe(panel);
const dev = document.getElementById('dev-panel');
if (dev) this.resizeObs.observe(dev);
// class 变化:拖拽结束(dragging 去掉)、展开收起(mini)、开发者面板开合(open)
this.mutObs = new MutationObserver(() => this.recompute());
this.mutObs.observe(panel, { attributes: true, attributeFilter: ['class', 'style'] });
if (dev) this.mutObs.observe(dev, { attributes: true, attributeFilter: ['class', 'style'] });
this.onResize = () => this.recompute();
window.addEventListener('resize', this.onResize);
this.recompute();
if (this.sunEffect) this.loop();
},
// 实时摆位:CTA 贴在面板正下方并跟随面板走;粒子特效开着时顺带同步画布尺寸。
// 遮罩做整屏压暗、不挖洞 —— 面板与 CTA 的 z-index 都高于遮罩,天然浮在上面,
// 少一套 clip-path 几何,也避免拖拽面板时洞口撕裂。
recompute: function() {
const panel = document.getElementById('ai-helper-panel');
if (!panel) return;
const pr = panel.getBoundingClientRect();
const W = window.innerWidth, H = window.innerHeight;
// canvas 尺寸跟随视口(含 dpr);粒子特效关闭时没有画布
if (this.canvas) {
const dpr = window.devicePixelRatio || 1;
this.canvas.width = Math.floor(W * dpr);
this.canvas.height = Math.floor(H * dpr);
this.canvas.style.width = W + 'px';
this.canvas.style.height = H + 'px';
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
// CTA 落在面板正下方、与面板同宽;贴底时上移避免溢出
const cw = pr.width;
let ctop = pr.bottom + 12;
if (ctop + 122 > H) ctop = H - 122;
this.cta.style.left = pr.left + 'px';
this.cta.style.top = ctop + 'px';
this.cta.style.width = cw + 'px';
},
// 粒子动画主循环:从面板外沿向外辐射、渐隐;维持 ~60 个
loop: function() {
const tick = () => {
this.rafId = requestAnimationFrame(tick);
const ctx = this.ctx;
const W = window.innerWidth, H = window.innerHeight;
ctx.clearRect(0, 0, W, H);
const panel = document.getElementById('ai-helper-panel');
if (!panel) return;
const pr = panel.getBoundingClientRect();
const cx = pr.left + pr.width / 2, cy = pr.top + pr.height / 2;
const hx = pr.width / 2, hy = pr.height / 2;
// 补充粒子到目标数
while (this.particles.length < 60) this.spawn();
for (let i = this.particles.length - 1; i >= 0; i--) {
const p = this.particles[i];
p.t += 1;
if (p.t >= p.life) { this.particles.splice(i, 1); continue; }
const e = p.t / p.life; // 0→1 进度
const r = this.bandInner + (this.bandOuter - this.bandInner) * e;
const x = cx + Math.cos(p.a) * (hx + r);
const y = cy + Math.sin(p.a) * (hy + r);
const alpha = (1 - e) * 0.85;
const rad = 1.6 + 2.4 * (1 - e);
const g = ctx.createRadialGradient(x, y, 0, x, y, rad * 3);
g.addColorStop(0, 'rgba(255,214,107,' + alpha + ')');
g.addColorStop(1, 'rgba(255,150,40,0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(x, y, rad * 3, 0, Math.PI * 2);
ctx.fill();
}
};
this.rafId = requestAnimationFrame(tick);
},
// 生成一个从面板外沿向外飞的粒子
spawn: function() {
const a = Math.random() * Math.PI * 2;
this.particles.push({
a: a,
t: 0,
life: 40 + Math.floor(Math.random() * 40) // 帧数:约 0.7~1.3s
});
},
// 「开始刷课」:打开自动播放(内存 + GM)+ 开跑引擎
// 【3.1.0】「自动答题」开关已删,答题恒跑,这里只管视频
start: function() {
currentConfig.autoPlayVideo = true;
GM_setValue('autoPlayVideo', true);
this.close();
if (typeof startEngine === 'function') startEngine();
},
// 「先不了」:只关自动播放
decline: function() {
currentConfig.autoPlayVideo = false;
GM_setValue('autoPlayVideo', false);
this.close();
},
// 关门:停 rAF、移除 DOM、卸监听(不留常驻动画与残留节点)
close: function() {
if (this.rafId) { cancelAnimationFrame(this.rafId); this.rafId = null; }
if (this.resizeObs) { this.resizeObs.disconnect(); this.resizeObs = null; }
if (this.mutObs) { this.mutObs.disconnect(); this.mutObs = null; }
if (this.onResize) { window.removeEventListener('resize', this.onResize); this.onResize = null; }
this.particles = [];
if (this.mask) { this.mask.remove(); this.mask = null; }
if (this.canvas) { this.canvas.remove(); this.canvas = null; this.ctx = null; }
if (this.cta) { this.cta.remove(); this.cta = null; }
}
};
===== 开屏模块到此结束 ===== */
// ============================ 开发者独立面板 ============================
const DevPanel = {
isOpen: false,
animation: null,
motionEffects: [],
clearMotion: function(panel) {
// 开合收尾只还原布局,不触发高级 UI 共用的 padding 等外观过渡。
const transition = panel.style.transition;
panel.style.transition = 'none';
if (this.animation) this.animation.cancel();
this.animation = null;
this.motionEffects.forEach(effect => effect.cancel());
this.motionEffects = [];
const content = panel.querySelector('.dev-morph-content');
if (content) content.replaceWith(...content.childNodes);
panel.querySelector('.dev-morph-icon')?.remove();
panel.classList.remove('dev-morphing');
void panel.offsetHeight;
panel.style.transition = transition;
},
setOpen: function(open) {
const answer = this === AnswerWindow;
const tutorial = this === CourseTutorial;
const panel = document.getElementById(answer ? 'ls3-answer-window' : tutorial ? 'course-tutorial' : 'dev-panel');
const button = answer ? document.querySelector('#answer-window-switch + .switch-track') : document.getElementById(tutorial ? 'tutorial-toggle-btn' : 'dev-toggle-btn');
if (!panel || !button || open === this.isOpen) return;
const entryColor = getComputedStyle(button).backgroundColor;
utils.resetPanelDepth(panel);
this.isOpen = open;
button.setAttribute('aria-expanded', String(open));
if (open) button.style.background = 'rgba(24,144,255,0.35)';
// 反向点击保留外壳的形状、位置和内容显露进度。
const properties = ['transform', 'width', 'height', 'borderRadius', 'backgroundColor', 'boxShadow'];
const readShell = () => {
const style = getComputedStyle(panel);
return Object.fromEntries(properties.map(key => [key, style[key]]));
};
const current = this.animation && readShell();
const oldContent = panel.querySelector('.dev-morph-content');
const contentOpacity = oldContent ? getComputedStyle(oldContent).opacity : (open ? 0 : 1);
const oldIcon = panel.querySelector('.dev-morph-icon');
const iconOpacity = oldIcon ? getComputedStyle(oldIcon).opacity : (open ? 1 : 0);
const oldAnchor = this.motionEffects[2]?.effect.target;
const anchorOpacity = oldAnchor ? getComputedStyle(oldAnchor).opacity : (open ? 0 : 1);
this.clearMotion(panel);
panel.dataset.__physicsRunning = '';
panel.classList.remove('squash');
if (open) panel.classList.add('dev-measuring');
panel.classList.add('open');
panel.inert = !open;
if (open) {
if (answer || tutorial) this.render();
else { this.refreshLog(); this.updatePromptPreview(); }
// 隐藏时 Tab 高度为 0;先完成实际布局,避免把高度过渡的起点当成展开终点。
if (!answer) { this.syncUiSubTabs(panel); this.syncActiveTab(panel); }
void panel.offsetHeight;
panel.classList.remove('dev-measuring');
} else if (panel.contains(document.activeElement)) {
button.focus({ preventScroll: true });
}
const finish = () => {
panel.classList.toggle('open', open);
this.clearMotion(panel);
// 外壳先以选中态颜色落回入口,再由按钮自身过渡恢复常态。
button.style.background = '';
};
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches || !currentConfig.tabAnimEnabled) {
finish();
return;
}
const rect = panel.getBoundingClientRect();
if (answer) {
panel.style.left = rect.left + 'px'; panel.style.top = rect.top + 'px';
panel.style.right = 'auto'; panel.style.bottom = 'auto';
}
let anchor = button;
let source = anchor.getBoundingClientRect();
// 主面板收起时,回到仍可见的主面板入口。
if (!source.width || !source.height || source.right <= 0 || source.left >= innerWidth || source.bottom <= 0 || source.top >= innerHeight || getComputedStyle(button).visibility === 'hidden') {
anchor = document.getElementById('ai-helper-panel');
source = anchor.getBoundingClientRect();
}
const style = getComputedStyle(panel);
const anchorStyle = getComputedStyle(anchor);
const expanded = { ...readShell(), transform: 'none', width: rect.width + 'px', height: rect.height + 'px' };
const folded = {
transform: `translate(${source.left - rect.left}px, ${source.top - rect.top}px)`,
width: source.width + 'px', height: source.height + 'px',
borderRadius: Math.min(parseFloat(anchorStyle.borderRadius), source.width / 2, source.height / 2) + 'px',
backgroundColor: anchor === button && open ? entryColor : anchorStyle.backgroundColor,
boxShadow: anchorStyle.boxShadow
};
// 内容保持原字号和排版,只让外壳改变尺寸,避免文字被压扁。
const content = document.createElement('div');
content.className = 'dev-morph-content';
content.style.width = (rect.width - parseFloat(style.borderLeftWidth) - parseFloat(style.borderRightWidth)) + 'px';
content.style.height = (rect.height - parseFloat(style.borderTopWidth) - parseFloat(style.borderBottomWidth)) + 'px';
content.style.padding = style.padding;
content.append(...panel.childNodes);
panel.appendChild(content);
const icon = document.createElement('span');
icon.className = 'dev-morph-icon';
icon.textContent = anchor === button ? '⚙' : '✨';
icon.style.fontSize = anchorStyle.fontSize;
panel.appendChild(icon);
panel.classList.add('dev-morphing');
const duration = open ? 560 : 440;
const timing = { duration, fill: 'both' };
const from = current || (open ? folded : expanded);
// 关闭先留出内容退场的时间,再把仍可见的外壳交还入口。
this.animation = panel.animate(open ? [
{ ...from, easing: 'cubic-bezier(0.2, 0.8, 0.2, 1)' }, expanded
] : [
{ ...from, offset: 0 },
{ ...from, offset: 0.18, easing: 'cubic-bezier(0.65, 0, 0.35, 1)' },
folded
], timing);
this.motionEffects = [
content.animate(open ? [
{ opacity: contentOpacity, offset: 0 },
{ opacity: contentOpacity, offset: 0.38 },
{ opacity: 1, offset: 0.85 }, { opacity: 1 }
] : [
{ opacity: contentOpacity }, { opacity: 0, offset: 0.18 }, { opacity: 0 }
], timing),
icon.animate(open ? [
{ opacity: iconOpacity }, { opacity: 0, offset: 0.22 }, { opacity: 0 }
] : [
{ opacity: iconOpacity }, { opacity: 0, offset: 0.18 }, { opacity: 0, offset: 0.78 }, { opacity: 1 }
], timing),
anchor.animate(open ? [
{ opacity: anchorOpacity }, { opacity: anchorOpacity, offset: 0.15 }, { opacity: 1, offset: 0.5 }, { opacity: 1 }
] : [
{ opacity: anchorOpacity }, { opacity: 1, offset: 0.3 }, { opacity: 1, offset: 0.7 }, { opacity: 0, offset: 0.95 }, { opacity: 0 }
], timing)
];
this.animation.onfinish = finish;
},
updateTabIndicator: function(panel) {
const indicator = panel.querySelector('.dev-tab-indicator');
const active = panel.querySelector('.dev-tab-btn.active');
if (!indicator || !active) return;
indicator.style.left = active.offsetLeft + 'px';
indicator.style.width = active.offsetWidth + 'px';
},
syncActiveTab: function(panel) {
this.updateTabIndicator(panel);
const active = panel.querySelector('.dev-tab-btn.active');
const view = panel.querySelector('.dev-tab-view');
const content = active && panel.querySelector('#' + active.dataset.tab);
if (view && content) view.style.height = content.offsetHeight + 'px';
},
syncUiSubTabs: function(panel) {
const active = panel.querySelector('.dev-ui-sub-tab.active');
const view = panel.querySelector('.dev-ui-sub-view');
const track = panel.querySelector('.dev-ui-sub-track');
const indicator = panel.querySelector('.dev-ui-sub-indicator');
if (!active || !view) return;
const tabs = [...panel.querySelectorAll('.dev-ui-sub-tab')];
const index = tabs.indexOf(active);
if (track) track.style.transform = 'translateX(' + (-index * 100) + '%)';
if (indicator) {
indicator.style.left = active.offsetLeft + 'px';
indicator.style.width = active.offsetWidth + 'px';
}
const content = panel.querySelector('#ui-' + active.dataset.uiTab);
if (content) view.style.height = content.offsetHeight + 'px';
},
create: function() {
if (document.getElementById('dev-panel')) return;
const panel = document.createElement('div');
panel.id = 'dev-panel';
panel.innerHTML = `
开发者设置
自定义 System 提示词(留空=按题型用默认)
自定义 User 提示词(可选,加在答题要求最前)
`;
document.body.appendChild(panel);
const examAdvanced = document.getElementById('exam-advanced-controls');
if (examAdvanced) {
examAdvanced.hidden = false;
panel.querySelector('#tab-exam-settings').appendChild(examAdvanced);
}
// 高级UI/Tab动画与主面板同步
if (currentConfig.glassBlur) panel.classList.add('panel-glass');
if (currentConfig.tabAnimEnabled) panel.classList.add('tab-anim');
// 开关轨道初始状态同步
panel.querySelectorAll('.switch-wrap input[type="checkbox"]').forEach(el => {
const track = el.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', el.checked);
});
this.bindEvents(panel);
},
bindDrag: function(panel) {
const owner = this;
// 拖拽(rAF 节流,解决拖动卡顿)
let dragging = false, ox = 0, oy = 0, dragRafId = null;
let dragMoved = false, startClientX = 0, startClientY = 0;
let lastPX = 0, lastPY = 0, lastPT = 0, vX = 0, vY = 0;
// 整个面板可拖,排除 tab 按钮/textarea/复选框/按钮等交互元素
const isInteractiveEl = (el) => !!el.closest('input, button, textarea, select, label, a, [data-tab]');
const endDrag = () => {
dragging = false;
if (dragRafId) { cancelAnimationFrame(dragRafId); dragRafId = null; }
panel.classList.remove('dragging');
panel.style.transition = '';
document.removeEventListener('mousemove', onDragMove);
document.removeEventListener('mouseup', endDrag);
const speed = Math.hypot(vX, vY);
if (dragMoved && speed >= 60) {
if (speed >= 200) utils.emitParticles(lastPX, lastPY, Math.round((speed - 170) / 12));
utils.launchPanelPhysics(panel, () => vX, () => vY);
}
vX = vY = 0;
setTimeout(() => { dragMoved = false; }, 0);
};
const onDragMove = (e) => {
if (!dragging) return;
e.preventDefault();
const now = performance.now();
if (!dragMoved && (Math.abs(e.clientX - startClientX) > 5 || Math.abs(e.clientY - startClientY) > 5)) {
dragMoved = true;
lastPX = e.clientX; lastPY = e.clientY; lastPT = now;
}
if (dragMoved) {
if (now - lastPT > 16) {
const dt = Math.max(1, now - lastPT);
vX = vX * 0.7 + ((e.clientX - lastPX) / dt * 1000) * 0.3;
vY = vY * 0.7 + ((e.clientY - lastPY) / dt * 1000) * 0.3;
lastPX = e.clientX; lastPY = e.clientY; lastPT = now;
}
}
if (dragRafId) return;
dragRafId = requestAnimationFrame(() => {
dragRafId = null;
panel.style.left = (e.clientX - ox) + 'px';
panel.style.top = (e.clientY - oy) + 'px';
});
};
panel.addEventListener('mousedown', e => {
if (owner.animation) return;
if (isInteractiveEl(e.target)) return;
panel.dataset.__physicsRunning = ''; // 打断惯性循环,交给拖拽接管
panel.classList.remove('squash');
dragging = true;
panel.classList.add('dragging');
ox = e.clientX - panel.getBoundingClientRect().left;
oy = e.clientY - panel.getBoundingClientRect().top;
dragMoved = false;
vX = vY = 0;
lastPX = e.clientX; lastPY = e.clientY; lastPT = performance.now();
panel.style.transition = 'none';
document.addEventListener('mousemove', onDragMove);
document.addEventListener('mouseup', endDrag);
});
},
bindEvents: function(panel) {
const highlight = panel.querySelector('.dev-highlight');
// 果冻按钮
panel.querySelectorAll('button').forEach(b => utils.jellyPress(b));
// 关闭按钮
panel.querySelector('#dev-close-btn').addEventListener('click', () => {
DevPanel.setOpen(false);
});
this.bindDrag(panel);
utils.bindPanelDepth(panel);
// 内容包装(推拉动画:固定视口 + 平移 track)
const devTabView = document.createElement('div');
devTabView.className = 'dev-tab-view';
const devTabTrack = document.createElement('div');
devTabTrack.className = 'dev-tab-track';
panel.querySelectorAll('.dev-tab-btn').forEach(btn => {
const content = panel.querySelector('#' + btn.dataset.tab);
if (content) devTabTrack.appendChild(content);
});
devTabView.appendChild(devTabTrack);
panel.querySelector('.dev-tabs').after(devTabView);
panel.querySelector('.dev-body').classList.add('panel-depth-layer');
// UI 页子 tab:外观 / Tab / 动效,与介绍页相同的胶囊 + 横向轨道结构
const uiSubTabs = panel.querySelectorAll('.dev-ui-sub-tab');
const uiSubIndicator = panel.querySelector('.dev-ui-sub-indicator');
const uiSubView = panel.querySelector('.dev-ui-sub-view');
const uiSubTrack = panel.querySelector('.dev-ui-sub-track');
const switchUiSubTab = (name) => {
const btn = panel.querySelector('.dev-ui-sub-tab[data-ui-tab="' + name + '"]');
const index = btn ? Array.from(uiSubTabs).indexOf(btn) : 0;
uiSubTabs.forEach(tab => tab.classList.toggle('active', tab === btn));
if (uiSubTrack && uiSubView) {
uiSubTrack.style.transform = 'translateX(' + (-index * 100) + '%)';
const content = panel.querySelector('#ui-' + name);
if (content) uiSubView.style.height = content.offsetHeight + 'px';
}
if (uiSubIndicator && btn) {
uiSubIndicator.style.left = btn.offsetLeft + 'px';
uiSubIndicator.style.width = btn.offsetWidth + 'px';
}
if (panel.classList.contains('open')) DevPanel.syncActiveTab(panel);
};
let uiSubJustDragged = false;
uiSubTabs.forEach(btn => btn.addEventListener('click', (e) => {
if (uiSubJustDragged && e.isTrusted) { uiSubJustDragged = false; return; }
switchUiSubTab(btn.dataset.uiTab);
}));
switchUiSubTab('appearance');
// UI 子 tab 复用主 tab 的拖拽、橡皮筋与弹簧参数。
const uiSubTabsEl = panel.querySelector('.dev-ui-sub-tabs');
const uiSubFollow = utils.createSpringFollower(v => { uiSubIndicator.style.left = v + 'px'; });
let uiSubDragging = false, uiSubMoved = false, uiSubStartX = 0, uiSubStartLeft = 0;
uiSubTabsEl.addEventListener('mousedown', (e) => {
uiSubDragging = true; uiSubMoved = false;
uiSubStartX = e.clientX;
uiSubStartLeft = parseFloat(uiSubIndicator.style.left) || uiSubIndicator.offsetLeft || 0;
uiSubFollow.reset(uiSubStartLeft);
});
document.addEventListener('mousemove', (e) => {
if (!uiSubDragging) return;
const dx = e.clientX - uiSubStartX;
if (!uiSubMoved && Math.abs(dx) > 5) {
uiSubMoved = true;
uiSubIndicator.style.transition = 'none';
}
if (uiSubMoved) {
const maxLeft = uiSubTabsEl.clientWidth - uiSubIndicator.offsetWidth;
uiSubFollow.seek(utils.rubberBand(uiSubStartLeft + dx, 0, maxLeft));
}
});
document.addEventListener('mouseup', () => {
if (!uiSubDragging) return;
uiSubDragging = false;
if (!uiSubMoved) return;
uiSubMoved = false;
uiSubFollow.stop();
uiSubIndicator.style.transition = '';
const center = uiSubIndicator.offsetLeft + uiSubIndicator.offsetWidth / 2;
let nearest = 0, distance = Infinity;
uiSubTabs.forEach((tab, index) => {
const tabCenter = tab.offsetLeft + tab.offsetWidth / 2;
const gap = Math.abs(tabCenter - center);
if (gap < distance) { distance = gap; nearest = index; }
});
uiSubJustDragged = true;
setTimeout(() => { uiSubJustDragged = false; }, 200);
switchUiSubTab(uiSubTabs[nearest].dataset.uiTab);
});
// 标签页切换(胶囊滑块跟随 + 推拉动画,与主面板同步)
const devIndicator = panel.querySelector('.dev-tab-indicator');
const updateDevIndicator = () => DevPanel.updateTabIndicator(panel);
let devJustDragged = false;
const switchDevTab = (name) => {
const btn = panel.querySelector('.dev-tab-btn[data-tab="' + name + '"]');
const curIdx = btn ? Array.from(panel.querySelectorAll('.dev-tab-btn')).indexOf(btn) : 0;
panel.querySelectorAll('.dev-tab-btn').forEach(b => b.classList.toggle('active', b === btn));
if (devTabTrack && devTabView) {
devTabTrack.style.transform = 'translateX(' + (-curIdx * 100) + '%)';
if (name === 'tab-ui') {
const activeUiTab = panel.querySelector('.dev-ui-sub-tab.active');
if (activeUiTab) switchUiSubTab(activeUiTab.dataset.uiTab);
}
const content = panel.querySelector('#' + name);
if (content) devTabView.style.height = content.offsetHeight + 'px';
}
if (name === 'tab-log') DevPanel.refreshLog();
updateDevIndicator();
};
panel.querySelectorAll('.dev-tab-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
if (devJustDragged && e.isTrusted) { devJustDragged = false; return; } // 只吞真实点击,不吞程序化 click()
switchDevTab(btn.dataset.tab);
});
});
switchDevTab('tab-prompts');
const devContentResize = new ResizeObserver(() => {
if (!panel.classList.contains('open')) return;
DevPanel.syncUiSubTabs(panel);
DevPanel.syncActiveTab(panel);
});
panel.querySelectorAll('.dev-tab-content').forEach(content => devContentResize.observe(content));
panel.querySelectorAll('.dev-ui-sub-content').forEach(content => devContentResize.observe(content));
// ===== dev 滑块拖拽:按住可拖动,越界弹簧跟随,松手落在最近 tab 并执行切换动画 =====
const devTabsEl = panel.querySelector('.dev-tabs');
const devBtns = panel.querySelectorAll('.dev-tab-btn');
const devFollow = utils.createSpringFollower(v => { devIndicator.style.left = v + 'px'; });
let devDragging = false, devMoved = false, devStartX = 0, devStartLeft = 0;
devTabsEl.addEventListener('mousedown', (e) => {
devDragging = true; devMoved = false;
devStartX = e.clientX;
devStartLeft = parseFloat(devIndicator.style.left) || devIndicator.offsetLeft || 0;
devFollow.reset(devStartLeft);
});
document.addEventListener('mousemove', (e) => {
if (!devDragging) return;
const dx = e.clientX - devStartX;
if (!devMoved && Math.abs(dx) > 5) {
devMoved = true;
devIndicator.style.transition = 'none';
}
if (devMoved) {
const target = devStartLeft + dx;
const minL = 0;
const maxL = devTabsEl.clientWidth - devIndicator.offsetWidth;
devFollow.seek(utils.rubberBand(target, minL, maxL));
}
});
document.addEventListener('mouseup', () => {
if (!devDragging) return;
devDragging = false;
if (!devMoved) return;
devMoved = false;
devFollow.stop();
devIndicator.style.transition = '';
const indCenter = devIndicator.offsetLeft + devIndicator.offsetWidth / 2;
let nearest = 0, best = Infinity;
devBtns.forEach((t, i) => {
const cx = t.offsetLeft + t.offsetWidth / 2;
const d = Math.abs(cx - indCenter);
if (d < best) { best = d; nearest = i; }
});
devJustDragged = true;
setTimeout(() => { devJustDragged = false; }, 200);
devBtns[nearest].click(); // 触发 dev 切换动画
});
panel.querySelector('#refresh-log-btn').addEventListener('click', () => DevPanel.refreshLog());
// 详细日志开关:即时保存并刷新(无需再点主面板保存配置)
const logDetailSwitch = panel.querySelector('#log-detail-switch');
if (logDetailSwitch) {
logDetailSwitch.addEventListener('change', () => {
currentConfig.logDetail = logDetailSwitch.checked;
GM_setValue('logDetail', currentConfig.logDetail);
const track = logDetailSwitch.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', logDetailSwitch.checked);
DevPanel.refreshLog();
utils.showMessage('日志详细模式已' + (logDetailSwitch.checked ? '开启' : '关闭'), 'info');
});
}
panel.querySelector('#clear-log-btn').addEventListener('click', () => {
Logger.clear();
DevPanel.refreshLog();
utils.showMessage('日志已清空', 'info');
});
// 趣味物理开关:同步外观、配置和运行中的特效。
const applyFunUI = () => {
document.querySelectorAll('#ai-helper-panel, #dev-panel, #course-tutorial').forEach(p => {
p.classList.toggle('fun-jelly-switch', currentConfig.funJellySwitch);
if (!currentConfig.funInertia) {
p.dataset.__physicsRunning = '';
p.classList.remove('squash');
}
if (!currentConfig.funWaterBall) p.classList.remove('water-ball');
if (!currentConfig.funJelly) {
p.querySelectorAll('button').forEach(b => b.classList.remove('pressed', 'jelly-pop'));
}
});
if (!currentConfig.funParticles) document.getElementById('ui-particle-layer')?.replaceChildren();
};
[
['dev-fun-jelly', 'funJelly'],
['dev-fun-jelly-switch', 'funJellySwitch'],
['dev-fun-inertia', 'funInertia'],
['dev-fun-particles', 'funParticles'],
['dev-fun-waterball', 'funWaterBall']
].forEach(([id, key]) => {
const input = panel.querySelector('#' + id);
input.addEventListener('change', () => {
currentConfig[key] = input.checked;
GM_setValue(key, input.checked);
input.nextElementSibling.classList.toggle('on', input.checked);
applyFunUI();
});
});
applyFunUI();
const depthSlider = panel.querySelector('#dev-depth-strength');
depthSlider.addEventListener('input', () => {
currentConfig.depthStrength = Number(depthSlider.value);
GM_setValue('depthStrength', currentConfig.depthStrength);
panel.querySelector('#dev-depth-strength-label').textContent = currentConfig.depthStrength + '%';
document.querySelectorAll('#ai-helper-panel, #dev-panel').forEach(p => utils.resetPanelDepth(p));
});
panel.querySelector('#dev-depth-reset').addEventListener('click', () => {
depthSlider.value = '100';
depthSlider.dispatchEvent(new Event('input'));
});
// 毛玻璃背景模糊:主面板与开发者面板同步
const devGlassBlurSwitch = panel.querySelector('#dev-glass-blur-switch');
if (devGlassBlurSwitch) {
const applyGlassBlur = () => {
const mainPanel = document.getElementById('ai-helper-panel');
if (mainPanel) {
if (!currentConfig.glassBlur) utils.resetPanelDepth(mainPanel);
mainPanel.classList.toggle('panel-glass', currentConfig.glassBlur);
mainPanel.style.setProperty('--glass-blur', currentConfig.glassBlurAmount + 'px');
mainPanel.style.setProperty('--panel-opacity', currentConfig.panelOpacity / 100);
}
panel.classList.toggle('panel-glass', currentConfig.glassBlur);
if (!currentConfig.glassBlur) utils.resetPanelDepth(panel);
panel.style.setProperty('--glass-blur', currentConfig.glassBlurAmount + 'px');
panel.style.setProperty('--panel-opacity', currentConfig.panelOpacity / 100);
AnswerWindow.applyAppearance();
CourseTutorial.applyAppearance();
};
devGlassBlurSwitch.addEventListener('change', () => {
currentConfig.glassBlur = devGlassBlurSwitch.checked;
GM_setValue('glassBlur', currentConfig.glassBlur);
applyGlassBlur();
const track = devGlassBlurSwitch.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', devGlassBlurSwitch.checked);
utils.showMessage('高级ui已' + (currentConfig.glassBlur ? '开启' : '关闭'), 'info');
});
const devGlassBlurAmount = panel.querySelector('#dev-glass-blur-amount');
const devGlassBlurLabel = panel.querySelector('#dev-glass-blur-label');
if (devGlassBlurAmount) {
devGlassBlurAmount.addEventListener('input', () => {
currentConfig.glassBlurAmount = Number(devGlassBlurAmount.value);
GM_setValue('glassBlurAmount', currentConfig.glassBlurAmount);
if (devGlassBlurLabel) devGlassBlurLabel.textContent = currentConfig.glassBlurAmount + 'px';
applyGlassBlur();
});
}
const devPanelOpacity = panel.querySelector('#dev-panel-opacity');
const devPanelOpacityLabel = panel.querySelector('#dev-panel-opacity-label');
if (devPanelOpacity) {
devPanelOpacity.addEventListener('input', () => {
currentConfig.panelOpacity = Number(devPanelOpacity.value);
GM_setValue('panelOpacity', currentConfig.panelOpacity);
if (devPanelOpacityLabel) devPanelOpacityLabel.textContent = currentConfig.panelOpacity + '%';
applyGlassBlur();
});
}
applyGlassBlur();
}
// Tab 切换动画开关
const devTabAnimSwitch = panel.querySelector('#dev-tab-anim-switch');
if (devTabAnimSwitch) {
devTabAnimSwitch.addEventListener('change', () => {
currentConfig.tabAnimEnabled = devTabAnimSwitch.checked;
GM_setValue('tabAnimEnabled', currentConfig.tabAnimEnabled);
const mainPanel = document.getElementById('ai-helper-panel');
if (mainPanel) mainPanel.classList.toggle('tab-anim', currentConfig.tabAnimEnabled);
panel.classList.toggle('tab-anim', currentConfig.tabAnimEnabled);
CourseTutorial.applyAppearance();
const track = devTabAnimSwitch.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', devTabAnimSwitch.checked);
utils.showMessage('Tab 切换动画已' + (currentConfig.tabAnimEnabled ? '开启' : '关闭'), 'info');
});
}
// Tab 拖拽弹性:模式开关 + 拉伸距离 + 弹簧软硬 K
const devRubberBand = panel.querySelector('#dev-rubber-band');
const devRubberLabel = panel.querySelector('#dev-rubber-band-label');
const devKSlider = panel.querySelector('#dev-k-slider');
const devKLabel = panel.querySelector('#dev-k-label');
const devKItem = panel.querySelector('#dev-k-item');
const devSpringModeSwitch = panel.querySelector('#dev-spring-mode-switch');
const devSpringModeLabel = panel.querySelector('#dev-spring-mode-label');
// 刷新 UI:K 滑条显隐/数值/可编辑性,以及模式文案
const refreshSpringUI = () => {
const auto = currentConfig.tabSpringMode !== 'manual';
const K = auto ? utils.springK() : (currentConfig.tabSpringK);
if (devKItem) devKItem.style.opacity = auto ? '0.4' : '1';
if (devKSlider) {
devKSlider.disabled = auto;
devKSlider.value = String(Math.round(K * 100));
}
if (devKLabel) devKLabel.textContent = 'K=' + Number(K).toFixed(2);
if (devSpringModeLabel) devSpringModeLabel.textContent = auto ? '自动(远=慢)' : '独立(可分开调)';
const track = devSpringModeSwitch && devSpringModeSwitch.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', !auto);
};
if (devSpringModeSwitch) {
devSpringModeSwitch.addEventListener('change', () => {
currentConfig.tabSpringMode = devSpringModeSwitch.checked ? 'manual' : 'auto';
GM_setValue('tabSpringMode', currentConfig.tabSpringMode);
if (!devSpringModeSwitch.checked) {
// 切回自动:同步 K 现值到配置(两模式下持久化一致)
const K = utils.springK();
currentConfig.tabSpringK = K;
GM_setValue('tabSpringK', K);
}
refreshSpringUI();
utils.showMessage('弹性模式:' + (devSpringModeSwitch.checked ? '独立调节(远近/软硬分开)' : '自动联动(拉得远=追得慢)'), 'info');
});
}
if (devRubberBand) {
devRubberBand.addEventListener('input', () => {
currentConfig.tabRubberBand = Math.round(Number(devRubberBand.value) / 10) * 10;
GM_setValue('tabRubberBand', currentConfig.tabRubberBand);
if (devRubberLabel) devRubberLabel.textContent = currentConfig.tabRubberBand + 'px';
// auto 模式下 OVER 改变会联动 K,同步刷新显示
if (currentConfig.tabSpringMode !== 'manual') {
currentConfig.tabSpringK = utils.springK();
GM_setValue('tabSpringK', currentConfig.tabSpringK);
if (devKSlider) devKSlider.value = String(Math.round(currentConfig.tabSpringK * 100));
if (devKLabel) devKLabel.textContent = 'K=' + currentConfig.tabSpringK.toFixed(2);
}
});
}
if (devKSlider) {
devKSlider.addEventListener('input', () => {
if (devKSlider.disabled) return; // auto 模式禁手动
currentConfig.tabSpringK = Math.round(Number(devKSlider.value)) / 100;
GM_setValue('tabSpringK', currentConfig.tabSpringK);
if (devKLabel) devKLabel.textContent = 'K=' + currentConfig.tabSpringK.toFixed(2);
});
}
refreshSpringUI();
// 保存提示词(保存按钮与恢复默认共用:恢复默认 = 清空后立即保存生效)
const savePrompts = () => {
let p1 = (document.getElementById('custom-prompt') || {}).value.trim();
let p2 = (document.getElementById('custom-user-prompt') || {}).value.trim();
// 超限截断(防单次 AI 消耗暴涨)
if (p1.length > PROMPT_MAX_LEN) {
p1 = p1.slice(0, PROMPT_MAX_LEN);
utils.showMessage('自定义 System 提示词超长,已截断至 ' + PROMPT_MAX_LEN + ' 字', 'warning');
}
if (p2.length > PROMPT_MAX_LEN) {
p2 = p2.slice(0, PROMPT_MAX_LEN);
utils.showMessage('自定义 User 提示词超长,已截断至 ' + PROMPT_MAX_LEN + ' 字', 'warning');
}
currentConfig.customPrompt = p1;
currentConfig.customUserPrompt = p2;
GM_setValue('customPrompt', currentConfig.customPrompt);
GM_setValue('customUserPrompt', currentConfig.customUserPrompt);
DevPanel.updatePromptPreview();
utils.showMessage('提示词已保存并生效', 'success');
Logger.milestone('自定义提示词已保存(System/User)');
};
panel.querySelector('#save-prompts-btn').addEventListener('click', savePrompts);
// 恢复默认:清空两个输入框后立即执行一次保存,让默认提示词当场生效
panel.querySelector('#reset-prompts-btn').addEventListener('click', () => {
panel.querySelector('#custom-prompt').value = '';
panel.querySelector('#custom-user-prompt').value = '';
savePrompts();
utils.showMessage('已恢复默认提示词并生效', 'success');
});
// 测试连接:用当前生效提示词实际调用AI,展示完整prompt与AI回复
panel.querySelector('#test-prompt-btn').addEventListener('click', async () => {
const resultEl = document.getElementById('test-prompt-result');
if (!resultEl) return;
// 优先取当前答题弹窗的真实题目,否则用示例题
let question = '实验室发生火灾时应立即用水扑救。';
let options = ['正确', '错误'];
let qtype = 'judgment';
const popup = document.querySelector('.ant-modal-wrap');
if (popup) {
const info = ExamProcessor.isExamModal(popup) ? ExamProcessor.extractExamQuestion(popup) : QuestionProcessor.extractQuestionInfo(popup);
if (info && info.type && info.text) {
question = info.text;
options = info.options.map(o => o.text);
qtype = info.type;
}
}
utils.showMessage('正在调用AI测试...', 'info');
const r = await DeepSeekService.testPrompt(question, options, qtype);
if (!r) return;
const customStatus = (currentConfig.customPrompt && currentConfig.customPrompt.trim())
? `已启用`
: `默认`;
resultEl.style.display = 'block';
resultEl.innerHTML = `
自定义提示词:${customStatus} | 题型:${qtype} ${popup ? '' : '(示例题,无答题弹窗)'}
System 提示词(角色/格式约束)
User 提示词(题目)
AI 原始回复
`;
resultEl.querySelector('#test-system-prompt').value = r.systemPrompt;
resultEl.querySelector('#test-user-prompt').value = r.userPrompt;
resultEl.querySelector('#test-ai-reply').value = r.raw + (r.status === 'ok' ? '' : '\n\n[请求异常: ' + r.status + ']');
// 失败时右上角 toast 提示(本地余额仍有值 + 上游类错误 → 明确"联系开发者"文案)
if (r.status !== 'ok') {
const toastMsg = (AuthService.isUpstreamFailure(r.status) && AuthService.hasBalance())
? '上游算力用尽,请联系开发者'
: ('提示词测试失败:' + (r.raw || r.status));
utils.showMessage(toastMsg, 'error');
}
Logger.milestone(`提示词测试完成: ${qtype}(${popup ? '真实题目' : '示例题'})`);
});
// 定期自动刷新日志
setInterval(() => {
if (panel.classList.contains('open')) DevPanel.refreshLog();
}, 3000);
},
refreshLog: function() {
const logView = document.getElementById('log-view');
if (logView) { logView.value = Logger.getText(); logView.scrollTop = logView.scrollHeight; }
},
// 更新"当前生效提示词"预览(双结构:System + User)
updatePromptPreview: function() {
const statusEl = document.getElementById('prompt-status');
const previewEl = document.getElementById('prompt-preview');
if (!statusEl || !previewEl) return;
const hasCustom = !!(currentConfig.customPrompt && currentConfig.customPrompt.trim());
// 状态区:自定义提示词 + 错题答案 两个维度
const customText = hasCustom
? `自定义提示词已启用`
: `默认提示词(未自定义)`;
statusEl.innerHTML = `状态:${customText}`;
// 双结构预览:System(你的要求/格式约束)+ User(错题参考 + 题目)
const system = DeepSeekService.buildSystemPrompt('single');
const user = DeepSeekService.buildUserPrompt('(示例题目)', ['A选项', 'B选项', 'C选项', 'D选项'], 'single');
previewEl.value = '【System 提示词 — 你的要求/格式约束】\n' + system
+ '\n\n【User 提示词 — 错题参考 + 题目】\n' + user;
}
};
// ============================ 视频题 API + AI 模式 ============================
// 课程接口只负责取题和提交;答案决策仍由授权服务后的 AI 完成。
// ---- 已答账本(1.2.2 同步)----
// 记录「提交成功」的题号,按 graphId 分桶落盘;下次进同一节默认跳过,不再重复 POST。
// 与「只重做错题」互斥:错题模式的目的是覆盖旧答案,所以那条路不看账本。
const AnsweredStore = {
KEY: 'videoAnsweredDone',
data: null,
load: function() {
if (this.data) return this.data;
try { this.data = JSON.parse(GM_getValue(this.KEY, '{}')) || {}; } catch (e) { this.data = {}; }
if (!this.data || typeof this.data !== 'object') this.data = {};
return this.data;
},
save: function() { try { GM_setValue(this.KEY, JSON.stringify(this.data || {})); } catch (e) {} },
bucket: function() {
const gid = String(VideoApiAnswer.graphId || '');
const all = this.load();
if (!all[gid]) all[gid] = {};
return all[gid];
},
has: function(id) { return !!this.bucket()[String(id)]; },
add: function(id) { this.bucket()[String(id)] = Date.now(); this.save(); },
count: function() { return Object.keys(this.bucket()).length; },
clear: function() {
this.load();
this.data[String(VideoApiAnswer.graphId || '')] = {};
this.save();
}
};
const VideoApiAnswer = {
token: '', courseId: '', graphId: '', hookInstalled: false,
submitted: new Set(), modalKillerInstalled: false,
reviewCourseId: '', reviewSwitchAfterAnswer: false,
available: function() {
// 【3.1.1】自动答题/手动作答开关已删(恒开/恒删):可用性只看答题模式
return currentConfig.videoAnswerMode === 'api-ai';
},
// 仅用于关闭平台「视频习题」弹窗;不再据此启动本节答题。
enabled: function() {
return this.available();
},
clearReviewCourse: function() {
this.reviewCourseId = '';
this.reviewSwitchAfterAnswer = false;
},
startReviewCourse: function(switchAfterAnswer) {
this.readContext();
const courseId = String(this.courseId || '');
if (!courseId) {
Logger.add('error', '复习模式后台答题无法获取课程 ID');
return;
}
const changed = this.reviewCourseId !== courseId;
this.reviewCourseId = courseId;
this.reviewSwitchAfterAnswer = !!switchAfterAnswer;
if (changed) this.submitted.clear();
// 复习模式只负责按平台状态检测/切课;本节答题已删除,不再从这里启动。
},
captureCourse: function(url) {
if (typeof url !== 'string' || !url.includes('/jcedutec/courseSource/')) return;
const match = url.match(/[?&]id=(\d+)/);
if (!match || !match[1] || match[1] === String(this.courseId)) return;
this.courseId = match[1];
this.submitted.clear();
// 只更新当前节上下文;不再设置 600ms 定时器触发本节答题。
},
hookPageRequests: function() {
if (this.hookInstalled) return;
this.hookInstalled = true;
const self = this;
const origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
try { this.__videoApiUrl = url; } catch (e) {}
return origOpen.apply(this, arguments);
};
const origSetHeader = XMLHttpRequest.prototype.setRequestHeader;
XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
try {
if (String(name).toLowerCase() === 'x-access-token' && value && !self.token) self.token = String(value);
if (this.__videoApiUrl) self.captureCourse(this.__videoApiUrl);
} catch (e) {}
return origSetHeader.apply(this, arguments);
};
const origFetch = window.fetch;
if (typeof origFetch === 'function') {
window.fetch = function(input, init) {
try {
const url = typeof input === 'string' ? input : (input && input.url) || '';
const headers = init && init.headers;
const value = headers && typeof headers.get === 'function'
? headers.get('x-access-token')
: headers && (headers['x-access-token'] || headers['X-Access-Token']);
if (value && !self.token) self.token = String(value);
self.captureCourse(url);
} catch (e) {}
return origFetch.apply(this, arguments);
};
}
},
readContext: function() {
try {
const params = new URL(location.href).searchParams;
this.courseId = this.courseId || params.get('id') || '';
// graphId 只在学习页 URL 里;错题采集在 myCourse 页(URL 不带 graphId),
// 所以学习页读到就缓存,采集页拿出来用 —— 否则上传题库没 graph_id 分不了库。
const gid = params.get('graphId') || '';
if (gid) {
this.graphId = gid;
try { GM_setValue('graphIdCache', gid); } catch (e) {}
} else if (!this.graphId) {
try { this.graphId = GM_getValue('graphIdCache', ''); } catch (e) {}
}
if (!this.token) {
const raw = localStorage.getItem('pro__Access-Token');
if (raw) {
try { this.token = String(JSON.parse(raw).value || raw); }
catch (e) { this.token = raw; }
}
}
} catch (e) {}
},
api: async function(method, path, body) {
const headers = this.token ? { 'x-access-token': this.token } : {};
const url = method === 'GET' ? path + (path.includes('?') ? '&' : '?') + '_t=' + Date.now() : path;
const init = { method, headers };
if (body) { headers['Content-Type'] = 'application/json'; init.body = JSON.stringify(body); }
const response = await fetch(url, init);
return response.json().catch(() => ({}));
},
fetchQuestions: function(courseId, graphId) {
return this.api('GET', '/api/jeecg-boot/jcedutec/courseSource/queryCourseQuestionRelaByMainId?id=' + encodeURIComponent(courseId) + '&graphId=' + encodeURIComponent(graphId))
.then(data => Array.isArray(data.result) ? data.result : []);
},
normalizeQuestion: function(q) {
const options = ['a', 'b', 'c', 'd'].map((key, index) => ({
letter: String.fromCharCode(65 + index),
text: String(q['option' + key] || '').replace(/\s+/g, ' ').trim()
})).filter(option => option.text);
const kind = String(q.kind);
return {
raw: q,
text: String(q.stem || q.question || '').replace(/\s+/g, ' ').trim(),
type: kind === '1' ? 'judgment' : kind === '3' ? 'multiple' : 'single',
options
};
},
answerToLetters: function(info, answers) {
if (!Array.isArray(answers) || !answers.length) return [];
const letters = [];
for (const raw of answers) {
const answer = String(raw || '').trim();
const direct = answer.toUpperCase().replace(/[::。.、,,\s]/g, '').match(/^[A-D]$/);
if (direct) { letters.push(direct[0]); continue; }
if (info.type === 'judgment' && /正确|错误|对|错/.test(answer)) {
const positive = /正确|对/.test(answer);
const option = info.options.find(item => positive ? /正确|对/.test(item.text) : /错误|错/.test(item.text));
if (option) letters.push(option.letter);
continue;
}
let best = null, bestScore = 0;
for (const option of info.options) {
const score = utils.similarity(option.text, answer);
if (score > bestScore) { best = option; bestScore = score; }
}
if (best && bestScore >= currentConfig.matchRate) letters.push(best.letter);
}
return [...new Set(letters)];
},
// 复习模式:优先用本地错题库直出答案,未命中才回落 AI
// reviewData 结构:{ 章节名: { 题目: JSON.stringify({a:答案文本[], l:字母串, o:选项文本[], k:题型}) } }
// 2.x 老格式是 { 章节名: { 题目: JSON.stringify([答案文本...]) } },由 ReviewCollector.parseEntry 兼容
lookupLocalAnswer: function(questionText, minScore) {
const need = Number(minScore) > 0 ? Number(minScore) : LOCAL_ANSWER_MATCH_THRESHOLD;
try {
// 复用题库解析缓存:reviewData 原始字符串不变则跳过 JSON.parse
const raw = currentConfig.reviewData || '{}';
let all;
if (raw === _reviewDataCacheKey) {
all = _reviewDataCache;
} else {
all = JSON.parse(raw);
_reviewDataCacheKey = raw;
_reviewDataCache = all;
}
// 题干与题库 key 统一归一:剥题型前缀 + 折叠空白 + 全角标点转半角。
// 剥前缀是为了兼容历史脏键:早期采集把 `(判断题) xxx` 整串当了 key,
// 而平台下发和现在采集的都是裸题干,不剥就永远匹配不上(长度差还会被严格模式拒掉)。
const normalize = (s) => {
if (!s) return '';
return String(s)
.replace(TYPE_PREFIX_RE, '')
.replace(/\s+/g, ' ')
.replace(/[():,。;、!?《》【】]/g, (m) => ({
'(': '(', ')': ')', ':': ':', ',': ',', '。': '.', ';': ';',
'、': ',', '!': '!', '?': '?', '《': '<', '》': '>', '【': '[', '】': ']'
}[m]))
.trim();
};
const q = normalize(questionText);
if (!q) return null;
let best = null, bestScore = 0;
for (const [chapter, qs] of Object.entries(all)) {
if (!qs || typeof qs !== 'object') continue;
for (const [key, val] of Object.entries(qs)) {
const keyNorm = normalize(key);
if (!keyNorm) continue;
let score = utils.similarity(keyNorm, q);
// 分数来自「包含」而非精确相等时(similarity 对包含返回 0.9),
// 短题干被长题干包含会误命中:严格模式(只重做错题)要求长度比 ≥0.9,
// 否则一道"特种设备"的题会被"消防安全里的特种设备"错配。
if (score >= 0.9 && keyNorm !== q) {
const ratio = Math.min(keyNorm.length, q.length) / Math.max(keyNorm.length, q.length);
if (ratio < (need >= 0.95 ? 0.9 : 0.75)) continue;
}
if (score > bestScore) { bestScore = score; best = val; }
}
}
if (best && bestScore >= need) {
// reviewData 有新旧两种存法:2.x 是裸文本数组,3.0 是 {a,l,o,k}。
// 这里统一返回答案文本数组,调用方(answerToLetters)不用关心版本。
let v = best;
try { v = JSON.parse(best); } catch (e) { return [String(best)]; }
if (Array.isArray(v)) return v;
if (v && Array.isArray(v.a)) return v.a;
return null;
}
} catch (e) {}
return null;
},
submit: function(q, letters, courseId, graphId) {
const option = String(q.kind) === '3' ? letters : letters[0] || '';
return this.api('POST', '/api/jeecg-boot/jcedutec/courseSource/submitAnswer', { questionId: q.id, id: courseId, graphId, option });
},
closeVideoModal: function() {
const modal = [...document.querySelectorAll('.ant-modal-wrap')].find(item =>
item.textContent && item.textContent.includes('视频习题') && item.getClientRects().length > 0
);
if (!modal) return;
const close = modal.querySelector('.ant-modal-close');
if (close) close.click(); else modal.remove();
setTimeout(() => { const video = document.querySelector('video'); if (video && video.paused) video.play().catch(() => {}); }, 100);
},
startModalKiller: function() {
if (this.modalKillerInstalled) return;
this.modalKillerInstalled = true;
// 【2026-11-06 浏览器卡死教训】这个 observer 盯的是整个 body 的 subtree,任何 DOM 改动都会触发;
// 而答题面板的日志/进度条是高频更新(每题、每 180ms)—— 不节流就形成
// 「改 DOM → observer 全 DOM 扫描 → 又改 DOM」的反馈回路,主线程直接被堵死。
// ⇒ 300ms 节流:既足够秒关平台弹窗,也不会被自己的面板更新拖死。
let lastRun = 0;
const tryClose = () => {
const now = Date.now();
if (now - lastRun < 300) return;
lastRun = now;
if (this.enabled()) this.closeVideoModal();
};
new MutationObserver(tryClose).observe(document.body, { childList: true, subtree: true });
setInterval(tryClose, 800);
},
// 仅「手动作答模式」使用:已随 3.1.1 开关精简整体删除;自动答题只走 FullCourseRunner。
boot: function() {
if (!this.available()) return;
this.hookPageRequests();
this.readContext();
this.startModalKiller();
// 自动答题由 FullCourseRunner 在 startEngine 启动;这里不再触发本节 run。
},
};
// ============================ 答题窗口(接管式,3.0 第 5 步) ============================
// 平台「视频习题」弹窗一出现就被 VideoApiAnswer.startModalKiller 关掉,本窗口是唯一入口。
// 数据来自题单接口,不读弹窗 DOM —— 弹窗关着照样显示、照样提交。
// 层级:启动门遮罩 > 本窗口(999980) > 平台弹窗(.ant-modal ~1000)。
const AnswerWindow = {
_el: null,
_data: null, // 当前题:{index,total,type,stem,options,picked,source,result,raw}
_line: { now: '待命', last: '' }, // 底部运行状态:当前动作 + 上一动作结果
isOn: function() { return currentConfig.answerWindowOn; },
setOn: function(v) {
currentConfig.answerWindowOn = !!v;
GM_setValue('answerWindowOn', currentConfig.answerWindowOn);
const input = document.getElementById('answer-window-switch');
if (input) {
input.checked = this.isOn();
if (input.nextElementSibling) input.nextElementSibling.classList.toggle('on', this.isOn());
}
if (this.isOn()) this.show(); else this.hide();
},
ensure: function() {
if (this._el && document.body.contains(this._el)) return this._el;
// 样式带版本标记:旧版(无 .aw-bars)已存在就替换掉,否则新结构会沿用旧 CSS 走形
const oldStyle = document.getElementById('ls3-aw-style');
if (oldStyle && oldStyle.textContent.indexOf('aw-light-v2') >= 0) {
/* 已是新版样式,不动 */
} else {
if (oldStyle) oldStyle.remove();
const staleWin = document.getElementById('ls3-answer-window');
if (staleWin) staleWin.remove();
const style = document.createElement('style');
style.id = 'ls3-aw-style';
style.textContent = `
#ls3-answer-window{position:fixed;right:18px;bottom:18px;width:396px;max-height:76vh;z-index:999980;
display:none;flex-direction:column;overflow:hidden;background:rgba(17,20,30,.96);color:#e8ecf5;
border:1px solid rgba(255,255,255,.13);border-radius:14px;box-shadow:0 18px 48px rgba(0,0,0,.5);
font:12px/1.55 -apple-system,"Segoe UI",system-ui,sans-serif;backdrop-filter:blur(10px);}
#ls3-answer-window.on{display:flex}
#ls3-answer-window .aw-head{display:flex;align-items:center;gap:8px;padding:9px 12px;
border-bottom:1px solid rgba(255,255,255,.1);background:rgba(255,255,255,.03);}
#ls3-answer-window .aw-title{font-weight:600;font-size:12.5px;letter-spacing:.3px;}
#ls3-answer-window .aw-count{margin-left:auto;font-size:11px;opacity:.75;font-variant-numeric:tabular-nums;}
#ls3-answer-window .aw-close{cursor:pointer;opacity:.5;font-size:15px;line-height:1;padding:0 2px;margin-left:8px;}
#ls3-answer-window .aw-close:hover{opacity:1}
/* ---- 三进度条:抓题 / 答题 / 提交(左绿成功、右红失败、中间灰未做) ---- */
#ls3-answer-window .aw-bars{padding:10px 12px 9px;display:flex;flex-direction:column;gap:9px;
border-bottom:1px solid rgba(255,255,255,.08);}
#ls3-answer-window .aw-bar-top{display:flex;align-items:baseline;gap:6px;margin-bottom:4px;}
#ls3-answer-window .aw-bar-name{font-size:11.5px;color:#c6d0e2;letter-spacing:.6px;}
#ls3-answer-window .aw-bar-num{margin-left:auto;font-size:11px;color:#8b97ad;font-variant-numeric:tabular-nums;}
/* 进度条移植自习题集 1.2.2:左绿(成功)/ 右红(失败)/ 中间灰(还没做),悬停看说明 */
#ls3-answer-window .aw-track{position:relative;height:16px;border-radius:7px;overflow:hidden;
background:rgba(255,255,255,.085);border:1px solid rgba(255,255,255,.07);cursor:help;}
#ls3-answer-window .aw-track>i{position:absolute;top:0;bottom:0;width:0;transition:width .22s ease;}
#ls3-answer-window .aw-track>i.aw-ok{left:0;background:linear-gradient(180deg,#52c98a,#3fbf74);}
#ls3-answer-window .aw-track>i.aw-bad{right:0;background:linear-gradient(180deg,#f2726f,#e5484d);}
#ls3-answer-window .aw-track>b.aw-txt{position:absolute;inset:0;display:flex;align-items:center;
justify-content:center;font-size:10px;font-weight:400;color:#dbe3f2;letter-spacing:.2px;
font-variant-numeric:tabular-nums;pointer-events:none;text-shadow:0 1px 2px rgba(0,0,0,.55);}
#ls3-answer-window .aw-bar-sub{margin-top:3px;font-size:10.5px;color:#6f7b92;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
#ls3-answer-window .aw-bar-sub.done{color:#5fd6a3;}
/* 中间的「答题」条用蓝色填充区分:它统计的是「已取到答案的题」,不是提交成功 */
#ls3-answer-window .aw-bar.answer .aw-bar-name{color:#93c2ff;}
#ls3-answer-window #aw-bar-answer .aw-track>i.aw-ok{background:linear-gradient(180deg,#5fa8ff,#3f8ff5);}
#ls3-answer-window #aw-bar-answer .aw-track>i.aw-ai{background:linear-gradient(180deg,#b592fa,#8754da);}
/* ---- 题面区(3.1.1:手动作答已删,题面只作展示,不再可交互) ---- */
#ls3-answer-window .aw-q{padding:9px 12px;border-bottom:1px solid rgba(255,255,255,.08);
max-height:36vh;overflow-y:auto;flex:none;}
#ls3-answer-window .aw-meta{display:flex;gap:6px;align-items:center;margin-bottom:6px;}
#ls3-answer-window .aw-type{font-size:11px;padding:1px 7px;border-radius:999px;
background:rgba(90,150,255,.18);color:#8fb6ff;border:1px solid rgba(90,150,255,.3);}
#ls3-answer-window .aw-src{font-size:11px;padding:1px 7px;border-radius:999px;
background:rgba(255,255,255,.07);color:#b9c3d6;border:1px solid rgba(255,255,255,.14);}
#ls3-answer-window .aw-src[data-src="题库"]{background:rgba(60,200,140,.16);color:#5fd6a3;border-color:rgba(60,200,140,.3);}
#ls3-answer-window .aw-src[data-src="AI"]{background:rgba(190,120,255,.16);color:#c69bff;border-color:rgba(190,120,255,.3);}
#ls3-answer-window .aw-src[data-src="批量"]{background:rgba(90,150,255,.16);color:#9dbcff;border-color:rgba(90,150,255,.3);}
#ls3-answer-window .aw-stem{font-size:12.5px;line-height:1.6;color:#f2f5fb;word-break:break-word;
display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;}
#ls3-answer-window .aw-opts{display:flex;flex-direction:column;gap:6px;margin-top:8px;}
#ls3-answer-window .aw-opt{text-align:left;padding:7px 10px;border-radius:9px;cursor:default;
background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.1);color:#dbe3f0;
font:inherit;line-height:1.5;transition:background .12s,border-color .12s;}
#ls3-answer-window .aw-opt.picked{background:rgba(60,130,255,.22);border-color:rgba(80,150,255,.6);color:#dbe9ff;}
/* ---- 日志文本框(等宽、内凹、可选中复制、自动滚底) ---- */
#ls3-answer-window .aw-logwrap{padding:8px 12px 10px;flex:1;min-height:0;display:flex;flex-direction:column;}
#ls3-answer-window .aw-logtitle{display:flex;align-items:center;font-size:10.5px;color:#616d85;margin-bottom:4px;}
#ls3-answer-window .aw-logtitle .aw-logauto{margin-left:auto;cursor:pointer;color:#93a0b8;padding:1px 7px;
border:1px solid rgba(255,255,255,.14);border-radius:999px;background:rgba(255,255,255,.04);}
#ls3-answer-window .aw-logtitle .aw-logauto:hover{color:#fff;border-color:rgba(255,255,255,.3);}
#ls3-answer-window .aw-log{flex:1;min-height:134px;max-height:210px;overflow-y:auto;padding:7px 9px;
border-radius:8px;background:rgba(0,0,0,.34);border:1px solid rgba(255,255,255,.08);
font:11px/1.5 ui-monospace,Consolas,"Cascadia Mono",Menlo,monospace;color:#a9b4c9;
white-space:pre-wrap;word-break:break-word;user-select:text;cursor:text;}
#ls3-answer-window .aw-log:empty::before{content:"等待日志…";color:#48526b;}
#ls3-answer-window .aw-log .lg-t{color:#4f5a73;}
#ls3-answer-window .aw-log .lg-ok{color:#5fd6a3;}
#ls3-answer-window .aw-log .lg-err{color:#ff8f8f;}
#ls3-answer-window .aw-log .lg-ai{color:#c69bff;}
#ls3-answer-window .aw-log .lg-ms{color:#8fb6ff;}
#ls3-answer-window .aw-foot{padding:6px 12px;border-top:1px solid rgba(255,255,255,.08);
background:rgba(255,255,255,.025);font-size:11px;line-height:1.45;flex:none;}
#ls3-answer-window .aw-now{color:#a9b8d4;}
#ls3-answer-window .aw-last{color:#6d7893;margin-top:1px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}`;
style.textContent += `
/* 统一面板外观,日志仍保留深色高对比区。 */
#ls3-answer-window{background:rgba(255,255,255,var(--panel-opacity,1));color:#303846;border-radius:22px;border:1px solid rgba(170,190,215,.45);box-shadow:0 14px 42px rgba(25,65,115,.2);backdrop-filter:none;}
#ls3-answer-window.open{display:flex;}
#ls3-answer-window.panel-glass{background:rgba(230,240,255,calc(var(--panel-opacity,1)*.8));backdrop-filter:blur(var(--glass-blur,28px));}
#ls3-answer-window .aw-head,#ls3-answer-window .aw-q,#ls3-answer-window .aw-foot{border-color:rgba(100,130,170,.16);}
#ls3-answer-window .aw-title,#ls3-answer-window .aw-stem{color:#303846;}
#ls3-answer-window .aw-bar-name,#ls3-answer-window .aw-count,#ls3-answer-window .aw-last{color:#62738c;}
#ls3-answer-window .aw-bar-sub{color:#536681;}
#ls3-answer-window .aw-close{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:10px;background:rgba(24,144,255,.12);color:#1890ff;opacity:1;}
#ls3-answer-window.dev-morphing{padding:0!important;overflow:hidden;pointer-events:none;}
#ls3-answer-window .dev-morph-content{flex:none;box-sizing:border-box;}
#ls3-answer-window .dev-morph-icon{position:absolute;inset:0;display:grid;place-items:center;color:#1890ff;pointer-events:none;}
/* aw-light-v2:浅色壳、深色日志,所有弱对比组件显式配色。 */
#ls3-answer-window{max-width:calc(100vw - 16px);cursor:grab;}
#ls3-answer-window.dragging{cursor:grabbing;user-select:none;}
#ls3-answer-window .aw-head{background:rgba(255,255,255,.5);}
#ls3-answer-window .aw-title,#ls3-answer-window .aw-stem,#ls3-answer-window .aw-now{color:#24364d;}
#ls3-answer-window .aw-count{opacity:1;}
#ls3-answer-window .aw-bars,#ls3-answer-window .aw-q{border-color:#cbd7e6;}
#ls3-answer-window .aw-bar-top,#ls3-answer-window .aw-bar-name,#ls3-answer-window .aw-logtitle{color:#425774;}
#ls3-answer-window .aw-bar.answer .aw-bar-name{color:#285b9b;}
#ls3-answer-window .aw-bar-name span:first-child{color:#2464a8!important;}
#ls3-answer-window .aw-bar-name span:last-child{color:#7847ad!important;}
#ls3-answer-window .aw-bar-sub.done{color:#176b46;}
#ls3-answer-window .aw-track{background:#dce5f0;border:1px solid #b9c9dc;}
#ls3-answer-window .aw-track>b.aw-txt{color:#182c46;text-shadow:0 1px 1px rgba(255,255,255,.75);font-weight:600;}
#ls3-answer-window .aw-type{background:#dceaff;border-color:#a8c5ef;color:#22578f;}
#ls3-answer-window .aw-src{background:#e7edf5;border-color:#bccbde;color:#425774;}
#ls3-answer-window .aw-src[data-src="题库"]{background:#d8f0e4;border-color:#9fcdb5;color:#176b46;}
#ls3-answer-window .aw-src[data-src="AI"]{background:#eee2ff;border-color:#c6a7e8;color:#7040a0;}
#ls3-answer-window .aw-src[data-src="批量"]{background:#dceaff;border-color:#a8c5ef;color:#22578f;}
#ls3-answer-window .aw-opt{background:#eef3f9;border-color:#c6d3e4;color:#2c405c;}
#ls3-answer-window .aw-opt.picked{background:#d6e8ff;border-color:#82afe8;color:#194e8a;}
#ls3-answer-window .aw-logtitle .aw-logauto{background:#e3edfa;border-color:#aec7e6;color:#285b9b;}
#ls3-answer-window .aw-logtitle .aw-logauto:hover{background:#d0e3fd;color:#194e8a;}
#ls3-answer-window .aw-log{background:#172235;border-color:#31445f;color:#d3deed;cursor:text;}
#ls3-answer-window .aw-log .lg-t,#ls3-answer-window .aw-log:empty::before{color:#99abc2;}
#ls3-answer-window .aw-foot{background:rgba(235,242,251,.65);border-color:#cbd7e6;}
`;
document.head.appendChild(style);
}
const el = document.createElement('div');
el.id = 'ls3-answer-window';
el.innerHTML = `
答题面板
—
×
`;
document.body.appendChild(el);
el.querySelector('#aw-close').addEventListener('click', () => this.setOn(false));
el.querySelector('#aw-logauto').addEventListener('click', (ev) => {
this._autoScroll = !this._autoScroll;
ev.currentTarget.textContent = '自动滚动: ' + (this._autoScroll ? '开' : '关');
});
this._el = el;
this.bindDrag(el);
utils.bindPanelDepth(el);
this.applyAppearance();
this._renderLog();
return el;
},
bindDrag: function(el) {
let drag = null;
el.addEventListener('pointerdown', event => {
if (event.button !== 0 || this.animation || event.target.closest('button,input,textarea,select,label,a,.aw-close,.aw-logauto,.aw-log,.aw-stem,.aw-opts')) return;
const rect = el.getBoundingClientRect();
drag = { x: event.clientX - rect.left, y: event.clientY - rect.top };
el.style.left = rect.left + 'px'; el.style.top = rect.top + 'px';
el.style.right = 'auto'; el.style.bottom = 'auto';
el.classList.add('dragging');
el.setPointerCapture(event.pointerId);
event.preventDefault();
});
el.addEventListener('pointermove', event => {
if (!drag) return;
el.style.left = Math.max(0, Math.min(innerWidth - el.offsetWidth, event.clientX - drag.x)) + 'px';
el.style.top = Math.max(0, Math.min(innerHeight - el.offsetHeight, event.clientY - drag.y)) + 'px';
});
const finish = () => { drag = null; el.classList.remove('dragging'); };
el.addEventListener('pointerup', finish);
el.addEventListener('pointercancel', finish);
el.addEventListener('lostpointercapture', finish);
},
isOpen: false,
animation: null,
motionEffects: [],
clearMotion: function(panel) { DevPanel.clearMotion.call(this, panel); },
applyAppearance: function() {
const el = this._el;
if (!el) return;
el.classList.toggle('panel-glass', currentConfig.glassBlur);
el.style.setProperty('--glass-blur', currentConfig.glassBlurAmount + 'px');
el.style.setProperty('--panel-opacity', currentConfig.panelOpacity / 100);
if (!currentConfig.glassBlur) utils.resetPanelDepth(el);
},
show: function() {
if (!this.isOn()) return;
this.ensure();
DevPanel.setOpen.call(this, true);
},
hide: function() { if (this._el) DevPanel.setOpen.call(this, false); },
// ---- 三进度条状态:抓题 / 答题 / 提交(done=成功数,bad=失败数,total=总数) ----
_bar: {
grab: { done: 0, bad: 0, total: 0, sub: '未开始' },
answer: { done: 0, bad: 0, total: 0, sub: '待命' },
submit: { done: 0, bad: 0, total: 0, sub: '待命' }
},
// 答题(取答案)进度:题目一抓到就往这里推,不等全课抓完
setAnswer: function(done, total, sub, bad, ai) {
this._bar.answer = { done: done || 0, bad: bad || 0, total: total || 0, sub: sub || '', ai: ai || 0 };
this._barPaintOnly('answer', this._bar.answer);
},
// 抓题进度:只重画进度条,不重建题目区
// (高频调用,走 render() 会把整个面板推倒重建 → 每节一次全量重绘 + 触发 body MutationObserver)
setGrab: function(done, total, sub, bad) {
this._bar.grab = { done: done || 0, bad: bad || 0, total: total || 0, sub: sub || '' };
this._barPaintOnly('grab', this._bar.grab);
},
// 提交进度:同上,每题只动条,不动题目
setSubmit: function(done, total, sub, bad) {
this._bar.submit = { done: done || 0, bad: bad || 0, total: total || 0, sub: sub || '' };
this._barPaintOnly('submit', this._bar.submit);
},
_barPaintOnly: function(name, st) {
if (!this._el) {
if (!this.isOn()) return; // 窗口关着就别为进度条把窗口拽出来
this.ensure();
}
this._paintBar(name, st);
},
// 左绿(成功)/ 右红(失败)/ 中间灰(未做),与习题集 1.2.2 同一套读法
_paintBar: function(name, st) {
const el = this._el;
if (!el) return;
const okEl = el.querySelector('#aw-' + name + '-ok');
const badEl = el.querySelector('#aw-' + name + '-bad');
const txt = el.querySelector('#aw-' + name + '-txt');
const num = el.querySelector('#aw-' + name + '-num');
const sub = el.querySelector('#aw-' + name + '-sub');
if (!okEl) return;
const t = st.total > 0 ? st.total : 0;
const fin = (st.done || 0) + (st.bad || 0);
okEl.style.width = t ? ((st.done || 0) / t * 100).toFixed(2) + '%' : '0';
badEl.style.width = t ? ((st.bad || 0) / t * 100).toFixed(2) + '%' : '0';
if (name === 'answer') {
const aiEl = el.querySelector('#aw-answer-ai');
const ai = Math.min(st.done || 0, st.ai || 0);
const bank = (st.done || 0) - ai;
okEl.style.width = t ? (bank / t * 100).toFixed(2) + '%' : '0';
if (aiEl) {
aiEl.style.left = t ? (bank / t * 100).toFixed(2) + '%' : '0';
aiEl.style.width = t ? (ai / t * 100).toFixed(2) + '%' : '0';
}
}
if (txt) txt.textContent = t ? `${fin}/${t} · ${Math.round(fin / t * 100)}%` : '—';
// 右上角直接给「数量」:抓题条是节数,答题/提交条是题数;失败数在下方说明行里
if (num) num.textContent = t ? `${fin}/${t} ${name === 'grab' ? '节' : '题'}` : '—';
if (sub) {
sub.textContent = st.sub || '';
sub.classList.toggle('done', t > 0 && fin >= t && !st.bad);
}
},
// ---- 日志文本框:直接吃 Logger.buffer,180ms 节流重绘,默认滚底 ----
_autoScroll: true,
_logTimer: null,
pushLog: function() {
if (this._logTimer) return;
this._logTimer = setTimeout(() => { this._logTimer = null; this._renderLog(); }, 180);
},
_renderLog: function() {
const el = this._el;
if (!el || !this.isOn()) return; // 窗口没开就别刷(刷了也看不见,白费 DOM 变动)
const box = el.querySelector('#aw-log');
if (!box) return;
const buf = (Logger && Logger.buffer) ? Logger.buffer.slice(-80) : [];
if (!buf.length) { box.textContent = ''; return; }
const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c]));
box.innerHTML = buf.map((e) => {
const cls = e.type === 'success' ? 'lg-ok'
: e.type === 'error' ? 'lg-err'
: e.type === 'ai' ? 'lg-ai' : 'lg-ms';
const detail = (currentConfig.logDetail && e.detail)
? '\n ' + esc(String(e.detail).split('\n').join('\n ')) : '';
return `${esc(e.time)} ${esc(e.message)}${detail}`;
}).join('\n');
if (this._autoScroll) box.scrollTop = box.scrollHeight;
},
render: function() {
if (!this.isOn()) return;
const el = this.ensure();
const d = this._data;
const t = { single: '单选', multiple: '多选', judgment: '判断', batch: '批量' }[d && d.type] || '—';
// 批量模式没有"第几题"的概念,显示共几题更有意义
el.querySelector('#aw-count').textContent = d
? (d.type === 'batch' ? `共 ${d.index} 题` : `第 ${d.index}/${d.total} 题`)
: '—';
el.querySelector('#aw-type').textContent = t;
const src = el.querySelector('#aw-src');
src.textContent = (d && d.source) || '待作答';
src.dataset.src = (d && d.source) || '';
el.querySelector('#aw-stem').textContent = d ? d.stem : '等待题目…';
const box = el.querySelector('#aw-opts');
box.innerHTML = '';
if (d) {
d.options.forEach((o) => {
const b = document.createElement('div');
b.className = 'aw-opt' + (d.picked.indexOf(o.letter) >= 0 ? ' picked' : '');
b.textContent = `${o.letter}. ${o.text}`;
box.appendChild(b);
});
}
el.querySelector('#aw-now').textContent = this._line.now;
el.querySelector('#aw-last').textContent = this._line.last;
this._paintBar('grab', this._bar.grab);
this._paintBar('answer', this._bar.answer);
this._paintBar('submit', this._bar.submit);
},
setLine: function(now, last) {
this._line.now = now || '待命';
if (last !== undefined) this._line.last = last;
this.render();
},
// 【3.1.1】setQuestion / setPicked / setResult / waitManualSubmit / submitManual
// 随手动作答链路整体删除:自动流水线只用三条进度条 + setLine 汇报状态。
setSource: function(s) { if (this._data) { this._data.source = s; this.render(); } }
};
// ============================ 全课抓题(免切课,1.2.2 移植) ============================
// 2026-11-05 实测(见 docs 交接):页面课程树组件 .ant-tree 的 __vue__ 向上第 3 层有
// $data.treeData,13 章 / 121 节,每节的 key 就是该节的 courseSource id(与地址栏 id= 同一套)。
// 逐节 GET queryCourseQuestionRelaByMainId 即可一次拉完全部题目,不点节点、不切课。
// 实测 150ms 串行:121 节 / 213 题 / 31 秒 / 0 报错。
// ⚠️ 不要按 DOM 逐个 li 读 __vue__:嵌套 li 会指回父章节节点,读出来全是章名。
const CourseScanner = {
_bank: null, // Map
_flat: null, // [{chapter, num, name, courseId, lesson}]
_chapters: [], // [{num, title, lessons:[{name, courseId, questions[]}]}] —— 按章提交用
_running: false,
_scanned: false,
_done: 0,
_total: 0,
_qCount: 0,
gap: 150, // 每节之间间隔(ms)
bank: function() {
if (!this._bank) this._bank = new Map();
return this._bank;
},
readTreeData: function() {
try {
const el = document.querySelector('.ant-tree');
let v = el && el.__vue__;
let hops = 0;
while (v && hops < 16) {
hops++;
const d = v.$data || {};
if (Array.isArray(d.treeData) && d.treeData.length) return d.treeData;
v = v.$parent;
}
} catch (e) { /* 读不到就回退 */ }
return null;
},
flatLessons: function(td) {
const out = [];
(td || []).forEach((ch) => {
const kids = Array.isArray(ch && ch.children) ? ch.children : [];
kids.forEach((n) => {
if (n && n.key) {
out.push({ chapter: String(ch.title || ''), name: String(n.title || ''), courseId: String(n.key) });
}
});
});
return out;
},
// 已扫到就直接取,不再发请求
questionsOf: function(courseId) {
const b = this.bank();
return b.has(String(courseId)) ? b.get(String(courseId)) : null;
},
chapterCount: function() {
const td = this.readTreeData();
return td ? td.filter((ch) => Array.isArray(ch.children) && ch.children.length).length : 0;
},
// opts.onLesson(sec):每抓完一节就回调一次 {chapter, lesson, courseId, questions}
// —— 全课自动答题靠它做「有题就答」的流水线,不必等 121 节全部抓完。
scan: async function(opts) {
const onLesson = (opts && typeof opts.onLesson === 'function') ? opts.onLesson : null;
if (this._running) return;
VideoApiAnswer.readContext();
const gid = VideoApiAnswer.graphId;
if (!gid) {
Logger.add('error', '抓题:未取到 graphId', '请进入「我的课程 → 某门课」详情页(地址带 graphId=)');
AnswerWindow.setGrab(0, 0, '未取到 graphId');
return;
}
const td = this.readTreeData();
if (!td) {
Logger.add('error', '抓题:未读到页面课程树(treeData)', '需在 courseDetail 页、且课程树已展开过');
AnswerWindow.setGrab(0, 0, '未读到课程树');
return;
}
// 按章分组保留结构(照习题集:chapters → lessons → questions),提交时一章一章走
this._chapters = td
.filter((ch) => Array.isArray(ch.children) && ch.children.length)
.map((ch, ci) => ({
num: String(ci + 1),
title: String(ch.title || ''),
lessons: ch.children.filter((n) => n && n.key).map((n) => ({
name: String(n.title || ''),
courseId: String(n.key),
questions: []
}))
}));
const flat = [];
this._chapters.forEach((ch) => ch.lessons.forEach((l) => flat.push({
chapter: ch, num: ch.num, name: l.name, courseId: l.courseId, lesson: l
})));
if (!flat.length) {
Logger.add('error', '抓题:课程树里没解析到小节', 'treeData 有 ' + td.length + ' 个顶层节点');
AnswerWindow.setGrab(0, 0, '没有小节');
return;
}
this._flat = flat;
this._total = flat.length;
this._done = 0;
this._qCount = 0;
this._running = true;
const chapters = this.chapterCount();
Logger.milestone(`抓题开始:${chapters} 章 / ${flat.length} 节|间隔 ${this.gap}ms|免切课、不点节点`);
AnswerWindow.setGrab(0, this._total, `0 节 · 0 题`);
let fail = 0, empty = 0;
for (let i = 0; i < flat.length; i++) {
const it = flat[i];
try {
const qs = await VideoApiAnswer.fetchQuestions(it.courseId, gid);
this.bank().set(it.courseId, qs);
if (it.lesson) it.lesson.questions = qs; // 写回章结构,供按章提交
this._qCount += qs.length;
if (!qs.length) empty++;
// 流水线:本节题一落地就交给上层(答题/提交 worker 立刻开工)
if (onLesson) {
try { onLesson({ chapter: it.chapter, lesson: it.lesson, courseId: it.courseId, questions: qs }); }
catch (e) { Logger.add('error', '抓题回调异常:' + it.name, String((e && e.message) || e).slice(0, 80)); }
}
} catch (e) {
fail++;
Logger.add('error', '抓题失败:' + it.name, String(e && e.message || e).slice(0, 80));
}
this._done = i + 1;
AnswerWindow.setGrab(this._done, this._total, `${this._qCount} 题 · 空 ${empty} 节 · 失败 ${fail} 节`, fail);
if (this._done % 10 === 0 || this._done === this._total) {
Logger.milestone(`抓题 ${this._done}/${this._total}|已得 ${this._qCount} 题`);
}
if (i < flat.length - 1) await new Promise((r) => setTimeout(r, this.gap));
}
this._running = false;
this._scanned = true;
Logger.milestone(`抓题完成:${this._total} 节 / ${this._qCount} 题|空 ${empty} 节、失败 ${fail} 节`);
AnswerWindow.setGrab(this._total, this._total, `${this._qCount} 题 · 完成`);
// 题量变了 ⇒ 提交进度条的全课分母跟着更新(完成度按已记绿/记红的题算)
try { CourseProgress.paint(); } catch (e) {}
},
// 只扫当前节(不进全课循环时用)
scanOne: async function(courseId) {
VideoApiAnswer.readContext();
const qs = await VideoApiAnswer.fetchQuestions(courseId, VideoApiAnswer.graphId);
this.bank().set(String(courseId), qs);
this._qCount = this._qCount + qs.length;
AnswerWindow.setGrab(this._scanned ? this._total : 1, this._scanned ? this._total : 1,
`${this._qCount} 题 · 仅本节`);
return qs;
}
};
// ============================ 全课进度(提交条的口径) ============================
// bdm 2026-11-06 定:提交进度条不再只算「本节几题」,而是全课所有题的进度预览。
// 一道题走完「答题(拿到答案)→ 提交(POST 成功)」两步才记绿;提交失败记红;没碰过是灰。
// 已答跳过(账本命中)的题一律记绿 —— 它们本来就是之前提交成功的。
const CourseProgress = {
okIds: null,
badIds: null,
ansIds: null, // 已取到答案的题(答题条口径)
ansBad: null, // 取答案失败的题(答题条红段)
aiIds: null,
targetCount: null,
init: function() {
if (!this.okIds) this.okIds = new Set();
if (!this.badIds) this.badIds = new Set();
if (!this.ansIds) this.ansIds = new Set();
if (!this.ansBad) this.ansBad = new Set();
if (!this.aiIds) this.aiIds = new Set();
return this;
},
// 答完一题(拿到答案);只有真拿到 letter 才记,记过的不重复记
answered: function(id, source) {
this.init();
const k = String(id);
if (this.ansIds.has(k)) return;
this.ansBad.delete(k);
this.ansIds.add(k);
if (source === 'ai') this.aiIds.add(k);
this.paintAnswer();
},
// 取答案失败一题(服务端报错 / AI 没回 / 空答案)
answerFail: function(id) {
this.init();
const k = String(id);
if (this.ansIds.has(k) || this.ansBad.has(k)) return;
this.ansBad.add(k);
this.paintAnswer();
},
// 答题条:分母 = 已抓到的题量(抓题还在跑时会一直涨)
paintAnswer: function() {
this.init();
const t = this.targetCount == null ? (CourseScanner._qCount || 0) : this.targetCount;
const ok = this.ansIds.size;
const bad = this.ansBad.size;
const ai = this.aiIds.size;
const sub = `成功 ${ok}(题库 ${ok - ai}|AI ${ai})|失败 ${bad}|总题 ${t}`;
AnswerWindow.setAnswer(ok, Math.max(t, ok + bad), sub, bad, ai);
},
// 总题数:抓过全课就用抓题得到的题量;没抓过就按已见题量兜底
total: function() {
this.init();
return Math.max(this.targetCount == null ? (CourseScanner._qCount || 0) : this.targetCount, this.okIds.size + this.badIds.size);
},
done: function(id) {
this.init();
const k = String(id);
this.badIds.delete(k);
this.okIds.add(k);
this.paint();
},
fail: function(id) {
this.init();
const k = String(id);
this.badIds.add(k);
this.paint();
},
forget: function(id) {
this.init();
const k = String(id);
this.okIds.delete(k);
this.badIds.delete(k);
},
reset: function() {
this.okIds = new Set();
this.badIds = new Set();
this.ansIds = new Set();
this.ansBad = new Set();
this.aiIds = new Set();
this.targetCount = null;
this.paint();
this.paintAnswer();
},
paint: function() {
this.init();
const t = this.total();
const ok = this.okIds.size;
const bad = this.badIds.size;
const left = Math.max(0, t - ok - bad);
const sub = t
? `全课 ${t} 题|完成 ${ok + bad}|剩 ${left}`
: `已提交 ${ok} 题`;
AnswerWindow.setSubmit(ok, t, sub, bad);
}
};
// ============================ 提交(照抄习题集 1.2.2) ============================
// 平台限流判定:只有这一种失败值得等;其它失败(参数错 / 无权限 / 题号不存在)
// 重试多少次都不会变好,直接记失败,不空转。
function isRateLimited(res) {
try { return /请求频繁|稍后重试|too many|rate limit/i.test(JSON.stringify(res || {})); }
catch (e) { return false; }
}
const _sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// 提交一批题。onProgress(done, ok, fail, total) 逐题回调 —— 进度条就是靠它驱动的。
// 与习题集 1.2.2 的 submitItems 逐行同构,只是接口换成 3.0 的 VideoApiAnswer.submit。
async function submitItems(items, onProgress) {
const graphId = VideoApiAnswer.graphId || '';
const paidFor = await AuthService.billingScope(graphId);
const total = items.length;
const gap = Math.max(200, Number(currentConfig.submitGap) || 3500);
const maxRetry = Math.max(1, Number(currentConfig.submitRetry) || 3);
let ok = 0, fail = 0, skip = 0, done = 0;
const report = () => { if (onProgress) { try { onProgress(done, ok, fail, total); } catch (e) { /* UI 异常不影响提交 */ } } };
report();
for (const item of items) {
const ready = AuthService.ensureReady(true);
if (!ready.ok || item.paidFor !== paidFor) {
Logger.add('error', `提交已停止:${ready.error || '该答案尚未经当前卡密计费,请重新取答案'}`);
fail += total - done;
report();
break;
}
const letters = Array.isArray(item.letters) ? item.letters : [];
if (!letters.length) {
Logger.add('info', `跳过提交|题号 ${item.q.id}:答案为空`);
skip++; done++; report(); continue;
}
let success = false;
let failure = '平台无响应';
for (let attempt = 0; attempt < maxRetry; attempt++) {
let res = null;
try { res = await VideoApiAnswer.submit(item.q, letters, item.courseId, graphId); }
catch (e) { res = { message: String(e && e.message || e) }; }
if (res && (res.success === true || res.code === 200)) { success = true; break; }
failure = res ? String(res.message || res.msg || res.code || '平台未返回失败原因').replace(/\s+/g, ' ').trim() : '平台无响应';
if (!isRateLimited(res) || attempt + 1 >= maxRetry) break;
Logger.add('info', `提交限流|题号 ${item.q.id}:${failure},${3 * (attempt + 1)} 秒后重试(${attempt + 1}/${maxRetry - 1})`);
await _sleep(3000 * (attempt + 1)); // 3 / 6 / 9 秒:平台限流约 6 秒恢复,等够再试
}
if (success) {
ok++;
// 【2026-11-06 对齐习题集】记账无条件:只要平台确认成功就写账本,
// 与「跳过已答」开关无关。开关只决定「要不要拿账本来跳过」,
// 若记账也受开关控制,关一次开关跑完 → 账本是空的 → 下次开开关全量重发 → 已答题被判错。
AnsweredStore.add(item.q.id);
try { VideoApiAnswer.submitted.add(item.q.id); } catch (e) {}
Logger.add('success', `提交成功|题号 ${item.q.id}|答案 ${letters.join('')}`);
} else {
fail++;
Logger.add('error', `提交失败|题号 ${item.q.id}|答案 ${letters.join('')}:${failure}`);
}
done++;
report();
await _sleep(gap);
}
return { ok: ok, fail: fail, skip: skip };
}
// ============================ 按章提交(照习题集 Submitter) ============================
// 习题集是「一章一章」提交的:章节结构里拍平该章所有节的题 → 一次拿答案 → submitItems 逐题 POST。
// 3.0 现在也走这条路:抓完整课,然后 13 章逐章跑,不再依赖当前停在哪一节。
const CourseSubmitter = {
_running: false,
_sum: { ok: 0, bad: 0, total: 0, chapters: 0 },
itemsOfChapter: function(ch) {
const out = [];
(ch.lessons || []).forEach((l) => {
(l.questions || []).forEach((q) => {
const info = VideoApiAnswer.normalizeQuestion(q);
if (!info.text || !info.options.length) return;
out.push({ q: q, info: info, courseId: l.courseId, lesson: l.name });
});
});
return out;
},
// 所有答案统一经服务端授权、查库和计费,本地错题只用于纠正上报。
resolve: async function(items, graphId) {
const need = [], map = new Map();
items.forEach((it, i) => {
it.letters = [];
it.seq = i + 1;
need.push({
seq: it.seq, stem: it.info.text,
options: it.info.options.map((o) => ({ letter: o.letter, text: o.text })),
kind: String(it.q.kind || ''), type: it.info.type
});
map.set(it.seq, it);
});
if (!need.length) return { lib: 0, ai: 0, cost: 0 };
const ready = await AuthService.ensureReady();
if (!ready.ok) return { error: ready.error || '授权校验未通过' };
const res = await AuthService.answerBatch(graphId, need);
if (!res || !res.success) return { error: res ? `${res.code || 'ERROR'}:${res.msg || '服务端未说明原因'}` : '服务端无响应' };
const data = res.data || {};
const paidFor = await AuthService.billingScope(graphId);
(data.answers || []).forEach((a) => {
const it = map.get(Number(a.seq));
if (!it) return;
const letters = [...new Set(String(a.answer || '').toUpperCase().split('').filter((c) => /[A-Z]/.test(c)))];
if (!letters.length || letters.some(c => !it.info.options.some(o => o.letter === c))
|| (it.info.type !== 'multiple' && letters.length !== 1)) return;
it.letters = letters;
it.source = a.source;
it.paidFor = paidFor;
});
if (data.balance_cent !== undefined) {
const cached = AuthService.getCachedStatus();
if (cached) { cached.balance_cent = data.balance_cent; AuthService.setCachedStatus(cached); }
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
}
return { lib: data.lib_hits || 0, ai: data.asked_ai || 0, cost: data.cost_cent || 0,
errorDetail: data.ai_error || '' };
},
chapter: async function(ch, label, sum, graphId) {
const all = this.itemsOfChapter(ch);
if (!all.length) { Logger.milestone(`${label}|第 ${ch.num} 章「${ch.title}」没有题,跳过`); return; }
let todo = all;
let skipped = 0;
if (currentConfig.skipAnswered) {
todo = all.filter((it) => {
if (AnsweredStore.has(it.q.id)) { skipped++; return false; }
return true;
});
}
Logger.milestone(`${label}|第 ${ch.num} 章「${ch.title}」|${all.length} 题${skipped ? `(已答跳过 ${skipped})` : ''}`);
AnswerWindow.setSubmit(sum.ok, sum.total,
`${label}|第 ${ch.num} 章 ${todo.length} 题 · 取答案中`, sum.bad);
if (!todo.length) {
Logger.milestone(`第 ${ch.num} 章全部已提交过,跳过`);
return;
}
const got = await this.resolve(todo, graphId);
if (got.error) {
Logger.add('error', `第 ${ch.num} 章取答案失败:${String(got.error).replace(/\s+/g, ' ').trim()}`);
sum.bad += todo.length;
AnswerWindow.setSubmit(sum.ok, sum.total, `${label}|第 ${ch.num} 章 取答案失败`, sum.bad);
return;
}
Logger.milestone(`第 ${ch.num} 章答案就绪:题库命中 ${got.lib},问 AI ${got.ai},扣 ${got.cost} 分`);
const r = await submitItems(
todo.map((it) => ({ q: it.q, courseId: it.courseId, letters: it.letters || [], paidFor: it.paidFor })),
(done, ok, fail, total) => {
AnswerWindow.setSubmit(sum.ok + ok, sum.total,
`${label}|第 ${ch.num} 章 ${done}/${total} · 成功 ${ok} 失败 ${fail}`, sum.bad + fail);
}
);
sum.ok += r.ok;
sum.bad += r.fail;
Logger.milestone(`第 ${ch.num} 章提交:成功 ${r.ok} / 失败 ${r.fail}${r.skip ? ` / 空答案 ${r.skip}` : ''}`);
AnswerWindow.setSubmit(sum.ok, sum.total,
`第 ${ch.num} 章完成 · 成功 ${r.ok} 失败 ${r.fail}`, sum.bad);
},
all: async function() {
if (this._running) { utils.showMessage('提交进行中,别重复点', 'info'); return; }
VideoApiAnswer.readContext();
const gid = VideoApiAnswer.graphId;
const chapters = (CourseScanner._chapters || []).slice();
if (!chapters.length) {
Logger.add('error', '全课提交:还没抓题', '先点「全课抓题」把 121 节的题抓下来');
utils.showMessage('先点「全课抓题」', 'warning');
return;
}
if (!gid) { utils.showMessage('未取到 graphId', 'warning'); return; }
this._running = true;
this._abort = false; // 每次开跑先清停止标志(FullCourseRunner.stop 会置 true)
const totalQ = chapters.reduce((n, ch) => n + this.itemsOfChapter(ch).length, 0);
const sum = { ok: 0, bad: 0, total: totalQ };
this._sum = sum;
AnswerWindow.setOn(true); AnswerWindow.show();
Logger.milestone(`全课提交开始:${chapters.length} 章 / ${totalQ} 题|间隔 ${currentConfig.submitGap}ms`);
AnswerWindow.setSubmit(0, totalQ, `0/${totalQ} · 准备 ${chapters.length} 章`);
try {
for (let i = 0; i < chapters.length; i++) {
if (this._abort) { Logger.milestone(`全课提交:收到停止,已跑完 ${i} 章,剩余 ${chapters.length - i} 章未动`); break; }
await this.chapter(chapters[i], `第 ${i + 1}/${chapters.length} 章`, sum, gid);
}
} catch (e) {
Logger.add('error', '全课提交异常', String(e && e.message || e));
}
this._running = false;
const done = sum.ok + sum.bad;
Logger.milestone(`全课提交完成:共 ${totalQ} 题|成功 ${sum.ok}、失败 ${sum.bad}`);
AnswerWindow.setSubmit(sum.ok, totalQ,
sum.bad ? `完成 · 成功 ${sum.ok} 失败 ${sum.bad}` : `全部成功 ${sum.ok}`, sum.bad);
utils.showMessage(`全课提交完成:成功 ${sum.ok},失败 ${sum.bad}`, sum.bad ? 'warning' : 'success');
}
};
// ============================ 未提交存货(3.1.1 · 落盘续跑) ============================
// 答案取到但还没提交的题,连同答案一起写 GM(按 graphId 分桶)。
// 刷新/中断后 start() 把存货灌回提交队列,autoSubmit 开着就自动续交;
// 提交成功或确认已答即出库,失败保留等下轮重试。
const PendingStore = {
KEY: 'ls3_pending_v1',
data: null,
load: function() {
if (this.data === null) {
try { this.data = GM_getValue(this.KEY, {}) || {}; } catch (e) { this.data = {}; }
}
return this.data;
},
save: function() { try { GM_setValue(this.KEY, this.data); } catch (e) {} },
bucket: function() {
const gid = String(VideoApiAnswer.graphId || '');
const all = this.load();
if (!all[gid]) all[gid] = {};
return all[gid];
},
has: function(id) { return !!this.bucket()[String(id)]; },
put: function(item) { this.bucket()[String(item.q.id)] = item; this.save(); },
remove: function(id) {
const b = this.bucket();
if (b[String(id)]) { delete b[String(id)]; this.save(); }
},
items: function() { return Object.values(this.bucket()); },
size: function() { return Object.keys(this.bucket()).length; }
};
// ============================ 全课自动答题(3.1.0 · 三阶段流水线) ============================
// bdm 定的行为:答题与抓题脚本一致 —— 全课抓题、逐题取答案、逐题提交,
// 不点课程树、不播视频、不等平台弹窗;视频那条由 Pusher 独立跑,两边互不影响。
// 3.1.1 起不再「抓完再答」:抓题每扫完一节就把该节题推进答题队列,
// 答案一就绪就推进提交队列 —— 三条进度条各推各的,整体耗时 ≈ 提交耗时。
// 触发:页面加载 3 秒后自动跑一轮;面板「一键完成课程中所有题目」随时手动重跑(跑动中变「停止本轮」)。
const FullCourseRunner = {
_running: false,
_rounds: 0, // 本页已跑轮数:同一页只自动跑一轮,重复触发直接忽略
_stop: false,
_ansQ: [], // 待取答案:{q, info, courseId, chap, chapTitle}
_subQ: [], // 待提交:同上 + letters
_scanDone: false, // 抓题结束(答题 worker 靠它判断该不该收工)
_ansDone: false, // 答题结束(提交 worker 靠它判断该不该收工)
_batch: 20, // 每次问服务端的题量
_paused: false, // autoSubmit 关着时提交 worker 处于暂停态(只报一次日志)
_stockIds: null, // 落盘存货里已入队的题号(防止存货与抓题重复入队)
// 前置体检:拿不到 graphId / token 就静默退出,避免在 myCourse 页刷一堆报错
_blockReason: function() {
try { VideoApiAnswer.readContext(); } catch (e) { /* 读不到就按缺条件处理 */ }
if (!VideoApiAnswer.graphId) return '未取到 graphId(需在课程详情页)';
if (!VideoApiAnswer.token) return '未取到登录 token';
return '';
},
start: async function(reason) {
if (this._running) { Logger.add('info', '全课自动答题:已在跑,忽略重复触发'); return; }
if (this._rounds >= 1 && reason !== 'manual') return;
const why = this._blockReason();
if (why) { utils.log(`全课自动答题未启动:${why}`); return; }
const ready = AuthService.ensureReady();
if (!ready.ok) { ControlPanel.updateAnswerAccess(); return; }
this._running = true;
this._rounds++;
this._stop = false;
this._ansQ = [];
this._subQ = [];
this._scanDone = false;
this._ansDone = false;
this._paused = false;
this._stockIds = new Set();
this._selectedIds = new Set();
this._syncOneKeyBtn(true);
const gid = VideoApiAnswer.graphId;
try {
const live = await AuthService.refreshStatus();
if (!live || !AuthService.ensureReady().ok) {
Logger.add('error', '答题未启动:授权状态校验失败,请刷新卡密状态');
return;
}
if (currentConfig.reviewData && currentConfig.reviewData !== '{}') {
const reported = await ReviewCollector.reportToServer(JSON.parse(currentConfig.reviewData));
if (currentConfig.reanswerOnly && !reported) {
Logger.add('error', '错题重答未启动:纠正答案上报失败,请检查网络后重试');
return;
}
}
const paidFor = await AuthService.billingScope(gid);
// 只有当前卡密、账号、课程已付费的存货可以续交,旧版本地直出重新取答案。
const stock = PendingStore.items();
stock.forEach((it) => {
if (!it || !it.q || !it.letters || !it.letters.length) return;
if (it.paidFor !== paidFor) return;
if (currentConfig.reanswerOnly && !VideoApiAnswer.lookupLocalAnswer(VideoApiAnswer.normalizeQuestion(it.q).text)) return;
this._subQ.push(it);
this._stockIds.add(String(it.q.id));
});
if (this._subQ.length) {
Logger.milestone(`落盘续跑:${this._subQ.length} 题已有答案未提交,直接入提交队列`);
}
CourseProgress.reset();
CourseProgress.targetCount = currentConfig.reanswerOnly ? 0 : null;
AnswerWindow.setOn(true);
AnswerWindow.show();
AnswerWindow.setAnswer(0, 0, '待命');
Logger.milestone(`全课自动答题开始(${reason}):有题就答、有答案就提交|每批 ${this._batch} 题`);
// 两个 worker 先起来,抓题一边抓一边往队列里喂(真正的流水线)
const pAns = this._answerer(gid);
const pSub = this._submitter();
if (!CourseScanner._chapters.length) {
if (currentConfig.expandChapters) {
try { await ChapterExpander.expandParentNodes(); } catch (e) { /* 展开失败仍尝试读 treeData */ }
}
Logger.milestone('全课自动答题:开始全课抓题…');
await CourseScanner.scan({ onLesson: (sec) => this._feed(sec) });
} else {
// 复用已抓题单:一次性喂进队列,后面照样流水线走
Logger.milestone(`全课自动答题:复用已抓题单 ${CourseScanner._qCount} 题`);
(CourseScanner._chapters || []).forEach((ch) => {
(ch.lessons || []).forEach((l) => {
this._feed({ chapter: ch, lesson: l, courseId: l.courseId, questions: l.questions || [] });
});
});
}
this._scanDone = true;
if (!CourseScanner._chapters.length) {
Logger.add('error', '全课自动答题中止:题单为空', '抓题没拿到东西,请手点「全课抓题」排查 treeData');
utils.showMessage('全课自动答题中止:没抓到题', 'error', 6000);
this._ansDone = true;
return;
}
await pAns;
this._ansDone = true;
await pSub;
const sum = this._summary();
Logger.milestone(`全课自动答题结束:取答案成功 ${sum.ans} 题、失败 ${sum.ansBad} 题|提交成功 ${sum.ok}、失败 ${sum.bad}`);
AnswerWindow.setLine('全课答题完成', sum.bad ? `失败 ${sum.bad} 题,可在「答题」页重跑` : `全部成功 ${sum.ok} 题`);
utils.showMessage(`全课答题结束:提交成功 ${sum.ok},失败 ${sum.bad}`, sum.bad ? 'warning' : 'success', 6000);
} catch (e) {
Logger.add('error', '全课自动答题异常', String((e && e.message) || e));
} finally {
this._running = false;
this._syncOneKeyBtn(false);
}
},
// 「一键完成课程中所有题目」按钮跑动中变「停止本轮」,停了变回来(面板可能重建,每次现查 DOM)
_syncOneKeyBtn: function(running) {
const b = document.getElementById('one-key-btn');
if (!b) return;
b.dataset.running = String(running);
b.textContent = running ? '停止本轮' : '一键完成课程中所有题目';
},
_summary: function() {
return {
ans: CourseProgress.ansIds ? CourseProgress.ansIds.size : 0,
ansBad: CourseProgress.ansBad ? CourseProgress.ansBad.size : 0,
ok: CourseProgress.okIds ? CourseProgress.okIds.size : 0,
bad: CourseProgress.badIds ? CourseProgress.badIds.size : 0
};
},
// 一节题到手 → 逐题入「待取答案」队列(账本命中直接记绿,不进队列)
_feed: function(sec) {
const ch = sec.chapter || {};
(sec.questions || []).forEach((q) => {
if (this._stop) return;
const id = String(q.id);
if (currentConfig.reanswerOnly && !VideoApiAnswer.lookupLocalAnswer(VideoApiAnswer.normalizeQuestion(q).text)) return;
if (this._selectedIds.has(id)) return;
this._selectedIds.add(id);
if (currentConfig.reanswerOnly) CourseProgress.targetCount = this._selectedIds.size;
if (!currentConfig.reanswerOnly && currentConfig.skipAnswered && AnsweredStore.has(id)) {
CourseProgress.answered(id, 'bank');
CourseProgress.done(id);
return;
}
// 落盘存货里已有答案的题:已在提交队列里(start 时灌入),不重问服务端
if (this._stockIds && this._stockIds.has(id)) {
CourseProgress.answered(id, 'bank');
return;
}
const info = VideoApiAnswer.normalizeQuestion(q);
if (!info.text || !info.options.length) { CourseProgress.answerFail(id); return; }
this._ansQ.push({
q: q, info: info, courseId: sec.courseId,
chap: ch.num || '', chapTitle: ch.title || ''
});
});
CourseProgress.paintAnswer();
},
// Worker A:取答案。整批问一次服务端(本地错题库先命中,未命中才问 AI)
_answerer: async function(gid) {
while (!this._stop) {
if (!this._ansQ.length) {
if (this._scanDone) return;
await _sleep(250);
continue;
}
const batch = this._ansQ.splice(0, this._batch);
const done = CourseProgress.ansIds.size;
AnswerWindow.setAnswer(done, Math.max(CourseProgress.total(), done + CourseProgress.ansBad.size + this._ansQ.length),
`取答案中|队里还剩 ${this._ansQ.length} 题`, CourseProgress.ansBad.size, CourseProgress.aiIds.size);
const got = await CourseSubmitter.resolve(batch, gid);
if (got && got.error) {
batch.forEach((it) => CourseProgress.answerFail(it.q.id));
Logger.add('error', `取答案失败一批:${String(got.error).replace(/\s+/g, ' ').trim()}`);
continue;
}
let filled = 0;
batch.forEach((it) => {
if (it.letters && it.letters.length) {
CourseProgress.answered(it.q.id, it.source);
filled++;
PendingStore.put(it); // 落盘:刷新/中断后凭这份数据续跑
this._subQ.push(it);
} else {
CourseProgress.answerFail(it.q.id);
}
});
Logger.milestone(`答案就绪 ${filled}/${batch.length} 题(题库命中 ${got.lib || 0}|问 AI ${got.ai || 0})`);
if (filled < batch.length) Logger.add('error', `取答案失败 ${batch.length - filled} 题:${got.errorDetail || '服务端未返回可用答案(缺失题号、空答案或选项不符)'}`);
}
},
// Worker B:提交。单题串行,submitItems 内部已含 3.5s 间隔 + 限流退避 + 已答记账
// 「答题后自动提交」= 提交队列的暂停/续交键:关着就不消费(存货全留 GM),
// 重新打开原地续交;答案已落盘,此时刷新页面也不丢。
_submitter: async function() {
while (!this._stop) {
if (!currentConfig.autoSubmit) {
// 没存货没队、答案也取完了:没啥可暂停的,直接收工(比如全课已答过的重跑)
if (this._ansDone && !this._subQ.length) return;
if (!this._paused) {
this._paused = true;
AnswerWindow.setSubmit(CourseProgress.okIds.size, Math.max(CourseProgress.total(), this._subQ.length),
`已暂停:答题后自动提交=关(存货 ${this._subQ.length} 题保留在盘)`, CourseProgress.badIds.size);
Logger.milestone(`自动提交已关:提交暂停,存货 ${this._subQ.length} 题保留;打开「答题后自动提交」即续交`);
}
await _sleep(500);
continue;
}
this._paused = false;
if (!this._subQ.length) {
if (this._ansDone) return;
await _sleep(250);
continue;
}
const it = this._subQ.shift();
// 提交前再查一次账本(习题集 pendingOf 的做法):排队期间可能已被别处提交成功,
// 已答的题**绝不能再 POST** —— 平台对已答题目重发会判错,跳过则不会。
if (!currentConfig.reanswerOnly && currentConfig.skipAnswered && AnsweredStore.has(it.q.id)) {
CourseProgress.answered(it.q.id, it.source);
CourseProgress.done(it.q.id);
PendingStore.remove(it.q.id); // 已答确认:存货出库
continue;
}
if (!it.letters || !it.letters.length) {
// 空答案不提交:submitItems 里也有一道同样的闸,这里提前拦,省一次无意义调用
CourseProgress.answerFail(it.q.id);
PendingStore.remove(it.q.id);
continue;
}
const r = await submitItems(
[{ q: it.q, courseId: it.courseId, letters: it.letters, paidFor: it.paidFor }],
(d, ok, fail) => {
AnswerWindow.setSubmit(CourseProgress.okIds.size + ok, CourseProgress.total(),
`提交中|队里还剩 ${this._subQ.length} 题`, CourseProgress.badIds.size + fail);
}
);
if (r.ok) { CourseProgress.done(it.q.id); PendingStore.remove(it.q.id); }
else { CourseProgress.fail(it.q.id); } // 失败留存货,下轮/续跑重试
}
},
// 停止:置标志,两个 worker 在下一轮循环退出(当前这一题/这一批会走完)
stop: function() {
this._stop = true;
Logger.milestone('全课自动答题:收到停止指令,当前这批走完即止');
}
};
// ============================ 答题处理逻辑 (完整还原) ============================
const QuestionProcessor = {
extractQuestionInfo: function(popup) {
const info = { type: null, text: '', options: [] };
try {
const titleElement = popup.querySelector('.sub-title');
if (titleElement) {
const txt = titleElement.textContent;
info.text = utils.cleanText(utils.removeHtml(txt)).replace(/^[((]?(判断题|单选题|多选题)[))][::]?\s*/, '');
if (txt.includes('判断题')) info.type = 'judgment';
else if (txt.includes('单选题')) info.type = 'single';
else if (txt.includes('多选题')) info.type = 'multiple';
}
const optElems = popup.querySelectorAll('.ant-checkbox-wrapper, .ant-radio-wrapper');
optElems.forEach((opt, index) => {
let optTxt = (opt.querySelector('.option') ? opt.querySelector('.option').textContent : opt.textContent).trim();
optTxt = optTxt.replace(/^[A-D][::\.、]\s*/, '').replace(/^[0-9][::\.、]\s*/, '');
if (optTxt) info.options.push({ index, text: optTxt, inputElement: opt.querySelector('input'), element: opt });
});
return info;
} catch (e) { return null; }
},
generateRandomAnswer: function(info) {
if (info.type === 'judgment') return Math.random() > 0.5 ? ['正确'] : ['错误'];
if (info.type === 'single' && info.options.length) return [info.options[Math.floor(Math.random() * info.options.length)].text];
if (info.type === 'multiple' && info.options.length) {
const count = Math.max(1, Math.floor(Math.random() * info.options.length));
const shuffled = [...info.options].sort(() => Math.random() - 0.5);
return shuffled.slice(0, count).map(o => o.text);
}
return [''];
},
clearAllSelections: function(popup) {
try {
// 静默取消选中,不触发click(避免React事件处理器意外提交)
popup.querySelectorAll('input:checked').forEach(input => {
input.checked = false;
input.dispatchEvent(new Event('change', { bubbles: true }));
});
} catch (e) {}
},
autoSubmitAnswer: function(popup) {
if (!currentConfig.autoSubmit) return;
let submitted = false; // 成功一次后阻止后续重试
[500, 1000, 1500].forEach(delay => {
setTimeout(() => {
if (submitted) return;
const btn = utils.findSubmitButton(popup);
if (btn && !btn.disabled && btn.offsetParent) {
if (utils.triggerButtonClick(btn)) {
submitted = true;
Logger.milestone('视频答题已自动提交');
utils.showMessage('已自动提交答案', 'success');
}
}
}, delay);
});
},
setAnswerToPage: async function(info, answers, popup) {
let finalAnswers = answers;
let useRandom = false;
// [诊断] 记录 AI 原始答案与页面选项,用于定位"AI答对却勾错"
Logger.milestone(`[诊断] AI答案=${JSON.stringify(answers)} | 选项文本=${JSON.stringify(info.options.map(o => o.text))}`);
if (!answers || !answers.length || !utils.fuzzyMatchIndex(info.options.map(o => o.text), answers, currentConfig.matchRate).length) {
if (currentConfig.randomAnswer) {
Logger.milestone(`[诊断] AI答案匹配失败,触发随机答题!`);
finalAnswers = this.generateRandomAnswer(info);
useRandom = true;
} else {
utils.log('无可用答案且未开启随机答题');
return false;
}
}
this.clearAllSelections(popup);
await utils.wait(200);
const matchIndices = utils.fuzzyMatchIndex(info.options.map(o => o.text), finalAnswers, currentConfig.matchRate);
if (matchIndices.length === 0 && useRandom) {
matchIndices.push(Math.floor(Math.random() * info.options.length));
}
Logger.milestone(`[诊断] finalAnswers=${JSON.stringify(finalAnswers)} | matchIndices=${JSON.stringify(matchIndices)} | useRandom=${useRandom}`);
let successCount = 0;
let expectedCount = 0;
if (info.type === 'judgment') {
expectedCount = 1;
const isCorrect = finalAnswers[0].includes('对') || finalAnswers[0].includes('正确') || finalAnswers[0] === 'A';
for (const opt of info.options) {
if ((isCorrect && (opt.text.includes('对') || opt.text.includes('正确'))) ||
(!isCorrect && (opt.text.includes('错') || opt.text.includes('错误')))) {
const verified = await utils.clickAndVerify(opt);
if (verified) successCount++;
break;
}
}
} else if (info.type === 'single') {
// 单选:只勾选相似度最高的一个
// (避免"包含"规则导致多个选项误匹配后全点,radio互斥最终停在最后一个)
expectedCount = 1;
let bestIdx = matchIndices[0];
let bestScore = -1;
for (const idx of matchIndices) {
if (!info.options[idx]) continue;
const score = utils.similarity(info.options[idx].text, finalAnswers[0]);
if (score > bestScore) { bestScore = score; bestIdx = idx; }
}
if (info.options[bestIdx]) {
const verified = await utils.clickAndVerify(info.options[bestIdx]);
if (verified) successCount++;
}
} else {
expectedCount = matchIndices.length;
for (const idx of matchIndices) {
if (info.options[idx]) {
const verified = await utils.clickAndVerify(info.options[idx]);
if (verified) successCount++;
}
}
}
if (successCount > 0 && successCount === expectedCount) {
utils.showMessage(`答题成功(${useRandom ? '随机答案' : 'AI答案'})`, 'success');
setTimeout(() => {
this.autoSubmitAnswer(popup);
}, 300);
return true;
} else {
utils.showMessage(`答题选项点击未生效,阻止自动提交`, 'error');
return false;
}
},
processQuestion: async function(popup) {
if (isAnswering) { utils.showMessage('正在处理,请稍等', 'warning'); return; }
isAnswering = true;
try {
const info = this.extractQuestionInfo(popup);
if (!info || !info.type) { utils.showMessage('无法识别题目', 'error'); return; }
Logger.milestone('检测到视频题目: ' + info.type + ' - ' + info.text.substring(0, 30) + '...');
const options = info.options.map(o => o.text);
// 调用 AI(答案与计费由服务端处理)
const aiAnswers = await DeepSeekService.getAnswerFromDeepSeek(info.text, options, info.type);
const result = await this.setAnswerToPage(info, aiAnswers, popup);
if (result) {
Logger.milestone('视频答题成功: ' + info.text.substring(0, 20) + '...');
}
} catch (e) {
Logger.add('error', '视频答题异常: ' + e.message);
utils.showMessage(`答题异常: ${e.message}`, 'error');
} finally {
isAnswering = false;
}
}
};
// ============================ 考试模式处理模块 ============================
const ExamProcessor = {
// 检测是否为考试弹窗(.ant-modal-wrap 内含 .ant-form + 第X题格式)
isExamModal: function(modal) {
if (!modal) return false;
const form = modal.querySelector('.ant-form');
if (!form || form.children.length < 2) return false;
const row1 = form.children[1];
return row1 && /第\d+题/.test(row1.textContent);
},
// 从考试弹窗提取题目信息(复用 QuestionProcessor 的输出格式)
extractExamQuestion: function(modal) {
const info = { type: null, text: '', options: [], isExam: true };
try {
const form = modal.querySelector('.ant-form');
if (!form || form.children.length < 2) return null;
const row1 = form.children[1]; // 第X题:(题型)题目
const rawText = row1.textContent.trim();
// 提取题型
const typeMatch = rawText.match(/(判断题|单选题|多选题)/);
if (typeMatch) {
if (typeMatch[1] === '判断题') info.type = 'judgment';
else if (typeMatch[1] === '单选题') info.type = 'single';
else if (typeMatch[1] === '多选题') info.type = 'multiple';
}
// 提取题干(去掉"第X题:(题型)"前缀)
info.text = rawText.replace(/^第\d+题[::]\s*[((]\s*(判断题|单选题|多选题)\s*[))]\s*/, '').trim();
// 提取选项(.ant-radio-wrapper 不含文本,需从父容器 .can-scroll 按 A:B:C:D:分割)
const optionsDiv = form.children[2]; // .can-scroll
if (optionsDiv) {
const radioWrappers = optionsDiv.querySelectorAll('.ant-radio-wrapper');
const raw = optionsDiv.textContent || '';
// 按 A:B:C:D:分割出选项文本
const parts = raw.split(/[A-D][::]/);
parts.forEach((part, idx) => {
if (idx === 0 || !part) return; // 跳过第一个空段
const cleaned = part.replace(/\s+/g, ' ').trim();
if (cleaned && idx - 1 < radioWrappers.length) {
const wrapper = radioWrappers[idx - 1];
info.options.push({
index: idx - 1,
text: cleaned,
element: wrapper,
inputElement: wrapper ? wrapper.querySelector('input[type="radio"]') : null
});
}
});
}
return info;
} catch (e) {
utils.log('提取考试题目失败:', e);
return null;
}
},
// 选中考试选项
selectExamOption: function(option) {
if (!option) return false;
try {
if (option.inputElement) {
option.inputElement.click();
option.inputElement.checked = true;
option.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
} else if (option.element) {
option.element.click();
}
return true;
} catch (e) {
utils.log('选中考试选项失败:', e);
return false;
}
},
// 找到考试按钮(下一题/提 交)
findExamButton: function(modal) {
const form = modal.querySelector('.ant-form');
if (!form || form.children.length < 4) return null;
const btnDiv = form.children[3]; // .custom-btn
if (!btnDiv) return null;
// 优先找"提 交",其次"下一题"
const buttons = btnDiv.querySelectorAll('button');
for (const btn of buttons) {
const t = btn.textContent.trim().replace(/\s+/g, '');
if (t === '提交' || t === '下一题') return btn;
}
return buttons[buttons.length - 1] || null;
},
// 判断是否是最后一题(按钮是"提 交")
isLastQuestion: function(modal) {
const btn = this.findExamButton(modal);
return btn ? btn.textContent.trim().replace(/\s+/g, '') === '提交' : false;
},
// 点击末题提交后,等待并确认平台的二次确认框。
confirmExamSubmission: function() {
return new Promise((resolve) => {
let settled = false;
const finish = (ok) => {
if (settled) return;
settled = true;
observer.disconnect();
clearTimeout(timer);
resolve(ok);
};
const tryConfirm = () => {
const dialog = [...document.querySelectorAll('.ant-modal-confirm')].reverse().find(item =>
item.getClientRects().length > 0 && /是否提交|确认提交试卷/.test(item.textContent || '')
);
if (!dialog) return;
const buttons = [...dialog.querySelectorAll('button')];
const confirmBtn = buttons.find(button =>
!button.disabled && /^(确定|确认|OK)$/i.test(button.textContent.trim().replace(/\s+/g, ''))
) || dialog.querySelector('button.ant-btn-primary:not([disabled])');
if (!confirmBtn) return;
confirmBtn.click();
finish(true);
};
const observer = new MutationObserver(tryConfirm);
observer.observe(document.body, { childList: true, subtree: true });
const timer = setTimeout(() => finish(false), 2000);
tryConfirm();
});
},
// 处理单道考试题
processExamQuestion: async function(modal) {
if (examProcessing) return;
examProcessing = true;
try {
const info = this.extractExamQuestion(modal);
if (!info || !info.type) {
utils.log('无法识别考试题目');
examProcessing = false;
return;
}
Logger.milestone('检测到考试题目: ' + info.type + ' - ' + info.text.substring(0, 30) + '...');
utils.log('考试题目:', { type: info.type, text: info.text.substring(0, 30) + '...', optionsCount: info.options.length });
// 调用 AI 获取答案
const options = info.options.map(o => o.text);
const aiAnswers = await DeepSeekService.getAnswerFromDeepSeek(info.text, options, info.type);
// 匹配答案
let finalAnswers = aiAnswers;
let useRandom = false;
if (!aiAnswers || aiAnswers.length === 0 || !utils.fuzzyMatchIndex(info.options.map(o => o.text), aiAnswers, currentConfig.matchRate).length) {
if (currentConfig.randomAnswer) {
finalAnswers = info.type === 'judgment'
? (Math.random() > 0.5 ? ['正确'] : ['错误'])
: [info.options[Math.floor(Math.random() * info.options.length)].text];
useRandom = true;
}
}
if (!finalAnswers || finalAnswers.length === 0) {
Logger.add('error', '考试无可用答案');
utils.log('无可用答案');
examProcessing = false;
return;
}
// 匹配选项索引
const matchIndices = utils.fuzzyMatchIndex(info.options.map(o => o.text), finalAnswers, currentConfig.matchRate);
if (matchIndices.length === 0 && useRandom) {
matchIndices.push(Math.floor(Math.random() * info.options.length));
}
// 选中答案
let selected = false;
if (info.type === 'judgment') {
const isCorrect = finalAnswers[0].includes('正确') || finalAnswers[0].includes('对');
for (const opt of info.options) {
const t = opt.text;
if ((isCorrect && (t.includes('正确') || t.includes('对'))) ||
(!isCorrect && (t.includes('错误') || t.includes('错')))) {
selected = this.selectExamOption(opt);
break;
}
}
} else {
for (const idx of matchIndices) {
if (info.options[idx]) {
selected = this.selectExamOption(info.options[idx]) || selected;
}
}
}
if (selected) {
const answerLabel = useRandom ? '随机答案' : 'AI答案';
Logger.milestone('考试答题成功: ' + info.text.substring(0, 20) + '... (' + answerLabel + ')');
utils.showMessage(`考试答题成功(${answerLabel})`, 'success');
}
// 自动翻到下一题 或 自动提交(独立开关)
setTimeout(async () => {
const btn = this.findExamButton(modal);
if (!btn || !btn.offsetParent || btn.disabled) return;
const btnText = btn.textContent.trim().replace(/\s+/g, '');
if (btnText === '提交') {
if (currentConfig.examAutoSubmit) {
Logger.milestone('自动提交考试');
utils.log('自动提交考试');
btn.click();
const confirmed = await this.confirmExamSubmission();
if (confirmed) {
utils.showMessage('考试已确认提交', 'success');
} else {
Logger.add('error', '考试二次确认按钮未找到');
utils.showMessage('未找到考试二次确认,请手动确认提交', 'warning');
}
} else {
Logger.milestone('末题已答,等待手动提交');
utils.log('末题已答,等待手动提交');
}
} else if (btnText === '下一题') {
if (currentConfig.examAutoAdvance) {
utils.log('自动翻下一题');
btn.click();
}
}
}, currentConfig.examAdvanceDelay);
} catch (e) {
Logger.add('error', '考试处理异常: ' + e.message);
utils.log('考试处理异常:', e);
} finally {
// 延迟释放锁,给翻页留时间
setTimeout(() => { examProcessing = false; }, currentConfig.examAdvanceDelay + 500);
}
}
};
// ============================ 考试批量并发答题 ============================
// 【2.5.7】考试数据本地存储:单场次一份,逐批落盘。
// 用途:刷新/崩溃后能续跑 —— 已全部拿到答案的批次直接跳过,不重复请求、不重复扣费。
const EXAM_STORE_KEY = 'examJobStore';
const ExamStore = {
read: function() {
const raw = GM_getValue(EXAM_STORE_KEY, null);
return raw && typeof raw === 'object' ? raw : null;
},
write: function(job) {
GM_setValue(EXAM_STORE_KEY, job);
},
wipe: function() {
// 【2.5.21】GM_deleteValue 未在 @grant 中声明(沙箱不注入该 API),
// 调用即抛 TypeError 并中断后续清理。写入 null 与删除在 read() 语义上等价。
GM_setValue(EXAM_STORE_KEY, null);
}
};
const ExamBatchProcessor = {
hookInstalled: false,
pending: false,
running: false,
activeRecordId: '',
runId: 0,
answers: new Map(),
answerSources: new Map(),
failedQuestions: new Set(),
errors: [],
completedBatches: 0,
totalBatches: 0,
runningBatches: 0,
totalQuestions: 0,
lastRecords: [],
// 【2.5.18】本场题目的归一化全集(seq 按原始下标定格);「重试未答出题目」靠它拿正确题号
questionModels: [],
// 【2.5.7】统计与调度状态
stats: { requests: 0, failedBatches: 0 }, // requests = 真正发出的请求数(≈ 扣费次数)
submitted: false,
netFailStreak: 0, // 连续"网络类"失败批数(轻量熔断用)
aborted: false, // 熔断停手标志
abortReason: '',
nextTokenAt: 0, // 令牌桶:下一张票的可用时刻
adapt: { effective: 0, window: [], successStreak: 0, rateLimited: false },
available: function() {
// 【3.1.1】自动答题/AI 答题开关已删(恒开):只看考试总开关
return currentConfig.examEnabled;
},
isActive: function() {
return this.pending || !!this.activeRecordId;
},
plan: function() {
const batchSize = clampExamBatchSize(currentConfig.examBatchSize);
const concurrency = clampExamConcurrency(currentConfig.examConcurrency);
const total = this.totalQuestions || 0;
const submits = total ? Math.ceil(total / batchSize) : 0;
const waves = submits ? Math.ceil(submits / concurrency) : 0;
return { batchSize: batchSize, concurrency: concurrency, total: total, submits: submits, waves: waves };
},
refreshPlanUI: function() {
const el = document.getElementById('exam-plan-summary');
if (!el) return;
const p = this.plan();
el.textContent = p.total
? `本次考试:共 ${p.total} 题|单轮 ${p.batchSize} 题|单次并发 ${p.concurrency} 轮\n总体提交次数:${p.submits} 次(分 ${p.waves} 波发完)`
: `本次考试:单轮 ${p.batchSize} 题|单次并发 ${p.concurrency} 轮\n总体提交次数:考试开始后按实际题数自动计算`;
},
updateStatus: function(message) {
const el = document.getElementById('exam-batch-status');
this.refreshPlanUI();
const answerProgress = document.getElementById('exam-answer-progress');
const answerCount = document.getElementById('exam-answer-count');
const answerState = document.getElementById('exam-answer-state');
if (answerState) answerState.textContent = this.cardErrorCode ? (this.cardErrorCode==='INSUFFICIENT_BALANCE'?'余额不足 · 已停止':'卡密错误 · 已停止') : this.balanceBlocked ? '余额不足 · 已停止' : this.running ? '答题中'
: this.totalQuestions && this.answers.size >= this.totalQuestions ? '答题完成'
: this.totalQuestions ? '未答完' : '未开始';
const roundProgress = document.getElementById('exam-grab-progress');
const roundCount = document.getElementById('exam-grab-count');
const failureCount = document.getElementById('exam-failure-count');
if (answerProgress) {
answerProgress.max = Math.max(1, this.totalQuestions);
answerProgress.value = Math.min(this.answers.size, this.totalQuestions);
}
if (answerCount) answerCount.textContent = this.totalQuestions
? `${this.answers.size}/${this.totalQuestions} 题已获取答案|${Math.max(0, this.totalQuestions - this.answers.size)} 题未获取`
: '等待考试开始';
const total = Math.max(1, this.totalQuestions);
const ai = [...this.answers.keys()].filter(id => this.answerSources.get(id) === 'ai').length;
const library = this.answers.size - ai;
const bad = [...this.failedQuestions].filter(id => !this.answers.has(id)).length;
const libPart = document.getElementById('exam-library-part');
const aiPart = document.getElementById('exam-ai-part');
const badPart = document.getElementById('exam-failed-part');
if (libPart) libPart.style.width = library / total * 100 + '%';
if (aiPart) { aiPart.style.left = library / total * 100 + '%'; aiPart.style.width = ai / total * 100 + '%'; }
if (badPart) badPart.style.width = bad / total * 100 + '%';
if (answerProgress) {
answerProgress.setAttribute('aria-valuemin', '0');
answerProgress.setAttribute('aria-valuemax', String(this.totalQuestions));
answerProgress.setAttribute('aria-valuenow', String(this.answers.size));
}
if (roundProgress) {
roundProgress.max = Math.max(1, this.totalQuestions);
roundProgress.value = Math.min(this.questionModels.length, this.totalQuestions);
}
const grabPart = document.getElementById('exam-grab-part');
if (grabPart) grabPart.style.width = Math.min(this.questionModels.length, this.totalQuestions) / total * 100 + '%';
if (roundCount) roundCount.textContent = this.totalQuestions
? `${this.questionModels.length}/${this.totalQuestions} 题已抓取`
: '尚未开始';
if (failureCount) failureCount.textContent = `失败批次:${this.stats.failedBatches}(不等于失败题数)`;
if (!el) return;
const upper = clampExamConcurrency(currentConfig.examConcurrency);
const effective = this.adapt && this.adapt.effective ? this.adapt.effective : upper;
const progress = this.totalBatches
? `批次 ${this.completedBatches}/${this.totalBatches}|并发 ${this.runningBatches}/${effective}${effective < upper ? `(上限 ${upper},已降级)` : ''}|有效答案 ${this.answers.size}|请求 ${this.stats.requests} 次`
: '';
const lastError = this.errors.length ? this.errors[this.errors.length - 1] : '';
el.textContent = `批量答题:${message}${progress ? '\n' + progress : ''}${lastError ? `\n失败:${this.errors.length}|${lastError}` : ''}`;
el.style.color = this.errors.length ? '#cf1322' : '#555';
},
normalizeQuestion: function(q, index) {
const options = ['a', 'b', 'c', 'd'].map((key, optionIndex) => ({
letter: String.fromCharCode(65 + optionIndex),
text: String(q['option' + key] || '').replace(/\s+/g, ' ').trim()
})).filter(option => option.text);
const kind = String(q.kind);
return {
id: String(q.id),
seq: index + 1,
kind,
type: kind === '1' ? 'judgment' : kind === '3' ? 'multiple' : 'single',
question: String(q.stem || q.question || '').replace(/\s+/g, ' ').trim(),
options
};
},
buildMessages: function(batch) {
const baseSystem = DeepSeekService.buildSystemPrompt('default');
const systemPrompt = baseSystem + '\n你将一次回答多道题。只能返回 JSON,不要解释,不要使用 Markdown。每项必须保留原题号 seq;answer 必须是字母数组。判断题和单选题数组只能有一个字母,多选题可有多个字母。';
let userPrompt = '';
if (!currentConfig.reviewMode && currentConfig.customUserPrompt && currentConfig.customUserPrompt.trim()) {
userPrompt += currentConfig.customUserPrompt.trim() + '\n\n';
}
userPrompt += '请回答以下题目:\n' + JSON.stringify(batch.map(q => ({
seq: q.seq,
type: q.type,
question: q.question,
options: Object.fromEntries(q.options.map(option => [option.letter, option.text]))
}))) + '\n返回格式:{"answers":[{"seq":题号,"answer":["A"]}]}';
return {
systemPrompt,
userPrompt,
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userPrompt }
]
};
},
parseResponse: function(raw, batch) {
const expected = new Map(batch.map(question => [question.id, question]));
const parsedAnswers = new Map();
try {
const cleaned = String(raw || '').replace(/```(?:json)?/gi, '').replace(/```/g, '').trim();
const start = cleaned.indexOf('{');
const end = cleaned.lastIndexOf('}');
if (start < 0 || end <= start) return parsedAnswers;
const data = JSON.parse(cleaned.slice(start, end + 1));
if (!Array.isArray(data.answers)) return parsedAnswers;
for (const item of data.answers) {
const id = String(item && item.id || '');
const question = expected.get(id) || batch.find(candidate => candidate.seq === Number(item && item.seq));
if (!question || parsedAnswers.has(question.id)) continue;
const rawLetters = Array.isArray(item.answer) ? item.answer : [item.answer];
const allowed = new Set(question.options.map(option => option.letter));
const letters = [...new Set(rawLetters.flatMap(value =>
String(value || '').toUpperCase().match(/[A-D]/g) || []
).filter(letter => allowed.has(letter)))].sort();
if (question.type === 'multiple' ? letters.length > 0 : letters.length === 1) {
parsedAnswers.set(question.id, letters);
}
}
} catch (error) {}
return parsedAnswers;
},
// 网络类失败可以重发;余额/卡密/提示词拦截类重发只会白扣额度
// 【2.5.9】TIMEOUT 已移出:超时即失败,不拆批、不原样重发(客户端超时≠服务端没扣费,
// 重发有双倍扣费风险,且白等最坏 216 秒)。用户可调小「单轮题数」或调大「等待超时」重跑。
isRetryable: function(code) {
return ['NETWORK_ERROR', 'BAD_RESPONSE', 'RATE_LIMITED'].indexOf(String(code || '')) >= 0;
},
isNetworkCode: function(code) {
return EXAM_NET_CODES.indexOf(String(code || '')) >= 0;
},
// 【2.5.7】令牌桶:同步"预约"下一张票,保证全池任意两次请求的间隔 ≥ EXAM_MIN_REQUEST_INTERVAL。
// 预约段内没有 await,所以并发调用会被原子地排成队列 —— 并发 8 也不会同时出站。
reserveRequestSlot: async function(runId) {
const myTurn = Math.max(Date.now(), this.nextTokenAt);
this.nextTokenAt = myTurn + EXAM_MIN_REQUEST_INTERVAL;
const wait = myTurn - Date.now();
if (wait > 0) await new Promise(resolve => setTimeout(resolve, wait));
return runId === this.runId && !this.aborted;
},
stopForInsufficientBalance: function(message, code = 'INSUFFICIENT_BALANCE') {
if (this.balanceBlocked) return;
this.balanceBlocked = true;
this.cardErrorCode = code;
this.aborted = true;
this.abortReason = code==='INSUFFICIENT_BALANCE'?'卡密余额不足,已停止答题':'卡密授权异常,已停止答题';
++this.runId;
this.running = false;
this.runningBatches = 0;
this.pending = false;
currentConfig.examEnabled = false;
this.errors.push(message || this.abortReason);
this.persist();
this.syncExamModeUI();
this.updateStatus(this.abortReason);
AuthService.cardFailure(code,message);
Logger.add('error', this.abortReason, message || 'INSUFFICIENT_BALANCE');
},
recoverAuthorization: function() {
if (!this.balanceBlocked && !this.cardErrorCode) return;
const ready=AuthService.checkReady();if(!ready.ok)return;
++this.runId;this.running=false;this.pending=false;this.runningBatches=0;
this.aborted=false;this.balanceBlocked=false;this.cardErrorCode='';this.abortReason='';this.nextTokenAt=0;
currentConfig.examEnabled=false;
if(AuthService.cardFailureNotice){AuthService.cardFailureNotice.remove();AuthService.cardFailureNotice=null;}
this.syncExamModeUI();this.updateStatus('授权已更新,请点击开始考试或重试未答出题目');
},
callBatch: async function(batch, runId) {
if (runId !== this.runId || this.aborted || !batch.length) return { answers: new Map(), canRetry: false, retryable: false };
const range = `第 ${batch[0].seq}-${batch[batch.length - 1].seq} 题`;
const graphId = 'shared'; // 课程与考试共用一个题库,不依赖视频页缓存。
// 【2.5.7】令牌桶整形:即便并发拉到 8,也按最小间隔匀速出站,避免瞬时峰值被限流
const slotOk = await this.reserveRequestSlot(runId);
if (!slotOk) return { answers: new Map(), canRetry: false, retryable: false };
this.stats.requests++;
// 【2.5.9】超时取「等待超时」滑块值(秒 → 毫秒),每次请求现读,改滑块即时生效
const response = await AuthService.answerBatch(graphId, batch.map(q => ({
seq: q.seq, stem: q.question, options: q.options, type: q.type, kind: q.kind
})), clampExamRequestTimeout(currentConfig.examRequestTimeout) * 1000, true);
if (runId !== this.runId) return { answers: new Map(), canRetry: false, retryable: false };
if (!response || !response.success) {
const code = response && response.code || 'UNKNOWN_ERROR';
const message = response && response.msg || 'AI 请求失败';
if (code === 'INSUFFICIENT_BALANCE') this.stopForInsufficientBalance(message);
return { answers: new Map(), canRetry: false, retryable: this.isRetryable(code),
failInfo: { range: range, code: code, message: message } };
}
if (response.data && response.data.balance_cent !== undefined) {
const cached = AuthService.getCachedStatus();
if (cached) {
cached.balance_cent = Math.min(Number(cached.balance_cent), Number(response.data.balance_cent));
AuthService.setCachedStatus(cached);
}
if (ControlPanel.updateAuthStatusUI) ControlPanel.updateAuthStatusUI();
}
const answers = new Map();
for (const item of (response.data && response.data.answers) || []) {
const q = batch.find(q => q.seq === Number(item.seq));
const letters = String(item.answer || '').toUpperCase().replace(/[^A-Z]/g, '').split('');
if (!q || !letters.length || letters.some(letter => !q.options.some(o => o.letter === letter)) ||
(q.type !== 'multiple' && letters.length !== 1)) continue;
answers.set(q.id, letters);
this.answerSources.set(q.id, item.source === 'ai' ? 'ai' : 'library');
this.failedQuestions.delete(q.id);
}
return { answers, canRetry: true, retryable: false };
},
// 整批重发:网络类失败按 2s / 4s 退避重试,最多 EXAM_RETRY_ATTEMPTS 次尝试
callBatchWithRetry: async function(batch, runId) {
let last = null;
for (let attempt = 1; attempt <= EXAM_RETRY_ATTEMPTS; attempt++) {
if (runId !== this.runId || this.aborted) return { answers: new Map(), canRetry: false, retryable: false };
last = await this.callBatch(batch, runId);
if (last.answers.size || !last.retryable || attempt >= EXAM_RETRY_ATTEMPTS) break;
// 【2.5.7】退避加抖动(0.5~1.5 倍):避免多个 worker 在同一毫秒一起重发又撞一次
const wait = Math.round(EXAM_RETRY_BASE_DELAY * Math.pow(2, attempt - 1) * (1 - EXAM_JITTER + Math.random() * 2 * EXAM_JITTER));
const info = last.failInfo || {};
this.updateStatus(`${info.range || '当前批'} 请求失败,${Math.round(wait / 1000)} 秒后重试(第 ${attempt + 1}/${EXAM_RETRY_ATTEMPTS} 次尝试)`);
Logger.add('info', `${info.range || '当前批'}请求失败,即将重试`,
`${info.code || ''} - ${info.message || ''};等待 ${wait}ms`);
await new Promise(resolve => setTimeout(resolve, wait));
}
if (last && !last.answers.size && last.failInfo) {
this.errors.push(`${last.failInfo.range}:${last.failInfo.message}`);
Logger.add('error', `${last.failInfo.range}批量答题失败`,
`${last.failInfo.code} - ${last.failInfo.message}(已尝试 ${EXAM_RETRY_ATTEMPTS} 次)`);
}
return last || { answers: new Map(), canRetry: false, retryable: false };
},
// 返回 { answers, failCode }:failCode 为 null 表示整批拿全,否则是最后一次失败的错误码
answerBatch: async function(batch, runId) {
const firstResult = await this.callBatchWithRetry(batch, runId);
const first = firstResult.answers;
const missing = batch.filter(question => !first.has(question.id));
let lastCode = (firstResult.failInfo && firstResult.failInfo.code) || null;
if (missing.length && firstResult.canRetry && runId === this.runId) {
const retryResult = await this.callBatchWithRetry(missing, runId);
for (const [id, answer] of retryResult.answers) first.set(id, answer);
if (retryResult.failInfo) lastCode = retryResult.failInfo.code;
if (first.size !== batch.length) {
this.errors.push(`第 ${batch[0].seq}-${batch[batch.length - 1].seq} 题仍缺 ${batch.length - first.size} 个答案`);
}
}
return {
answers: first,
failCode: first.size === batch.length ? null : String(lastCode || 'INCOMPLETE_RESPONSE')
};
},
// 【2.5.7】自适应降级 + 轻量熔断的记账入口:每批结束后调用一次
recordBatchOutcome: function(batch, outcome) {
for (const q of batch) {
if (outcome && outcome.answers && outcome.answers.has(q.id)) this.failedQuestions.delete(q.id);
else this.failedQuestions.add(q.id);
}
const ok = !!(outcome && outcome.answers && outcome.answers.size === batch.length);
const code = outcome && outcome.failCode ? String(outcome.failCode) : (ok ? '' : 'INCOMPLETE_RESPONSE');
if (!ok) this.stats.failedBatches++;
// —— 自适应降级:按滑动窗口失败率调整有效并发(滑块给的是上限)——
this.adapt.window.push(ok ? 1 : 0);
while (this.adapt.window.length > EXAM_ADAPT_WINDOW) this.adapt.window.shift();
const upper = clampExamConcurrency(currentConfig.examConcurrency);
if (this.adapt.effective > upper) this.adapt.effective = upper;
if (this.adapt.effective < 1) this.adapt.effective = 1;
const fails = this.adapt.window.filter(value => !value).length;
if (this.adapt.window.length >= EXAM_ADAPT_WINDOW &&
fails / this.adapt.window.length > EXAM_ADAPT_FAIL_RATIO &&
this.adapt.effective > 1) {
const ratio = Math.round(fails / this.adapt.window.length * 100);
this.adapt.effective = 1;
Logger.add('warning', '考试并发已降级', `近 ${this.adapt.window.length} 批失败率 ${ratio}% → 有效并发降为 1`);
}
if (ok) {
this.adapt.successStreak++;
if (this.adapt.successStreak >= EXAM_ADAPT_RECOVER_STREAK &&
!this.adapt.rateLimited &&
this.adapt.effective < upper) {
this.adapt.effective++;
this.adapt.successStreak = 0;
Logger.add('info', '考试并发已回升', `连续 ${EXAM_ADAPT_RECOVER_STREAK} 批成功 → 有效并发升为 ${this.adapt.effective}`);
}
} else {
this.adapt.successStreak = 0;
}
if (code === 'RATE_LIMITED') this.adapt.rateLimited = true; // 被限流过:不再自动升档
// —— 轻量熔断:只认"网络类"连环失败(余额/上游类不重试,谈不上连环白等)——
if (!ok && this.isNetworkCode(code)) this.netFailStreak++;
else this.netFailStreak = 0;
if (this.netFailStreak >= EXAM_BREAKER_FAILS) this.tripBreaker();
},
// 轻量熔断:连续网络类失败 ⇒ 整池停手(不做冷却/探测/半开),已得答案保留
tripBreaker: function() {
if (this.aborted) return;
this.aborted = true;
this.abortReason = `网络异常,已停止答题(连续 ${this.netFailStreak} 批网络类失败,已得答案保留)`;
Logger.add('error', '考试批量已熔断停手', this.abortReason);
utils.showMessage('⚠️ 网络异常,已停止答题
已得答案已保留:可等网络恢复后重新运行继续,或关闭自动提交后手动提交', 'error', 10000);
this.persist();
this.updateStatus(this.abortReason);
},
// 续跑判定:整批题目都已在答案表里 ⇒ 这批不必再请求(省一次扣费)
isBatchSatisfied: function(batch) {
return batch.every(question => this.answers.has(String(question.id)));
},
// 【2.5.7】逐批落盘:答案 + 进度 + 统计;刷新/崩溃后可续跑
persist: function() {
if (!this.activeRecordId) return;
try {
ExamStore.write({
version: 1,
recordId: String(this.activeRecordId),
savedAt: Date.now(),
total: this.totalQuestions,
answers: [...this.answers.entries()].map(([id, letters]) => [id, [...letters]]),
stats: { requests: this.stats.requests, failedBatches: this.stats.failedBatches },
submitted: !!this.submitted
});
} catch (error) {
Logger.add('warning', '考试进度落盘失败', error.message || String(error));
}
},
// 续跑恢复:同场次且题目 id 仍对得上才采用;题库/场次变了就忽略,重新答题
restore: function(recordId, questions) {
const saved = ExamStore.read();
if (!saved || String(saved.recordId) !== String(recordId) || !Array.isArray(saved.answers)) return 0;
const valid = new Set(questions.map(question => String(question.id)));
let restored = 0;
for (const pair of saved.answers) {
if (!Array.isArray(pair) || pair.length < 2) continue;
const id = String(pair[0]);
const letters = Array.isArray(pair[1]) ? pair[1].map(value => String(value)) : [];
if (!valid.has(id) || !letters.length) continue;
this.answers.set(id, letters);
restored++;
}
if (saved.stats) {
this.stats.requests = Number(saved.stats.requests) || 0;
this.stats.failedBatches = Number(saved.stats.failedBatches) || 0;
}
this.submitted = !!saved.submitted;
return restored;
},
// 「清除考试数据」:一键清掉本机保存的考试相关数据(答案 / 批次进度 / 统计读数)
clearStoredData: function() {
if (this.running) {
utils.showMessage('正在答题,请等本轮结束后再清除', 'warning');
return false;
}
ExamStore.wipe();
this.answers = new Map();
this.answerSources = new Map();
this.failedQuestions = new Set();
this.errors = [];
this.stats = { requests: 0, failedBatches: 0 };
this.netFailStreak = 0;
this.aborted = false;
this.balanceBlocked = false;
this.cardErrorCode = '';
this.abortReason = '';
this.submitted = false;
this.resetSlotButtons();
this.completedBatches = 0;
this.totalBatches = 0;
this.totalQuestions = 0;
this.runningBatches = 0;
this.activeRecordId = '';
// 【2.5.18】题目全集一并丢弃,避免「重试未答出题目」拿上一场的题号
this.questionModels = [];
this.adapt = { effective: clampExamConcurrency(currentConfig.examConcurrency), window: [], successStreak: 0, rateLimited: false };
this.syncSubmitUI();
this.updateStatus('考试数据已清除');
Logger.add('info', '已清除考试数据', '答案 / 批次进度 / 统计读数均已清空');
utils.showMessage('已清除本机保存的考试数据', 'info');
return true;
},
findExamVm: function(recordId) {
const root = document.querySelector('#app') && document.querySelector('#app').__vue__;
const stack = root ? [root] : [];
const seen = new Set();
while (stack.length) {
const vm = stack.pop();
if (!vm || seen.has(vm)) continue;
seen.add(vm);
if (Array.isArray(vm.records) && String(vm.recordId || '') === String(recordId) && vm.param) return vm;
for (const child of vm.$children || []) stack.push(child);
}
return null;
},
// 【2.5.12】不依赖 recordId 找「正在进行中的考试」页面:有题目数组 + 作答状态 + 提交方法即是
// 用途:「一键完成」时用户已进考场但 startExam 请求已被闸门错过,就地起跑
findActiveExamVm: function() {
const root = document.querySelector('#app') && document.querySelector('#app').__vue__;
const stack = root ? [root] : [];
const seen = new Set();
while (stack.length) {
const vm = stack.pop();
if (!vm || seen.has(vm)) continue;
seen.add(vm);
if (Array.isArray(vm.records) && vm.records.length && vm.param && typeof vm.submit === 'function') return vm;
for (const child of vm.$children || []) stack.push(child);
}
return null;
},
syncDisplayedQuestion: function(vm) {
const currentId = String(vm.model && vm.model.id || '');
const value = vm.param[currentId];
if (String(vm.model && vm.model.kind) === '3') {
vm.options = Array.isArray(value) ? [...value] : [];
vm.option = '';
} else {
vm.option = typeof value === 'string' ? value : '';
vm.options = [];
}
},
// 【2.5.12】考试模式相关 UI 的统一同步入口:开始按钮 / 自动提交开关 / 三个参数输入框 / 提交槽位
// 「一键完成」改了配置后由它把界面一次性拉齐,避免界面与真实配置不一致
syncExamModeUI: function() {
const btn = document.getElementById('exam-start-btn');
if (btn) {
const on = !!currentConfig.examEnabled;
btn.dataset.on = on ? '1' : '0';
btn.textContent = on ? '■ 已开始 · 点击停止' : '▶ 开始考试';
}
const autoSwitch = document.getElementById('exam-auto-submit-switch');
if (autoSwitch) {
autoSwitch.checked = !!currentConfig.examAutoSubmit;
const track = autoSwitch.nextElementSibling;
if (track && track.classList.contains('switch-track')) track.classList.toggle('on', autoSwitch.checked);
}
this.syncExamNumberInputs();
// 【2.5.15】计划摘要同样由当前配置派生,一并重算 —— 否则「一键完成」改了参数后这里会留旧值
this.refreshPlanUI();
this.syncSubmitUI();
},
// 三个参数输入框回填(配置被程序改写时同步显示值)
syncExamNumberInputs: function() {
const pairs = [
['exam-batch-size', currentConfig.examBatchSize],
['exam-concurrency', currentConfig.examConcurrency],
['exam-timeout', currentConfig.examRequestTimeout]
];
for (const [id, value] of pairs) {
const el = document.getElementById(id);
if (el) el.value = value;
}
},
// 【2.5.12】一键完成:套用推荐预设参数 + 开启自动提交 + 开启考试模式;
// 若检测到已在考场(页面已有题目),就地起跑,不必等 startExam 请求再被捕获
oneClickComplete: async function() {
if (this.running) {
utils.showMessage('正在答题中,无需重复点击', 'info');
return;
}
// 1) 预设参数:预设 === 三个默认值(单一来源),稳优先,无需用户判断
currentConfig.examBatchSize = EXAM_BATCH_SIZE_DEFAULT;
currentConfig.examConcurrency = EXAM_CONCURRENCY_DEFAULT;
currentConfig.examRequestTimeout = EXAM_TIMEOUT_DEFAULT;
GM_setValue('examBatchSize', currentConfig.examBatchSize);
GM_setValue('examConcurrency', currentConfig.examConcurrency);
GM_setValue('examRequestTimeout', currentConfig.examRequestTimeout);
// 2) 自动提交:一键完成的题眼 —— 跑完即交,不需要再回来点按钮
// 【2.5.21】会话态:仅本场有效,不写盘
currentConfig.examAutoSubmit = false;
// 3) 考试模式总闸门
currentConfig.examEnabled = true;
this.syncExamModeUI();
const presetText = `单轮 ${currentConfig.examBatchSize} 题|并发 ${currentConfig.examConcurrency} 轮|超时 ${currentConfig.examRequestTimeout} 秒`;
Logger.milestone(`一键完成:已套用预设(${presetText})并开启自动提交与考试模式`);
// 4) 已在考场则立即起跑;未进考场则等 startExam 请求被捕获
const vm = this.findActiveExamVm();
const recordId = vm ? String(vm.recordId || '') : '';
if (vm && recordId) {
const saved = ExamStore.read();
const alreadySubmitted = (saved && String(saved.recordId) === recordId && saved.submitted) || this.submitted;
if (alreadySubmitted) {
utils.showMessage(`已套用预设参数并开启自动提交
检测到本场考试已提交过;如需重跑请先「清除考试数据」`, 'warning', 8000);
return;
}
utils.showMessage(`已套用预设参数(${presetText})并开启自动提交
检测到进行中的考试,立即开始答题`, 'success', 6000);
this.run(vm.records, recordId).catch(error => {
this.running = false;
this.errors.push(`批量答题异常:${error.message || error}`);
this.updateStatus('运行失败');
});
} else {
utils.showMessage(`已套用预设参数(${presetText})并开启自动提交
进入考试后将自动完成`, 'success', 6000);
}
},
// 提交槽位 UI:开关常驻(关闭态也保留,随时可切回);手动态两枚按钮(填入答案 / 提交本次考试)
// 同排显示、自动态一起淡出 —— 层级与显隐规则与拆分前一致
// 「无答案」不用 disabled,改成 data-empty 视觉 + data-tooltip 悬停提示
syncSubmitUI: function() {
const slot = document.querySelector('#exam-submit-slot');
const label = document.querySelector('#exam-submit-label');
const fillBtn = document.querySelector('#exam-fill-btn');
const submitBtn = document.querySelector('#exam-manual-submit-btn');
if (!slot || !submitBtn) return;
const auto = false;
if (label) label.textContent = auto ? '自动提交' : '手动提交';
slot.classList.toggle('is-auto', auto);
slot.classList.toggle('is-manual', !auto);
// 【2.5.20】两枚按钮的可用性判据不同,不能共用一个 has:
// 填入 —— 看脚本手里有没有答案(没答案就没东西可写)
// 提交 —— 看卷面上有没有答案(清过数据 / 刷新过都该能交,这才是「能不能交」的真判据)
const fillHas = !!(this.answers && this.answers.size);
const submitHas = this.pageFilledCount() > 0;
// 【2.5.19】文案表只剩 idle / busy —— 按钮不再有「已填入 / 已提交 / 重试填入 / 重试提交」任何终态
this.renderSlotButton(fillBtn, fillHas,
{ idle: '填入答案', busy: '填入中…' },
{
empty: '暂无已获取的答案,请先让批量答题跑一轮',
idle: '把已获取的答案写进考试页面(只填不交;答案不完整也会填入)',
busy: '正在把答案填入页面,请稍候'
});
this.renderSlotButton(submitBtn, submitHas,
{ idle: '提交本次考试', busy: '提交中…' },
{
empty: '卷面上还没有作答,先点「填入答案」或在页面上自己答;空卷提交会白耗一次机会',
idle: '把页面上的答案提交(提交前二次确认;答案不完整会先告警)',
busy: '正在提交本次考试,请勿重复点击'
});
},
// 单枚槽位按钮的文案 / 灰态 / 悬停提示(has = 脚本手里是否已有答案)
// 【2.5.19】只剩 idle / submitting 两态:成功与失败都不挂终态、一律回 idle,成败由 toast 说
renderSlotButton: function(btn, has, texts, tips) {
if (!btn) return;
const state = btn.dataset.state || 'idle';
if (state === 'submitting') {
btn.dataset.empty = '0';
btn.textContent = texts.busy;
btn.dataset.tooltip = tips.busy;
return;
}
btn.dataset.empty = has ? '0' : '1';
btn.textContent = texts.idle;
btn.dataset.tooltip = has ? tips.idle : tips.empty;
},
// 【2.5.16】新一场考试 / 清空数据时把两枚槽位按钮复位 —— 保证不残留 busy 态
// (2.5.19 起按钮已无成功/失败终态,此复位仍必要:防上一轮卡在「填入中…/提交中…」)
resetSlotButtons: function() {
for (const id of ['exam-fill-btn', 'exam-manual-submit-btn']) {
const btn = document.getElementById(id);
if (btn) btn.dataset.state = 'idle';
}
},
// 只把答案写入页面(幂等、不提交);allowPartial=true 时允许部分填写
applyAnswersToPage: async function(records, recordId, runId, allowPartial) {
if (runId !== this.runId) return null;
if (!allowPartial && this.answers.size !== records.length) return null;
const vm = this.findExamVm(recordId);
if (!vm) {
this.errors.push('无法访问考试页面答案状态');
this.updateStatus('填写失败');
return null;
}
let filled = 0;
for (const record of records) {
const id = String(record.id);
const letters = this.answers.get(id);
if (!letters || !letters.length) {
if (allowPartial) continue;
return null;
}
const value = String(record.kind) === '3' ? [...letters] : letters[0];
if (typeof vm.$set === 'function') vm.$set(vm.param, id, value);
else vm.param[id] = value;
filled++;
}
this.syncDisplayedQuestion(vm);
if (typeof vm.$nextTick === 'function') await new Promise(resolve => vm.$nextTick(resolve));
this.updateStatus(`答案已填入页面 ${filled}/${records.length}`);
return vm;
},
// 提交:跳到末题 + 触发页面提交 + 等二次确认
examElapsedSeconds: function(vm){
if(!vm || !vm.recordId)return null;
let timing;try{timing=JSON.parse(sessionStorage.getItem('examTiming:'+vm.recordId)||'null');}catch(e){}
if(!timing)return null;
// 优先使用网页剩余时间,避免本机时钟与服务器时间偏差。
if(Number.isFinite(timing.duration)&&timing.duration>0&&Number.isFinite(Number(vm.count))){
return Math.max(0,timing.duration-Number(vm.count));
}
return Number.isFinite(timing.start)?Math.max(0,(Date.now()-timing.start)/1000):null;
},
commitExam: async function(records, vm) {
const elapsed=this.examElapsedSeconds(vm);
if(elapsed!==null && elapsed<60){
const overlay=utils.showBigNotice('请满一分钟后再提交','考试已进行 '+Math.floor(elapsed)+' 秒。过早提交,网站不会统计成绩,会显示 0 分。请再等待 '+Math.ceil(60-elapsed)+' 秒后重新提交。','warning');
const box=overlay.firstElementChild;
box.style.background='#f8fafc';box.style.color='#173f82';
this.updateStatus('考试不足一分钟,已暂停提交');
return 'blocked';
}
if (!vm || typeof vm.submit !== 'function') {
this.errors.push('无法访问考试页面答案状态');
this.updateStatus('等待手动提交');
// 【2.5.19】按钮不再留失败态,失败只靠 toast 说话 —— 这条分支原先只改状态条,补上 toast 免丢信息
utils.showMessage('无法访问考试提交按钮,请在页面上手动提交', 'warning', 8000);
return false;
}
if (records && records.length) {
const last = records[records.length - 1];
vm.index = records.length - 1;
vm.seria = `第${records.length}题`;
vm.model = Object.assign({}, last);
vm.model.kind_text = String(last.kind) === '1' ? '判断题' : String(last.kind) === '3' ? '多选题' : '单选题';
this.syncDisplayedQuestion(vm);
if (typeof vm.$nextTick === 'function') await new Promise(resolve => vm.$nextTick(resolve));
}
const confirmation = ExamProcessor.confirmExamSubmission();
vm.submit();
const confirmed = await confirmation;
this.submitted = !!confirmed;
this.persist();
this.updateStatus(confirmed ? '已确认提交,等待评分结果' : '二次确认失败,请手动提交');
if (!confirmed) utils.showMessage('提交二次确认未完成,请在页面上手动确认', 'warning');
return confirmed;
},
// 缺失题号文本(先带原始序号再过滤 —— 不能 filter 后再取 index,会错位成过滤后的下标)
missingSeqText: function(records) {
const missingSeqs = records
.map((record, index) => ({ record: record, seq: index + 1 }))
.filter(item => !this.answers.has(String(item.record.id)))
.map(item => item.seq);
return this.summarizeSeqs(missingSeqs);
},
// 【2.5.16】「提交本次考试」入口:纯提交(不再顺带填入答案 —— 填入由另一枚按钮负责)
// 底部拦截:页面上一个答案都没有时不提交,避免白耗一次考试机会
manualSubmit: async function() {
// 【2.5.18】本场已提交过就不再交(原先靠按钮的「已提交」终态拦;按钮不再留态,改在入口拦)
if (this.submitted) {
Logger.add('warning', '提交被拦截:本场考试已提交过');
utils.showMessage('本场考试已提交过,已拦截重复提交
如需重跑请先「清除考试数据」', 'warning', 8000);
this.updateStatus('提交已拦截:本场已提交过');
return 'blocked';
}
// 【2.5.20】不再依赖 activeRecordId / lastRecords(清过数据它们就是空的,会把提交整个废掉):
// 找不到内存记录时从页面上反查考试实例,判据一律以「卷面上有没有答案」为准
const ctx = this.resolveExamContext();
const vm = ctx.vm;
const records = ctx.records;
if (!vm) {
utils.showMessage('无法访问考试页面,请保持在考试页面后重试', 'warning');
this.updateStatus('提交失败:页面不可访问');
return false;
}
const filled = this.countFilledOnPage(vm, records.length ? records : null);
if (!filled) {
Logger.add('warning', '提交被拦截:页面上没有任何答案');
utils.showMessage('页面上还没有答案,已拦截本次提交
请先点「填入答案」,或自行在页面上作答后再提交', 'warning', 8000);
this.updateStatus('提交已拦截:页面无答案');
return 'blocked';
}
// 完整性只在「脚本手里确有答案清单」时才谈 —— 清过数据后 answers 为空,
// 若照旧比对会误报「答案不完整 0/100」,而卷面其实是满的
if (this.answers.size && records.length && this.answers.size !== records.length) {
Logger.milestone(`提交:答案不完整 ${this.answers.size}/${records.length}(页面已填 ${filled})`);
utils.showMessage(`⚠️ 按手动意愿提交(答案不完整 ${this.answers.size}/${records.length})
缺失题号:${this.missingSeqText(records)}`, 'warning', 8000);
} else if (records.length) {
Logger.milestone(`提交:答案完整,页面已填 ${filled}/${records.length}`);
} else {
Logger.milestone(`提交:页面已填 ${filled} 题(题目清单不在手上,以卷面为准)`);
}
return await this.commitExam(records, vm);
},
// 【2.5.16】「填入答案」入口:只把已得答案写进页面,不提交
manualFill: async function() {
if (!this.answers || !this.answers.size) {
utils.showMessage('暂无已获取的答案,请先让批量答题跑一轮', 'warning');
return false;
}
// 【2.5.20】同上:内存记录缺失时从页面反查,别让「清过数据」把填入也废掉
const ctx = this.resolveExamContext();
const records = ctx.records;
const recordId = ctx.recordId;
if (!records.length || !recordId) {
utils.showMessage('尚无可填入的考试数据,请先让批量答题跑一轮', 'warning');
return false;
}
const vm = await this.applyAnswersToPage(records, recordId, this.runId, true);
if (!vm) {
utils.showMessage('无法访问考试页面,请保持在考试页面后重试', 'warning');
this.updateStatus('填入失败:页面不可访问');
return false;
}
const filled = this.countFilledOnPage(vm, records);
if (this.answers.size !== records.length) {
Logger.milestone(`填入答案:不完整 ${this.answers.size}/${records.length}(页面已填 ${filled})`);
utils.showMessage(`已填入已得的答案 ${this.answers.size}/${records.length}
缺失题号:${this.missingSeqText(records)}`, 'warning', 8000);
} else {
Logger.milestone(`填入答案:完整 ${this.answers.size}/${records.length},未提交`);
}
return true;
},
// 数一下页面上真的有答案的题数(提交前的拦截依据:看页面真实状态,不看脚本记忆)
// 【2.5.20】records 允许缺省 —— 清除过数据 / 刷新过之后题目清单可能不在手上,
// 此时直接数 param 里的非空项;判据始终是「卷面上有没有答案」,与脚本内存无关
countFilledOnPage: function(vm, records) {
if (!vm || !vm.param) return 0;
const isNonEmpty = value => Array.isArray(value)
? value.length > 0
: (value !== undefined && value !== null && String(value) !== '');
let n = 0;
if (Array.isArray(records) && records.length) {
for (const record of records) {
if (isNonEmpty(vm.param[String(record.id)])) n++;
}
return n;
}
for (const key of Object.keys(vm.param)) {
if (isNonEmpty(vm.param[key])) n++;
}
return n;
},
// 【2.5.20】解析当前考试上下文:优先用脚本内存;内存被清过(activeRecordId 为空)时
// 直接从页面上反查正在进行的考试实例 —— 这样「清除考试数据」不会让提交功能失效
resolveExamContext: function() {
let records = this.lastRecords || [];
let recordId = this.activeRecordId ? String(this.activeRecordId) : '';
let vm = recordId ? this.findExamVm(recordId) : null;
if (!vm) {
const active = this.findActiveExamVm();
if (active) {
vm = active;
if (!records.length && Array.isArray(active.records)) records = active.records;
if (!recordId) recordId = String(active.recordId || '');
}
}
return { vm: vm, records: records, recordId: recordId };
},
// 【2.5.20】卷面上已作答的题数(找不到考试页面时为 0)
// 「提交本次考试」的可用性判据用它 —— 只要卷子有答案就该能交,哪怕脚本手里是空的
pageFilledCount: function() {
const active = this.findActiveExamVm();
if (!active) return 0;
return this.countFilledOnPage(active, Array.isArray(active.records) && active.records.length ? active.records : null);
},
fillAnswers: async function(records, recordId, runId) {
const vm = await this.applyAnswersToPage(records, recordId, runId, false);
if (runId !== this.runId) return false;
if (!vm) return false;
if (!currentConfig.examAutoSubmit) {
Logger.milestone(`自动提交已关闭:答案已填入页面 ${this.answers.size}/${records.length},等待手动提交`);
this.updateStatus(`答案已填入页面 ${this.answers.size}/${records.length}\n自动提交已关闭 → 请点击面板「手动提交」`);
this.syncSubmitUI();
return true;
}
return await this.commitExam(records, vm);
},
// 把缺失题号压成区间文本:61,62,...,70 -> 61-70
summarizeSeqs: function(seqs) {
if (!seqs.length) return '无';
const sorted = [...seqs].sort((a, b) => a - b);
const parts = [];
let start = sorted[0];
let prev = sorted[0];
for (let i = 1; i <= sorted.length; i++) {
const current = sorted[i];
if (current === prev + 1) { prev = current; continue; }
parts.push(start === prev ? String(start) : `${start}-${prev}`);
start = current;
prev = current;
}
return parts.join('、');
},
// 【2.5.18】手动重试:只把「上一轮没答出」的题重新交给 AI 跑一遍
// 与「重跑整场」的区别:已答出的题不再请求(不重复扣费),已得答案与统计读数都保留
retryMissing: async function() {
if (this.running) {
utils.showMessage('正在答题,请等本轮结束后再重试', 'warning');
return false;
}
if (this.submitted) {
utils.showMessage('本场考试已提交过,无需重试
如需重跑请先「清除考试数据」', 'warning', 8000);
return false;
}
const records = this.lastRecords || [];
const recordId = this.activeRecordId;
if (!records.length || !recordId) {
utils.showMessage('尚无可重试的考试数据,请先让批量答题跑一轮', 'warning');
return false;
}
const allQuestions = this.questionModels && this.questionModels.length
? this.questionModels
: records.map((record, index) => this.normalizeQuestion(record, index));
const missing = allQuestions.filter(question => !this.answers.has(String(question.id)));
if (!missing.length) {
utils.showMessage('全部题目都已答出,无需重试', 'info');
return false;
}
const missingText = this.summarizeSeqs(missing.map(question => question.seq));
Logger.milestone(`手动重试未答出题目 ${missing.length}/${allQuestions.length},题号:${missingText}`);
utils.showMessage(`重新请求 ${missing.length} 道未答出的题目
题号:${missingText}`, 'info', 6000);
this.run(records, recordId, { append: true }).catch(error => {
this.running = false;
this.errors.push(`重试未答出题目异常:${error.message || error}`);
this.updateStatus('重试失败');
});
return true;
},
// 【2.5.18】options.append = 重试模式:保留已得答案 / 统计 / 已提交标记,只把「未答出」的题再跑一遍
run: async function(records, recordId, options) {
const append = !!(options && options.append);
const runId = ++this.runId;
this.running = true;
this.activeRecordId = String(recordId);
if (!append) {
this.lastRecords = records;
this.answers = new Map();
this.answerSources = new Map();
this.failedQuestions = new Set();
this.errors = [];
// 【2.5.7】每轮开始重置统计与调度状态(续跑恢复会随后覆盖统计)
this.stats = { requests: 0, failedBatches: 0 };
this.submitted = false;
// 【2.5.16】新一场考试:槽位按钮状态一并复位,否则上一场遗留的态会一直挂着
this.resetSlotButtons();
}
this.netFailStreak = 0;
this.aborted = false;
this.balanceBlocked = false;
this.cardErrorCode = '';
this.abortReason = '';
this.nextTokenAt = 0;
this.syncSubmitUI();
// 本轮进度计数每轮从零起(重试轮也一样)
this.completedBatches = 0;
this.runningBatches = 0;
// 本轮运行的参数在开始时定格:中途拖动滑块不会打乱正在跑的批次划分
const batchSize = clampExamBatchSize(currentConfig.examBatchSize);
const concurrency = clampExamConcurrency(currentConfig.examConcurrency);
// 题目全集(本场不变量):seq 按原始下标定格,重试子集沿用同一套序号,缺失题号才不会错位
const allQuestions = append && this.questionModels && this.questionModels.length
? this.questionModels
: records.map((record, index) => this.normalizeQuestion(record, index));
this.questionModels = allQuestions;
this.totalQuestions = allQuestions.length;
// 正常模式跑全集;重试模式只跑「答案表里还没有」的那部分(已答出的不重复请求)
const questions = append
? allQuestions.filter(question => !this.answers.has(String(question.id)))
: allQuestions;
this.refreshPlanUI();
const invalid = questions.filter(question => !question.id || !question.question || !question.options.length);
if (invalid.length) {
this.errors.push(`${invalid.length} 道题缺少题干或选项`);
this.running = false;
this.updateStatus('题目解析失败');
return;
}
// 【2.5.7】续跑:同场次已有落盘答案则恢复;已拿全答案的批次随后会被跳过(不重复扣费)
const restored = this.restore(String(recordId), allQuestions);
if (restored) {
Logger.add('info', '考试续跑', `已从本地恢复 ${restored} 条答案,已完成的批次将跳过`);
}
// 【2.5.18】恢复出的「已提交」不再挂到按钮上(按钮无终态);重复提交由 manualSubmit 入口拦截
this.syncSubmitUI();
const ready = await AuthService.ensureReady();
if (!ready.ok || runId !== this.runId) {
if (['INSUFFICIENT_BALANCE','CARD_NOT_FOUND','CARD_DISABLED','CARD_EXPIRED','ACCOUNT_MISMATCH','CARD_NOT_ACTIVATED','CARD_REQUIRED','ACCOUNT_REQUIRED'].includes(ready.code)) this.stopForInsufficientBalance(ready.error,ready.code);
if (!ready.ok) this.errors.push(ready.error);
this.running = false;
this.updateStatus('授权校验失败');
return;
}
const batches = [];
for (let index = 0; index < questions.length; index += batchSize) {
batches.push(questions.slice(index, index + batchSize));
}
this.totalBatches = batches.length;
this.adapt = { effective: concurrency, window: [], successStreak: 0, rateLimited: false };
this.updateStatus(`已捕获 ${questions.length} 题,AI 答题中${restored ? `(续跑,已恢复 ${restored} 条)` : ''}`);
let cursor = 0;
const pool = { active: 0 };
// 许可闸门:worker 数固定为滑块上限,但同一时刻真正出站的批数由 adapt.effective 放行
const acquire = async () => {
while (runId === this.runId && !this.aborted && pool.active >= this.adapt.effective) {
await new Promise(resolve => setTimeout(resolve, 60));
}
if (runId !== this.runId || this.aborted) return false;
pool.active++;
return true;
};
const worker = async () => {
while (runId === this.runId && !this.aborted) {
const batchIndex = cursor++;
if (batchIndex >= batches.length) return;
const batch = batches[batchIndex];
// 续跑:整批已拿到答案 ⇒ 跳过,不再请求(省扣费)
if (this.isBatchSatisfied(batch)) {
this.completedBatches++;
this.updateStatus(`第 ${batchIndex + 1} 批已有答案,跳过`);
continue;
}
const allowed = await acquire();
if (!allowed) return;
this.runningBatches++;
this.updateStatus(`处理第 ${batchIndex + 1} 批`);
try {
const outcome = await this.answerBatch(batch, runId);
if (runId !== this.runId) return;
for (const [id, answer] of outcome.answers) this.answers.set(id, answer);
this.recordBatchOutcome(batch, outcome);
this.persist();
} catch (error) {
this.errors.push(`第 ${batchIndex + 1} 批异常:${error.message || error}`);
this.recordBatchOutcome(batch, { answers: new Map(), failCode: 'EXCEPTION' });
this.persist();
} finally {
pool.active--;
if(runId===this.runId){
this.runningBatches--;
this.completedBatches++;
this.updateStatus(`第 ${batchIndex + 1} 批完成`);
}
}
}
};
await Promise.all(Array.from({ length: Math.min(concurrency, batches.length) }, worker));
if (runId !== this.runId) return;
this.running = false;
this.persist();
this.syncSubmitUI();
if (this.aborted) {
this.updateStatus(this.abortReason);
return;
}
// 【2.5.18】完整性一律按「本场全集」判定 —— 重试轮只跑了缺失子集,不能用子集长度比
if (this.answers.size !== allQuestions.length) {
const missingSeqs = allQuestions.filter(question => !this.answers.has(question.id)).map(question => question.seq);
const missingText = this.summarizeSeqs(missingSeqs);
this.updateStatus(`答案不完整 ${this.answers.size}/${allQuestions.length},已停止自动提交\n缺失题号:${missingText}`);
Logger.add('error', `考试答案不完整 ${this.answers.size}/${allQuestions.length},缺失题号:${missingText}`);
utils.showMessage(`⚠️ 考试答案不完整(${this.answers.size}/${allQuestions.length}),已停止提交
缺失题号:${missingText}
可点「重试未答出题目」再试,或先调大「等待超时」`, 'warning', 9000);
return;
}
// 填入用整场的原始题面(重试轮传子集会让 applyAnswersToPage 的完整性校验对不上)
await this.fillAnswers(this.lastRecords || records, recordId, runId);
this.syncSubmitUI();
},
captureStartExam: function(data) {
this.pending = false;
const result = data && data.success && data.result;
if(result && result.id){
const start=Date.parse(String(result.startTime||result.createTime||'').replace(/-/g,'/'));
const timing={start:Number.isFinite(start)?start:Date.now(),duration:Number(result.examTime)*60};
try{sessionStorage.setItem('examTiming:'+result.id,JSON.stringify(timing));}catch(e){}
}
const records = result && result.records;
if (!this.available() || !Array.isArray(records) || !records.length || !result.id) {
if (!this.activeRecordId) this.updateStatus('等待考试开始');
return;
}
if (this.activeRecordId === String(result.id)) return;
this.run(records, String(result.id)).catch(error => {
this.running = false;
this.errors.push(`批量答题异常:${error.message || error}`);
this.updateStatus('运行失败');
});
},
boot: function() {
if (this.hookInstalled) return;
this.hookInstalled = true;
const self = this;
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
this.__examBatchUrl = String(url || '');
if (this.__examBatchUrl.includes('/jcedutec/exam/startExam')) {
self.pending = true;
self.updateStatus('等待考试题目');
}
return originalOpen.apply(this, arguments);
};
const originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function() {
if (this.__examBatchUrl && this.__examBatchUrl.includes('/jcedutec/exam/startExam')) {
this.addEventListener('load', () => {
let data = this.response;
if (typeof data === 'string') {
try { data = JSON.parse(data); } catch (error) { data = null; }
}
self.captureStartExam(data);
}, { once: true });
this.addEventListener('error', () => { self.pending = false; self.updateStatus('考试题目请求失败'); }, { once: true });
}
return originalSend.apply(this, arguments);
};
const originalFetch = window.fetch;
if (typeof originalFetch === 'function') {
window.fetch = async function(input, init) {
const url = typeof input === 'string' ? input : input && input.url || '';
if (String(url).includes('/jcedutec/exam/startExam')) {
self.pending = true;
self.updateStatus('等待考试题目');
}
const response = await originalFetch.apply(this, arguments);
if (String(url).includes('/jcedutec/exam/startExam')) {
response.clone().json().then(data => self.captureStartExam(data)).catch(() => {
self.pending = false;
self.updateStatus('考试题目响应解析失败');
});
}
return response;
};
}
if ((location.hostname === '127.0.0.1' || location.protocol === 'file:') && !window.__labSafetyExamMockInstalled) {
window.__labSafetyExamMockInstalled = true;
window.addEventListener('lab-safety:mock-exam', event => this.captureStartExam(event.detail));
}
this.updateStatus('等待考试开始');
}
};
// 只暴露诊断快照,不暴露答案内容或内部可变对象。
window.__labSafetyExamBatchDebug = () => ({
pending: ExamBatchProcessor.pending,
running: ExamBatchProcessor.running,
activeRecordId: ExamBatchProcessor.activeRecordId,
completedBatches: ExamBatchProcessor.completedBatches,
totalBatches: ExamBatchProcessor.totalBatches,
totalQuestions: ExamBatchProcessor.totalQuestions,
questionModels: ExamBatchProcessor.questionModels.length,
submitted: ExamBatchProcessor.submitted,
runningBatches: ExamBatchProcessor.runningBatches,
answerCount: ExamBatchProcessor.answers.size,
errors: [...ExamBatchProcessor.errors]
});
// ============================ 推进器(核心循环,3.0 重写) ============================
// 全树序绕环推进;运行期完全本地记账,平台状态只在冷启动读一次当基线。
// 主判据 ended(document 捕获阶段监听,切课换