正文
增加 74 行删除 23 行
17 行未改动18192021222324252627318 行未改动全部展开34634734834935035135235336 行未改动3903913923933943953963973983994004014024031,409 行未改动全部展开18131814181518161817181818191820182118221823182418251826182718281829183018311832269 行未改动全部展开21022103210421052106210721082109211088 行未改动2199220022012202220322042205220622072208465 行未改动全部展开26742675267626772678267926802681268220 行未改动2703270427052706270727082709271027114 行未改动271627172718271927202721272227232724272527262727272888 行未改动2817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844740 行未改动全部展开3585358635873588358935903591359235931,006 行未改动全部展开17 行未改动```javascript// ==UserScript==// @name LuoguSP// @namespace https://github.com/ShanireZ/LuoguSP// @version 2.12.4// @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/LuoguSP318 行未改动全部展开{ signal },);} catch (error) {if (signal.aborted) return null;/* 临时网络错误不能永久降级 _contentOnly。 */}if (text != null) {try {36 行未改动if (!controller) return;const taskGeneration = generation;const taskRoute = routeToken();const taskIdentity = identity.resolve(anchor);if (!taskIdentity) return;if (typeof documentAdapter.appliedPid === "function" &&documentAdapter.appliedPid(anchor) === taskIdentity.pid)return;if (coloringAnchors.get(anchor) === taskIdentity.key) return;coloringAnchors.set(anchor, taskIdentity.key);try {const color = await getColor(taskIdentity.pid, controller.signal);1,409 行未改动全部展开ideTextarea: "textarea.ide-textarea", // 输入/输出面板的文本域ideSampleBlock: ".io-sample-block", // 题面样例块(输入 #N / 输出 #N 各一块)cmContent: ".cm-content", // CodeMirror 6 内容层lentilleContext: "script#lentille-context", // 新版页面数据(JSON,含 problem.samples)// —— 安全访问中心拦截页(接口与接管边界见下方受限内容区段注释)——restrictedUrlPre: "pre#url", // 拦截页里的目标链接文本restrictedGoButton: "button#go", // 拦截页「继续访问」按钮};// 功能开关:key → 显示名。新增功能只需在此登记 + 在底部 FEATURES 注册启动器。const FEATURE_LABELS = new Map([[`${STORAGE_PREFIX}addProblemsColor`, "显示题目颜色"],[`${STORAGE_PREFIX}addMessageLink`, "私信界面 Ctrl+Click 打开用户主页"],[`${STORAGE_PREFIX}showIntro`, "显示隐藏的个人简介"],[`${STORAGE_PREFIX}ideBatchSampleTest`, "IDE 一键测试样例"],[`${STORAGE_PREFIX}showRestrictedContent`, "受限文章/剪贴板直接显示"],]);const storage = {get: (k) => localStorage.getItem(k) === "true",269 行未改动全部展开};}// ============================================================// 私信界面 Ctrl+Click 打开用户主页(用户名 + 头像)// ============================================================function addMessageLink() {const bound = new WeakSet(); // 去重,避免重复绑定const uidCache = new Map(); // username -> uid 缓存88 行未改动};}// ============================================================// 显示隐藏的个人简介// 洛谷把个人简介改为「仅国际站可见」,但境内站服务器仍把 introduction 下发到页面同源数据里// (SSR 脚本 / lentille 接口),只是前端不渲染。这里读同源数据自行补显,无需跨域。// ============================================================function digIntro(obj, wantUid) {let result = null;465 行未改动全部展开};}// ============================================================// 题目难度着色// ============================================================// 单队列 FIFO:300ms 发起间隔、最多 3 并发、15s 超时。const limiter = createGetRequestScheduler({fetch: (url, init) => fetch(url, init),20 行未改动});const problemAnchorIdentity = (anchor) => problemIdentity.resolve(anchor);// 把子树中第一处 pid 文本包成 <b>(纯 DOM,避免 innerHTML.replace 误伤属性内同名子串、// 重建整个锚点子树、抖掉已绑定的监听)。返回是否成功包裹。function wrapPidText(root, pid, color) {const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);let node;while ((node = walker.nextNode())) {4 行未改动const b = document.createElement("b");b.style.color = color;b.textContent = pid;mid.parentNode.replaceChild(b, mid);return true;}return false;}const problemPipeline =typeof document === "undefined"? null: createProblemPipeline({88 行未改动return () => observer.disconnect();},appliedPid: (anchor) => anchor.dataset.luoguspPid,isConnected: (anchor) => anchor.isConnected,applyColor: (a, pid, color) => {// 虚拟列表可能在请求期间复用锚点;Problem Pipeline 已复核身份后才会到这里。const span = a.children[0];if (span &&span.matches("span.pid") &&(span.innerText || span.textContent || "").trim() === pid) {span.style.color = color;span.style.fontWeight = "bold";a.dataset.luoguspPid = pid;} else if (wrapPidText(a, pid, color)) {a.dataset.luoguspPid = pid;}},},});// ============================================================// IDE 一键测试样例// 洛谷新版题目页(columba)IDE 模式(#ide)下,逐组驱动题面样例的原生「运行」,// 结果从输出面板 DOM 捕获(结果经页面常驻 WS 推送,网络层拿不到——勿改走拦截)。// 锚点与配色均来自 2026-07 洛谷 columba IDE 的真实页面观测。// ============================================================740 行未改动全部展开});const startIdeBatch = () => ideBatchRunner.start();// ============================================================// 受限文章/剪贴板直接显示(原生壳注入)// 国内站访问非本人/未审核的 /article、/paste 会落在「安全访问中心」拦截页// (独立静态页、零全站样式、无 CSP)。本功能在拦截页上重建官方页面:// 1) 壳骨架收割:从 .cn 同源页拿官方壳(columba 源=/ranking 等,lfe 源=/image 等;// 骨架自带真实 csrf、当前登录用户、用户主题、官方脚本当前版本——全部活取,绝不写死);1,006 行未改动全部展开17 行未改动18192021222324252627318 行未改动全部展开34634734834935035135235335435535636 行未改动3933943953963973983994004014024034044054064074084094104114124134141,409 行未改动全部展开18241825182618271828182918301831183218331834183518361837183818391840184118421843269 行未改动全部展开21132114211521162117211821192120212188 行未改动2210221122122213221422152216221722182219465 行未改动全部展开26852686268726882689269026912692269320 行未改动2714271527162717271827192720272127224 行未改动27272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276588 行未改动285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895740 行未改动全部展开3636363736383639364036413642364336441,006 行未改动全部展开17 行未改动```javascript// ==UserScript==// @name LuoguSP// @namespace https://github.com/ShanireZ/LuoguSP// @version 2.12.5// @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/LuoguSP318 行未改动全部展开{ signal },);} catch (error) {if (signal.aborted) return null;// 已删除、无权访问或尚未公开的题目都可能返回 403/404;它们没有可着色难度,// 也不需要再请求完整页面或污染控制台。if (error && (error.status === 403 || error.status === 404)) return null;/* 临时网络错误不能永久降级 _contentOnly。 */}if (text != null) {try {36 行未改动if (!controller) return;const taskGeneration = generation;const taskRoute = routeToken();const taskIdentity = identity.resolve(anchor);const appliedPid =typeof documentAdapter.appliedPid === "function"? documentAdapter.appliedPid(anchor): null;if (!taskIdentity) {if (appliedPid && typeof documentAdapter.clearColor === "function")documentAdapter.clearColor(anchor, appliedPid);return;}if (appliedPid === taskIdentity.pid) return;// 洛谷记录分页会复用同一批锚点。先撤销旧题号的样式,避免新题查询失败时// (例如题目已删除而返回 403)继续显示上一页题目的难度色。if (appliedPid && typeof documentAdapter.clearColor === "function")documentAdapter.clearColor(anchor, appliedPid);if (coloringAnchors.get(anchor) === taskIdentity.key) return;coloringAnchors.set(anchor, taskIdentity.key);try {const color = await getColor(taskIdentity.pid, controller.signal);1,409 行未改动全部展开ideTextarea: "textarea.ide-textarea", // 输入/输出面板的文本域ideSampleBlock: ".io-sample-block", // 题面样例块(输入 #N / 输出 #N 各一块)cmContent: ".cm-content", // CodeMirror 6 内容层lentilleContext: "script#lentille-context", // 新版页面数据(JSON,含 problem.samples)// —— 安全访问中心拦截页(接口与接管边界见下方“显示受限文章与剪贴板”区段注释)——restrictedUrlPre: "pre#url", // 拦截页里的目标链接文本restrictedGoButton: "button#go", // 拦截页「继续访问」按钮};// 功能开关:key → 显示名。新增功能只需在此登记 + 在底部 FEATURES 注册启动器。const FEATURE_LABELS = new Map([[`${STORAGE_PREFIX}addProblemsColor`, "题号显示难度颜色"],[`${STORAGE_PREFIX}addMessageLink`, "私信 Ctrl+Click 打开用户个人页"],[`${STORAGE_PREFIX}showIntro`, "个人页显示个人介绍"],[`${STORAGE_PREFIX}ideBatchSampleTest`, "IDE 模式一键测试所有样例"],[`${STORAGE_PREFIX}showRestrictedContent`, "显示受限文章与剪贴板"],]);const storage = {get: (k) => localStorage.getItem(k) === "true",269 行未改动全部展开};}// ============================================================// 私信 Ctrl+Click 打开用户个人页// ============================================================function addMessageLink() {const bound = new WeakSet(); // 去重,避免重复绑定const uidCache = new Map(); // username -> uid 缓存88 行未改动};}// ============================================================// 个人页显示个人介绍// 洛谷把个人介绍改为「仅国际站可见」,但境内站服务器仍把 introduction 下发到页面同源数据里// (SSR 脚本 / lentille 接口),只是前端不渲染。这里读同源数据自行补显,无需跨域。// ============================================================function digIntro(obj, wantUid) {let result = null;465 行未改动全部展开};}// ============================================================// 题号显示难度颜色// ============================================================// 单队列 FIFO:300ms 发起间隔、最多 3 并发、15s 超时。const limiter = createGetRequestScheduler({fetch: (url, init) => fetch(url, init),20 行未改动});const problemAnchorIdentity = (anchor) => problemIdentity.resolve(anchor);// 把子树中第一处 pid 文本包成 <b>(纯 DOM,避免 innerHTML.replace 误伤属性内同名子串、// 重建整个锚点子树、抖掉已绑定的监听)。返回创建的包裹节点,未找到则返回 null。function wrapPidText(root, pid, color) {const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);let node;while ((node = walker.nextNode())) {4 行未改动const b = document.createElement("b");b.style.color = color;b.textContent = pid;mid.parentNode.replaceChild(b, mid);return b;}return null;}const appliedProblemColors = new WeakMap();const captureInlineProperty = (element, property) =>Object.freeze({value: element.style.getPropertyValue(property),priority: element.style.getPropertyPriority(property),});const restoreInlineProperty = (element, property, original) => {if (original.value)element.style.setProperty(property, original.value, original.priority);else element.style.removeProperty(property);};const clearProblemColor = (anchor) => {const state = appliedProblemColors.get(anchor);if (state && state.node && anchor.contains(state.node)) {if (state.kind === "span") {restoreInlineProperty(state.node, "color", state.color);restoreInlineProperty(state.node, "font-weight", state.fontWeight);} else if (state.kind === "wrapper") {state.node.replaceWith(document.createTextNode(state.node.textContent || ""));anchor.normalize();}}appliedProblemColors.delete(anchor);delete anchor.dataset.luoguspPid;};const problemPipeline =typeof document === "undefined"? null: createProblemPipeline({88 行未改动return () => observer.disconnect();},appliedPid: (anchor) => anchor.dataset.luoguspPid,isConnected: (anchor) => anchor.isConnected,clearColor: (anchor) => clearProblemColor(anchor),applyColor: (a, pid, color) => {// 虚拟列表可能在请求期间复用锚点;Problem Pipeline 已复核身份后才会到这里。clearProblemColor(a);const span = a.children[0];if (span &&span.matches("span.pid") &&(span.innerText || span.textContent || "").trim() === pid) {appliedProblemColors.set(a, {kind: "span",node: span,color: captureInlineProperty(span, "color"),fontWeight: captureInlineProperty(span, "font-weight"),});span.style.color = color;span.style.fontWeight = "bold";a.dataset.luoguspPid = pid;} else {const wrapper = wrapPidText(a, pid, color);if (!wrapper) return;appliedProblemColors.set(a, {kind: "wrapper",node: wrapper,});a.dataset.luoguspPid = pid;}},},});// ============================================================// IDE 模式一键测试所有样例// 洛谷新版题目页(columba)IDE 模式(#ide)下,逐组驱动题面样例的原生「运行」,// 结果从输出面板 DOM 捕获(结果经页面常驻 WS 推送,网络层拿不到——勿改走拦截)。// 锚点与配色均来自 2026-07 洛谷 columba IDE 的真实页面观测。// ============================================================740 行未改动全部展开});const startIdeBatch = () => ideBatchRunner.start();// ============================================================// 显示受限文章与剪贴板(原生壳注入)// 国内站访问非本人/未审核的 /article、/paste 会落在「安全访问中心」拦截页// (独立静态页、零全站样式、无 CSP)。本功能在拦截页上重建官方页面:// 1) 壳骨架收割:从 .cn 同源页拿官方壳(columba 源=/ranking 等,lfe 源=/image 等;// 骨架自带真实 csrf、当前登录用户、用户主题、官方脚本当前版本——全部活取,绝不写死);1,006 行未改动全部展开