正文
增加 716 行删除 6 行
4 行未改动56789101112133 行未改动171819202122232425262728293031323335 行未改动69707172737475767778798081828352 行未改动136137138139140141142143876 行未改动全部展开102010211022102310241025102610279 行未改动103710381039104010411042104310444 行未改动1049105010511052105310544 行未改动- 私信界面 Ctrl+点击 聊天列表或聊天框中的用户名或头像,即可直接打开用户主页。- 显示其他用户个人页面中被系统隐藏的个人简介。- 脚本管理插件中一键更新最新版本的LuoguSP插件。关于插件的建议及BUG反馈,评论区留言 或 私信 或 [Github项目](https://github.com/ShanireZ/LuoguSP) 中提交Issues都可。安装方式和之前一样:1. 先安装油猴/篡改猴/暴力猴之类的浏览器插件。推荐使用Edge浏览器,因为它的插件市场能直接访问。2. 点击新增脚本,复制下方的脚本内容,不要有所遗漏。3 行未改动```javascript// ==UserScript==// @name LuoguSP// @namespace https://github.com/ShanireZ/LuoguSP// @version 2.8.5// @description LuoguSP:题目难度着色 / 私信 Ctrl+Click(用户名+头像) 跳转主页 / 显示隐藏的个人简介// @author ShanireZ, realskc (Until 1.8.2)// @license GPL-3.0// @match https://www.luogu.com.cn/*// @homepageURL https://github.com/ShanireZ/LuoguSP// @supportURL https://github.com/ShanireZ/LuoguSP/issues// @updateURL https://raw.githubusercontent.com/ShanireZ/LuoguSP/main/LuoguSP.user.js// @downloadURL https://raw.githubusercontent.com/ShanireZ/LuoguSP/main/LuoguSP.user.js// @grant none// @require https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js// @require https://cdn.jsdelivr.net/npm/marked@4.3.0/marked.min.js// @require https://cdn.jsdelivr.net/npm/dompurify@3.0.9/dist/purify.min.js35 行未改动chatTrigger: '[slot="trigger"]', // 私信用户名触发点(旧 data-v 选择器已失效,用语义属性)userIntroColumn: ".sidebar-container .main", // 用户主页右侧内容列(补显简介的挂载点)nativeIntro: ".introduction", // 洛谷原生简介元素(存在=已显示,脚本不重复补)voidAnchor: "a[data-v-bade3303][data-v-4842157a]", // 题号着色里特殊的 javascript:void 0 链接};// 功能开关:key → 显示名。新增功能只需在此登记 + 在底部 FEATURES 注册启动器。const FEATURE_LABELS = new Map([[`${STORAGE_PREFIX}addProblemsColor`, "显示题目颜色"],[`${STORAGE_PREFIX}addMessageLink`, "私信界面 Ctrl+Click 打开用户主页"],[`${STORAGE_PREFIX}showIntro`, "显示隐藏的个人简介"],]);const storage = {get: (k) => localStorage.getItem(k) === "true",52 行未改动.luogusp-intro-card .hljs-bullet,.luogusp-intro-card .hljs-link,.luogusp-intro-card .hljs-meta,.luogusp-intro-card .hljs-selector-id,.luogusp-intro-card .hljs-symbol,.luogusp-intro-card .hljs-title{color:#4078f2;}.luogusp-intro-card .hljs-built_in,.luogusp-intro-card .hljs-class .hljs-title,.luogusp-intro-card .hljs-title.class_,.luogusp-intro-card .hljs-title.function_{color:#c18401;}.luogusp-intro-card .hljs-emphasis{font-style:italic;}.luogusp-intro-card .hljs-strong{font-weight:700;}`;(document.head || document.documentElement).appendChild(style);}876 行未改动全部展开document.querySelectorAll("a[href]").forEach(colorAnchor);}// ============================================================// 启动// ============================================================const isChatPage = location.href.startsWith("https://www.luogu.com.cn/chat");9 行未改动if (isChatPage) setTimeout(addMessageLink, 500);},},{ key: `${STORAGE_PREFIX}showIntro`, run: watchHiddenIntro },];injectStyle();for (const f of FEATURES) {4 行未改动console.error("LuoguSP feature failed:", e);}}})();```4 行未改动56789101112133 行未改动171819202122232425262728293031323335 行未改动6970717273747576777879808182838485868788899091929352 行未改动146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183876 行未改动全部展开1060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617379 行未改动1747174817491750175117521753175417554 行未改动176017611762176317644 行未改动- 私信界面 Ctrl+点击 聊天列表或聊天框中的用户名或头像,即可直接打开用户主页。- 显示其他用户个人页面中被系统隐藏的个人简介。- 脚本管理插件中一键更新最新版本的LuoguSP插件。关于插件的建议及BUG反馈,评论区留言 或 私信 或 [Gitee项目](https://gitee.com/shanire/LuoguSP) 中提交Issues都可。安装方式和之前一样:1. 先安装油猴/篡改猴/暴力猴之类的浏览器插件。推荐使用Edge浏览器,因为它的插件市场能直接访问。2. 点击新增脚本,复制下方的脚本内容,不要有所遗漏。3 行未改动```javascript// ==UserScript==// @name LuoguSP// @namespace https://github.com/ShanireZ/LuoguSP// @version 2.9.2// @description LuoguSP:题目难度着色 / 私信 Ctrl+Click(用户名+头像) 跳转主页 / 显示隐藏的个人简介 / IDE 一键测试样例// @author ShanireZ, realskc (Until 1.8.2)// @license GPL-3.0// @match https://www.luogu.com.cn/*// @homepageURL https://github.com/ShanireZ/LuoguSP// @supportURL https://github.com/ShanireZ/LuoguSP/issues// @updateURL https://gitee.com/shanire/LuoguSP/raw/main/LuoguSP.user.js// @downloadURL https://gitee.com/shanire/LuoguSP/raw/main/LuoguSP.user.js// @grant none// @require https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js// @require https://cdn.jsdelivr.net/npm/marked@4.3.0/marked.min.js// @require https://cdn.jsdelivr.net/npm/dompurify@3.0.9/dist/purify.min.js35 行未改动chatTrigger: '[slot="trigger"]', // 私信用户名触发点(旧 data-v 选择器已失效,用语义属性)userIntroColumn: ".sidebar-container .main", // 用户主页右侧内容列(补显简介的挂载点)nativeIntro: ".introduction", // 洛谷原生简介元素(存在=已显示,脚本不重复补)voidAnchor: "a[data-v-bade3303][data-v-4842157a]", // 题号着色里特殊的 javascript:void 0 链接// —— IDE 模式(2026-07 columba 前端;侦察实录 docs/superpowers/specs/2026-07-22-ide-mode-recon-notes.md)——ideToolbar: ".ide-toolbar", // IDE 三个分区(代码/输入/输出)各一条工具栏ideToolbarText: ".title .text", // 工具栏标题文字(代码/输入/输出)ideToolbarActions: ".actions", // 工具栏右侧按钮容器ideRunResult: ".run-result", // 输出工具栏里的 时间+内存 / RE 原因ideTextarea: "textarea.ide-textarea", // 输入/输出面板的文本域ideSampleBlock: ".io-sample-block", // 题面样例块(输入 #N / 输出 #N 各一块)cmContent: ".cm-content", // CodeMirror 6 内容层lentilleContext: "script#lentille-context", // 新版页面数据(JSON,含 problem.samples)};// 功能开关:key → 显示名。新增功能只需在此登记 + 在底部 FEATURES 注册启动器。const FEATURE_LABELS = new Map([[`${STORAGE_PREFIX}addProblemsColor`, "显示题目颜色"],[`${STORAGE_PREFIX}addMessageLink`, "私信界面 Ctrl+Click 打开用户主页"],[`${STORAGE_PREFIX}showIntro`, "显示隐藏的个人简介"],[`${STORAGE_PREFIX}ideBatchSampleTest`, "IDE 一键测试样例"],]);const storage = {get: (k) => localStorage.getItem(k) === "true",52 行未改动.luogusp-intro-card .hljs-bullet,.luogusp-intro-card .hljs-link,.luogusp-intro-card .hljs-meta,.luogusp-intro-card .hljs-selector-id,.luogusp-intro-card .hljs-symbol,.luogusp-intro-card .hljs-title{color:#4078f2;}.luogusp-intro-card .hljs-built_in,.luogusp-intro-card .hljs-class .hljs-title,.luogusp-intro-card .hljs-title.class_,.luogusp-intro-card .hljs-title.function_{color:#c18401;}.luogusp-intro-card .hljs-emphasis{font-style:italic;}.luogusp-intro-card .hljs-strong{font-weight:700;}.luogusp-ide-tabbar{display:flex;gap:20px;padding:0 12px;border-bottom:1px solid #e8e8e8;flex:none;}.luogusp-ide-tab{font-size:13px;color:#606266;padding:7px 2px 5px;cursor:pointer;border-bottom:2px solid transparent;}.luogusp-ide-tab.on{color:#3498db;border-bottom-color:#3498db;font-weight:500;}.luogusp-ide-panel{overflow:auto;flex:1 1 0;min-height:0;padding:8px 12px 12px;font-size:13px;color:#333;}.luogusp-ide-head{display:flex;align-items:center;gap:10px;margin-bottom:8px;}.luogusp-ide-title{font-weight:500;}.luogusp-ide-summary{font-size:12px;color:#888;}.luogusp-ide-headbtns{margin-left:auto;display:flex;gap:6px;}.luogusp-ide-row{border:1px solid #e8e8e8;border-radius:6px;margin:0 0 8px;background:#fff;overflow:hidden;}.luogusp-ide-rowhead{display:flex;align-items:center;gap:10px;padding:8px 12px;cursor:pointer;}.luogusp-ide-rowhead:hover{background:#f7fbfe;}.luogusp-ide-chev{color:#999;width:10px;transition:transform .2s;}.luogusp-ide-row.open .luogusp-ide-chev{transform:rotate(90deg);}.luogusp-ide-meta{font-size:12px;color:#999;margin-left:auto;}.luogusp-ide-pill{font-size:12px;padding:1px 10px;border-radius:10px;border:1px solid transparent;white-space:nowrap;}.luogusp-ide-detail{display:none;border-top:1px solid #eee;background:#fcfcfc;padding:10px 12px;}.luogusp-ide-row.open .luogusp-ide-detail{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;}.luogusp-ide-row.open .luogusp-ide-detail.luogusp-ide-log{display:block;}@media (max-width:1500px){.luogusp-ide-row.open .luogusp-ide-detail{grid-template-columns:1fr;}}.luogusp-ide-pane h5{margin:0 0 4px;font-size:12px;font-weight:500;color:#888;}.luogusp-ide-pane .code-container{margin:0;}.luogusp-ide-pane pre{margin:0;border:1px solid #e6e6e6;border-radius:4px;background:#fff;padding:6px 8px;font-size:12px;line-height:1.55;color:#333;overflow-x:auto;min-height:40px;font-family:"Fira Code","Fira Mono",Menlo,Consolas,"DejaVu Sans Mono",monospace;}.luogusp-ide-pane .luogusp-ide-diffline{background:#fcebeb;color:#a32d2d;display:block;margin:0 -8px;padding:0 8px;}.luogusp-ide-note{font-size:12px;color:#a32d2d;margin:0 0 8px;}.luogusp-ide-empty{color:#aaa;font-style:italic;}.luogusp-ide-legend{display:flex;flex-wrap:wrap;gap:6px;align-items:center;margin-top:10px;padding-top:8px;border-top:1px dashed #eee;font-size:12px;color:#999;}.luogusp-ide-panel .code-container:hover>.copy-button{opacity:1;}.luogusp-ide-panel .copy-button{position:absolute;top:.3em;right:.3em;padding:.45em;display:flex;align-items:center;justify-content:center;transition:opacity .2s;opacity:0;background:transparent;border:0;border-radius:4px;cursor:pointer;color:#555;}.luogusp-ide-panel .copy-button.copied{color:#52c41a;}.luogusp-ide-panel .copy-icon{width:1em;height:1em;}`;(document.head || document.documentElement).appendChild(style);}876 行未改动全部展开document.querySelectorAll("a[href]").forEach(colorAnchor);}// ============================================================// IDE 一键测试样例// 洛谷新版题目页(columba)IDE 模式(#ide)下,逐组驱动题面样例的原生「运行」,// 结果从输出面板 DOM 捕获(结果经页面常驻 WS 推送,网络层拿不到——勿改走拦截)。// 锚点与配色的事实来源:docs/superpowers/specs/2026-07-22-ide-mode-recon-notes.md// ============================================================function ideToolbarByTitle(title) {for (const tb of document.querySelectorAll(SELECTORS.ideToolbar)) {const t = tb.querySelector(SELECTORS.ideToolbarText);if (t && t.textContent.trim() === title) return tb;}return null;}const IDE_BATCH = {running: false, // 批测进行中(防重入)stopReq: false, // 「停止」请求:当前组跑完即停driving: false, // 程序化点击原生按钮的瞬间为 true(区分用户手点)activeTab: "custom", // custom=原生输入输出 / samples=样例面板tabBar: null,panel: null,ioLayout: null, // 原生 输入|输出 水平分栏(tab 切换时显隐)rowsEl: null,summaryEl: null,stopBtn: null,results: null, // 本轮各组结果(过期标注用)stale: false,inputSnapshot: null, // 批测前用户自定义输入快照};function ideModeActive() {return (location.hash === "#ide" && !!document.querySelector(SELECTORS.ideToolbar));}function lentilleProblem() {try {const el = document.querySelector(SELECTORS.lentilleContext);if (!el) return null;const json = JSON.parse(el.textContent);return (json && json.data && json.data.problem) || null;} catch (e) {return null;}}function currentPid() {const m = location.pathname.match(/^\/problem\/([A-Za-z0-9_]+)/);return m ? m[1] : "";}async function getIdeSamples() {const pid = currentPid();if (!pid) return null;const p = lentilleProblem();if (p && p.pid === pid && Array.isArray(p.samples)) return p.samples;// SPA 换题后 lentille-context 滞留旧题(真机实测)→ 新版内容接口兜底。// 注意:旧 `?_contentOnly=1` 在 columba 页面已死(返回整页 HTML),// 正确姿势是带 x-lentille-request 头(真机实测 2026-07-22)。try {const res = await fetch(`/problem/${pid}`, {headers: { "x-lentille-request": "content-only" },});const json = await res.json();const prob = json && json.data && json.data.problem;if (prob && Array.isArray(prob.samples)) return prob.samples;} catch (e) {console.error("LuoguSP ide samples:", e);}return null;}function sampleRunButtons() {// 「输入 #N」「输出 #N」各一块都带「运行」;只取输入块的,按 DOM 序=样例序const btns = [];for (const block of document.querySelectorAll(SELECTORS.ideSampleBlock)) {if (!/^(输入|Input)/i.test((block.textContent || "").trim())) continue;const run = [...block.querySelectorAll("a, button")].find((b) => (b.textContent || "").trim() === "运行",);if (run) btns.push(run);}return btns;}function readIdeCode() {const content = document.querySelector(SELECTORS.cmContent);if (!content) return "";// 洛谷构建把 CM6 的 cmView 命名为 cmTile;拿不到就退化为可见文本(空代码检测够用)const view = content.cmTile && content.cmTile.view;if (view && view.state && view.state.doc) return view.state.doc.toString();return content.textContent || "";}let ideSubmitWaiter = null;function installIdeSubmitObserver() {if (XMLHttpRequest.prototype.open.__luoguspIde) return;const rawOpen = XMLHttpRequest.prototype.open;const rawSend = XMLHttpRequest.prototype.send;const open = function (method, url) {this.__luoguspIdeSubmit =typeof url === "string" && url.indexOf("/api/ide_submit") !== -1;return rawOpen.apply(this, arguments);};const send = function () {if (this.__luoguspIdeSubmit)this.addEventListener("loadend", () => {if (ideSubmitWaiter) {const w = ideSubmitWaiter;ideSubmitWaiter = null;w(this.status);}});return rawSend.apply(this, arguments);};open.__luoguspIde = true;XMLHttpRequest.prototype.open = open;XMLHttpRequest.prototype.send = send;}function waitIdeSubmit(ms) {return new Promise((resolve) => {const timer = setTimeout(() => {if (ideSubmitWaiter === fn) ideSubmitWaiter = null;resolve(null);}, ms);const fn = (status) => {clearTimeout(timer);resolve(status);};ideSubmitWaiter = fn;});}const sleep = (ms) => new Promise((r) => setTimeout(r, ms));function outputParts() {const tb = ideToolbarByTitle("输出");if (!tb) return null;const actions = tb.querySelector(SELECTORS.ideToolbarActions);const spans = actions ? [...actions.querySelectorAll("span")] : [];return {pill: spans.find((s) => !s.classList.contains("run-result")) || null,rr: actions ? actions.querySelector(SELECTORS.ideRunResult) : null,textarea: tb.parentElement? tb.parentElement.querySelector(SELECTORS.ideTextarea): null,};}// 完成锚点:胶囊 存在→消失→重现(实测清空 300~560ms、结果 1~3.5s;详见侦察实录)// 注意:此处不看 stopReq——设计口径是「当前组跑完即停」,停止只在组间生效async function waitIdePill(present, timeoutMs) {const t0 = Date.now();while (Date.now() - t0 < timeoutMs) {const parts = outputParts();if (!parts) return null; // IDE 已卸载if (!!parts.pill === present) return parts.pill || true;await sleep(150);}return null;}async function runOneSample(runBtn) {const before = outputParts();if (!before) return { verdict: "UKE", note: "IDE 面板不存在" };const hadPill = !!before.pill;let submitP = waitIdeSubmit(10000);IDE_BATCH.driving = true;runBtn.click();IDE_BATCH.driving = false;let status = await submitP;if (status === 429) {await sleep(3000); // 限流:等 3s 原地重试一次submitP = waitIdeSubmit(10000);IDE_BATCH.driving = true;runBtn.click();IDE_BATCH.driving = false;status = await submitP;}if (status == null || status < 200 || status >= 300)return {verdict: "UKE",note: status == null ? "未观测到提交请求" : `提交失败 HTTP ${status}`,};if (hadPill && (await waitIdePill(false, 5000)) === null)return { verdict: "UKE", note: "旧结果未清空,疑似运行未开始" };const pill = await waitIdePill(true, 30000);if (!pill || pill === true)return { verdict: "UKE", note: "30s 未返回结果" };const parts = outputParts();return {verdict: (pill.textContent || "").trim() || "UKE",pillStyle: pill.getAttribute("style") || "",detail: parts.rr ? parts.rr.textContent.trim() : "",output: parts.textarea ? parts.textarea.value : "",};}function ideBatchHint(msg) {const btn = document.querySelector(".luogusp-ide-batch-btn");if (!btn) return;const old = btn.textContent;btn.textContent = msg;btn.disabled = true;setTimeout(() => {btn.textContent = old;btn.disabled = IDE_BATCH.running;}, 1500);}async function startIdeBatch() {if (IDE_BATCH.running) return;mountIdeTabs();const samples = await getIdeSamples();if (!samples || !samples.length) return ideBatchHint("本题无样例");if (!readIdeCode().trim()) return ideBatchHint("代码为空");const runBtns = sampleRunButtons();if (!runBtns.length) return ideBatchHint("找不到样例运行按钮");const n = Math.min(samples.length, runBtns.length);if (runBtns.length !== samples.length)console.error("LuoguSP ide batch: 样例数与运行按钮数不一致",samples.length,runBtns.length,);IDE_BATCH.running = true;IDE_BATCH.stopReq = false;IDE_BATCH.stale = false;IDE_BATCH.results = new Array(n).fill(null);const inputTa = (() => {const tb = ideToolbarByTitle("输入");return tb && tb.parentElement? tb.parentElement.querySelector(SELECTORS.ideTextarea): null;})();IDE_BATCH.inputSnapshot = inputTa ? inputTa.value : null;const batchBtn = document.querySelector(".luogusp-ide-batch-btn");const selfTest = (() => {const tb = ideToolbarByTitle("代码");const actions = tb && tb.querySelector(SELECTORS.ideToolbarActions);return actions? [...actions.querySelectorAll("button")].find((b) => (b.textContent || "").trim() === "自测",): null;})();if (batchBtn) batchBtn.disabled = true;if (selfTest) selfTest.disabled = true; // 批测中禁原生自测防互相干扰if (IDE_BATCH.stopBtn) IDE_BATCH.stopBtn.style.display = "";switchIdeTab("samples");renderIdeRows(samples);if (IDE_BATCH.summaryEl) IDE_BATCH.summaryEl.textContent = "测试中…";let ceLog = null;for (let i = 0; i < n; i++) {if (IDE_BATCH.stopReq) break;const p = ideRowParts(i);if (p) {p.pill.setAttribute("style", IDE_PILL_RUN);p.pill.textContent = "运行中";}expandIdeRow(i);let r;try {r = await runOneSample(runBtns[i]);} catch (e) {console.error("LuoguSP ide batch:", e);r = { verdict: "UKE", note: String(e) };}IDE_BATCH.results[i] = r;applyIdeResult(i, r, samples[i]);if (r.verdict === "CE") {ceLog = r.output || "";for (let j = i + 1; j < n; j++) {IDE_BATCH.results[j] = {verdict: "CE",output: ceLog,note: "编译错误",};applyIdeResult(j, IDE_BATCH.results[j], samples[j]);}break;}if (i < n - 1 && !IDE_BATCH.stopReq) await sleep(500); // 组间限速}if (inputTa && IDE_BATCH.inputSnapshot != null) {inputTa.value = IDE_BATCH.inputSnapshot; // 还原用户自定义输入inputTa.dispatchEvent(new Event("input", { bubbles: true })); // 同步 Vue 绑定}IDE_BATCH.running = false;if (batchBtn) batchBtn.disabled = false;if (selfTest) selfTest.disabled = false;if (IDE_BATCH.stopBtn) IDE_BATCH.stopBtn.style.display = "none";finishIdeSummary();}// 判定口径同洛谷:CRLF 归一、去行尾空格、去末尾空行。仅用于 diff 渲染与交叉校验,// 最终判定以原生胶囊为准(AC/WA 由洛谷前端本地比较,侦察实录 §6)。function normalizeIdeOut(s) {return String(s == null ? "" : s).replace(/\r\n?/g, "\n").split("\n").map((l) => l.replace(/[ \t]+$/, "")).join("\n").replace(/\n+$/, "");}function idePane(title, lines, badSet, emptyNote) {const pre = document.createElement("pre");if (!lines.length || (lines.length === 1 && lines[0] === "")) {if (emptyNote) {const span = document.createElement("span");span.className = "luogusp-ide-empty";span.textContent = emptyNote;pre.appendChild(span);}} else {lines.forEach((l, k) => {const span = document.createElement("span");if (badSet && badSet.has(k)) span.className = "luogusp-ide-diffline";span.textContent = l;pre.appendChild(span);if (k < lines.length - 1)pre.appendChild(document.createTextNode("\n"));});}const box = document.createElement("div");box.className = "code-container";box.append(pre, makeCopyButton(pre));const pane = document.createElement("div");pane.className = "luogusp-ide-pane";const h = document.createElement("h5");h.textContent = title;pane.append(h, box);return pane;}function applyIdeResult(i, r, sample) {const p = ideRowParts(i);if (!p) return;p.pill.textContent = r.verdict;p.pill.setAttribute("style",r.pillStyle || "background-color:#3d3d3d;border-color:#333;color:#fff;",);p.detail.innerHTML = "";p.detail.classList.remove("luogusp-ide-log");if (r.verdict === "CE") {// CE:不显示三栏,直接展示编译日志(输出框捕获;侦察实录 §5)p.meta.textContent = "";p.detail.classList.add("luogusp-ide-log");p.detail.appendChild(idePane("编译信息",String(r.output || "").split("\n"),null,"(无编译输出)",),);return;}p.meta.textContent = r.detail || "";if (r.note) {const note = document.createElement("p");note.className = "luogusp-ide-note";note.textContent = r.note;p.detail.appendChild(note);if (r.output == null) {p.detail.classList.add("luogusp-ide-log"); // UKE 无产物,只留说明return;}}if (r.verdict === "RE" && r.detail) {const note = document.createElement("p");note.className = "luogusp-ide-note";note.textContent = r.detail; // RE 原因在 run-result 位置(侦察实录 §5)p.detail.appendChild(note);p.meta.textContent = "";}const expLines = normalizeIdeOut(sample[1]).split("\n");const actLines = normalizeIdeOut(r.output).split("\n");const bad = new Set();if (r.verdict !== "AC") {const m = Math.max(expLines.length, actLines.length);for (let k = 0; k < m; k++)if ((expLines[k] || "") !== (actLines[k] || "")) bad.add(k);}p.detail.append(idePane("输入", normalizeIdeOut(sample[0]).split("\n"), null, "(空)"),idePane("期望输出", expLines, bad, "(空)"),idePane("实际输出",actLines,bad,r.verdict === "AC" ? "(空)" : "(未产生输出)",),);}// 实测原生内联配色(侦察实录 §5);MLE/OLE/UKE 未实测,行内以运行时复制为准const IDE_LEGEND = [["AC", "rgb(83,196,26)", "rgb(80,161,39)", "#fff"],["WA", "rgb(231,77,60)", "rgb(208,69,53)", "#fff"],["TLE", "rgb(5,34,66)", "rgb(10,31,54)", "#fff"],["RE", "rgb(156,61,207)", "rgb(138,62,179)", "#fff"],["CE", "rgb(250,219,20)", "rgb(215,190,28)", "#614700"],["UKE", "#3d3d3d", "#333", "#fff"],];function finishIdeSummary() {if (!IDE_BATCH.summaryEl || !IDE_BATCH.results) return;const rs = IDE_BATCH.results;const counts = {};let ac = 0,tested = 0;rs.forEach((r) => {if (!r) return;tested++;if (r.verdict === "AC") ac++;else counts[r.verdict] = (counts[r.verdict] || 0) + 1;});let text = `${ac}/${rs.length} 通过`;for (const k in counts) text += ` · ${counts[k]} ${k}`;if (tested < rs.length) {text += " · 已停止";rs.forEach((r, i) => {if (r) return;const p = ideRowParts(i);if (p) p.pill.textContent = "未测";});}IDE_BATCH.summaryEl.textContent = text;const firstBad = rs.findIndex((r) => r && r.verdict !== "AC");if (firstBad !== -1) expandIdeRow(firstBad);else if (IDE_BATCH.rowsEl)IDE_BATCH.rowsEl.querySelectorAll(".luogusp-ide-row.open").forEach((r) => r.classList.remove("open"));}function markIdeStale() {if (IDE_BATCH.stale || IDE_BATCH.running || !IDE_BATCH.results) return;IDE_BATCH.stale = true;if (IDE_BATCH.summaryEl && document.contains(IDE_BATCH.summaryEl))IDE_BATCH.summaryEl.textContent += " · 结果可能已过期,建议重新测试";}function hookIdeStaleAndGuard() {// 代码变更 → 过期标注(CM6 是 contenteditable,input/keydown 均会冒泡)const stale = (e) => {if (e.target && e.target.closest && e.target.closest(SELECTORS.cmContent))markIdeStale();};document.addEventListener("input", stale, true);document.addEventListener("keydown", stale, true);// 批测中拦掉用户手点原生 运行/自测(程序化点击带 driving 标记放行)document.addEventListener("click",(e) => {if (!IDE_BATCH.running || IDE_BATCH.driving) return;const t =e.target &&e.target.closest &&e.target.closest(`${SELECTORS.ideSampleBlock} a, ${SELECTORS.ideToolbar} a.run`,);if (t) {e.preventDefault();e.stopPropagation();}},true,);}function mountIdeButton() {const tb = ideToolbarByTitle("代码");if (!tb) return;const actions = tb.querySelector(SELECTORS.ideToolbarActions);if (!actions || actions.querySelector(".luogusp-ide-batch-btn")) return;const selfTest = [...actions.querySelectorAll("button")].find((b) => (b.textContent || "").trim() === "自测",);if (!selfTest) return;// 克隆原生「自测」按钮继承洛谷样式(含 data-v 作用域),只换文字const btn = selfTest.cloneNode(true);btn.textContent = "一键测试";btn.classList.add("luogusp-ide-batch-btn");btn.disabled = false;btn.addEventListener("click", (e) => {e.preventDefault();e.stopPropagation();startIdeBatch();});actions.insertBefore(btn, selfTest);}function mountIdeTabs() {if (IDE_BATCH.tabBar && document.contains(IDE_BATCH.tabBar)) return;const inputTb = ideToolbarByTitle("输入");if (!inputTb) return;const ioLayout = inputTb.closest(".panel-layout"); // 底部 输入|输出 水平分栏const host = ioLayout && ioLayout.parentElement;if (!host) return;host.querySelectorAll(".luogusp-ide-tabbar, .luogusp-ide-panel").forEach((e) => e.remove());const tabBar = document.createElement("div");tabBar.className = "luogusp-ide-tabbar";tabBar.innerHTML ='<span class="luogusp-ide-tab" data-tab="custom">自定义测试</span>' +'<span class="luogusp-ide-tab" data-tab="samples">样例测试</span>';tabBar.addEventListener("click", (e) => {const t = e.target.closest("[data-tab]");if (t) switchIdeTab(t.dataset.tab);});const panel = document.createElement("div");panel.className = "luogusp-ide-panel";panel.innerHTML ='<div class="luogusp-ide-head">' +'<span class="luogusp-ide-title">样例测试</span>' +'<span class="luogusp-ide-summary">尚未运行</span>' +'<span class="luogusp-ide-headbtns"></span>' +"</div>" +'<div class="luogusp-ide-rows"></div>' +'<div class="luogusp-ide-legend"></div>';// 停止/重新测试:同样克隆原生「自测」继承样式const tpl = [...document.querySelectorAll(`${SELECTORS.ideToolbar} button`),].find((b) =>(b.textContent || "").trim() === "自测" ||b.classList.contains("luogusp-ide-batch-btn"),);const headBtns = panel.querySelector(".luogusp-ide-headbtns");const mkBtn = (text, cls, onClick) => {const b = tpl ? tpl.cloneNode(true) : document.createElement("button");b.textContent = text;b.className = (tpl ? tpl.className : "") + " " + cls;b.classList.remove("luogusp-ide-batch-btn");b.disabled = false;b.addEventListener("click", (e) => {e.preventDefault();e.stopPropagation();onClick();});headBtns.appendChild(b);return b;};IDE_BATCH.stopBtn = mkBtn("停止", "luogusp-ide-stop", () => {IDE_BATCH.stopReq = true;});IDE_BATCH.stopBtn.style.display = "none";mkBtn("重新测试", "luogusp-ide-rerun", () => startIdeBatch());host.insertBefore(tabBar, ioLayout);host.appendChild(panel);IDE_BATCH.tabBar = tabBar;IDE_BATCH.panel = panel;IDE_BATCH.ioLayout = ioLayout;IDE_BATCH.rowsEl = panel.querySelector(".luogusp-ide-rows");IDE_BATCH.summaryEl = panel.querySelector(".luogusp-ide-summary");panel.querySelector(".luogusp-ide-legend").innerHTML ="图例:" +IDE_LEGEND.map(([t, bg, bd, fg]) =>`<span class="luogusp-ide-pill" style="background-color:${bg};border-color:${bd};color:${fg};">${t}</span>`,).join("") +'<span style="margin-left:4px;">行内颜色实时取自洛谷原生结果</span>';syncIdeTabVisibility();}function switchIdeTab(tab) {IDE_BATCH.activeTab = tab;syncIdeTabVisibility();}function syncIdeTabVisibility() {const { tabBar, panel, ioLayout } = IDE_BATCH;if (!tabBar || !document.contains(tabBar) || !panel || !ioLayout) return;const samples = IDE_BATCH.activeTab === "samples";ioLayout.style.display = samples ? "none" : "";panel.style.display = samples ? "" : "none";tabBar.querySelectorAll(".luogusp-ide-tab").forEach((t) => {t.classList.toggle("on", (t.dataset.tab === "samples") === samples);});}const IDE_PILL_WAIT ="background-color:#bfbfbf;border-color:#b3b3b3;color:#fff;";const IDE_PILL_RUN ="background-color:#3498db;border-color:#2f89c5;color:#fff;";function renderIdeRows(samples) {const rowsEl = IDE_BATCH.rowsEl;if (!rowsEl) return;rowsEl.innerHTML = samples.map((s, i) => `<div class="luogusp-ide-row" data-idx="${i}"><div class="luogusp-ide-rowhead"><span class="luogusp-ide-chev">▶</span>样例 #${i + 1}<span class="luogusp-ide-meta"></span><span class="luogusp-ide-pill" style="${IDE_PILL_WAIT}">等待</span></div><div class="luogusp-ide-detail"></div></div>`,).join("");rowsEl.querySelectorAll(".luogusp-ide-rowhead").forEach((h) => {h.addEventListener("click", () => {const row = h.parentElement;const was = row.classList.contains("open");rowsEl.querySelectorAll(".luogusp-ide-row.open").forEach((r) => r.classList.remove("open"));if (!was) row.classList.add("open");});});}function ideRowParts(i) {const row =IDE_BATCH.rowsEl &&IDE_BATCH.rowsEl.querySelector(`.luogusp-ide-row[data-idx="${i}"]`);if (!row) return null;return {row,pill: row.querySelector(".luogusp-ide-pill"),meta: row.querySelector(".luogusp-ide-meta"),detail: row.querySelector(".luogusp-ide-detail"),};}function expandIdeRow(i) {if (!IDE_BATCH.rowsEl) return;IDE_BATCH.rowsEl.querySelectorAll(".luogusp-ide-row.open").forEach((r) => r.classList.remove("open"));const p = ideRowParts(i);if (p) p.row.classList.add("open");}function ensureIdeBatchUI() {if (!ideModeActive()) {unmountIdeBatchUI();return;}mountIdeButton();mountIdeTabs();syncIdeTabVisibility();}function unmountIdeBatchUI() {if (IDE_BATCH.running) IDE_BATCH.stopReq = true; // 退出 IDE/换题:请求停止IDE_BATCH.activeTab = "custom"; // 复位,防再次进入时默认落在空面板IDE_BATCH.tabBar = IDE_BATCH.panel = IDE_BATCH.ioLayout = null;IDE_BATCH.rowsEl = IDE_BATCH.summaryEl = IDE_BATCH.stopBtn = null;}// SPA:进出 IDE 模式/换题时补挂与清理(rAF 节流,同既有 watchSettingButton 模式)function watchIdeBatch() {installIdeSubmitObserver();hookIdeStaleAndGuard();let scheduled = false;const tick = () => {scheduled = false;try {ensureIdeBatchUI();} catch (e) {console.error("LuoguSP ide batch:", e);}};const queue = () => {if (!scheduled) {scheduled = true;requestAnimationFrame(tick);}};new MutationObserver(queue).observe(document.body, {childList: true,subtree: true,});watchUrlChange(queue);ensureIdeBatchUI();}// ============================================================// 启动// ============================================================const isChatPage = location.href.startsWith("https://www.luogu.com.cn/chat");9 行未改动if (isChatPage) setTimeout(addMessageLink, 500);},},{ key: `${STORAGE_PREFIX}showIntro`, run: watchHiddenIntro },{ key: `${STORAGE_PREFIX}ideBatchSampleTest`, run: watchIdeBatch },];injectStyle();for (const f of FEATURES) {4 行未改动console.error("LuoguSP feature failed:", e);}}})();```