正文
增加 762 行删除 62 行
123456789101112680 行未改动全部展开69369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173229 行未改动76276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880930 行未改动840841842843844845846847848849850851852853854153 行未改动全部展开100810091010101110121013101410151016101710181019102010211022102310241025102616 行未改动1043104410451046104710481049105010511052105310541055105610571058105927 行未改动1087108810891090109110921093109410951096109710981099110011011102110311041105122 行未改动全部展开122812291230123112321233123412351236341 行未改动全部展开157815791580158115821583158415851586158715881,650 行未改动全部展开3239324032413242324332443245324632473 行未改动325132523253325432553256325732586 行未改动配置异常简单,下载油猴插件,谷歌浏览器开fq或者下载[安装包](https://pan.quark.cn/s/1ac7209c3f94#/list/share)\点击油猴-->添加新脚本->ctrl+a再ctrl+v然后ctrl+s就行了```js// ==UserScript==// @name BZOJ 增强工具 + 网页字体更换器// @namespace https://bzoj.org/// @version 2.0.1// @description 整合 BZOJ 测试点大方块(自动轮询、完成通知、亮暗模式适配、总分数垂直对齐)、全站网页字体更换器、以及题目 Markdown 块内查看/复制功能(右上角按钮,可撤销),BZOJ 功能仅在 bzoj.org 下激活// @author bzoj-enhancer & FontSwitcher// @match *://*/*// @grant GM_notification// @grant GM_addStyle680 行未改动全部展开}}, 2000);},/*** 手动偏移状态栏:从 GM_getValue 读取用户设置的偏移量(px),* 用 transform: translateY() 应用到状态栏 h1 内所有子元素* (图标、分数、状态文本),让整体一起上下移动。* 默认 -6px(用户实测的舒适值)。*/_applyScoreOffset: function () {const title = document.querySelector('#status .section__title, .section[data-status] .section__title');if (!title) return;// 读取偏移量(px),默认 -6,正数=下移,负数=上移const offset = parseFloat(GM_getValue('bzoj_score_offset', '-6')) || 0;const transform = offset !== 0 ? `translateY(${offset}px)` : '';// 应用到 h1 内所有子元素(图标、分数、状态文本)const children = Array.from(title.children);for (const c of children) {c.style.transform = transform;c.style.display = 'inline-block';c.style.verticalAlign = 'middle';}},installObserver: function () {const self = this;if (this.observer) return;this.observer = new MutationObserver(() => {// 立即隐藏表格(不防抖,避免闪烁)self._hideTables();// 重新应用分数偏移(Hydro 重建 DOM 时 transform 会丢失)self._applyScoreOffset();// 重建方块需要防抖,等 DOM 稳定后再处理clearTimeout(self._observerDebounce);self._observerDebounce = setTimeout(() => {29 行未改动.bzoj-hide-table { display: none !important; }.bzoj-hide-container { display: none !important; }.bzoj-hide-section-body { display: none !important; }/* ============ 修复 record 页面总分数垂直居中 ============ *//* Hydro 的 record 状态栏结构:<h1 class="section__title"><span class="icon record-status--icon pass"></span> // 图标(background-image,固定尺寸)<span style="color: #25ad40">100</span> // 分数(无 class,inline style)<span class="record-status--text pass">Accepted</span> // 状态文本</h1>问题:分数 span 的字体高度与图标/状态文本不一致,导致垂直中心偏低。策略:用 flex 居中 + JS 运行时测量精确修正。 *//* 1. 让状态栏 h1 使用 flex 居中 */#status .section__title,.section[data-status] > .section__header > .section__title {display: flex !important;align-items: center !important;}/* 2. 所有子元素统一为 inline-block + 垂直居中 */#status .section__title > *,.section[data-status] > .section__header > .section__title > * {display: inline-block !important;vertical-align: middle !important;align-self: center !important;line-height: 1.2 !important;margin-top: 0 !important;margin-bottom: 0 !important;}/* 3. 图标保留 Hydro 原有尺寸 */#status .section__title .record-status--icon,.section[data-status] .section__title .record-status--icon {flex-shrink: 0 !important;line-height: 1 !important;}`);// 4. 应用用户设置的分数偏移(默认 -6px)self._applyScoreOffset();// MutationObserver 会在 DOM 变化时重新调用const initialResult = self.extractTestCases(document);if (initialResult) {self._lastResult = initialResult;const allDone = self.updateBlocks(initialResult);30 行未改动_modal: null,_lastMarkdown: '',init: function () {// 1. 路径检测:必须是 /p/<id>,排除 /p/<id>/submit、/p/<id>/solution 等子路径const path = window.location.pathname;if (!/^\/p\/[^\/]+$/.test(path)) return;// 2. 结构检测:必须存在题面正文容器const content = document.querySelector('.problem-content, [data-fragment-id="problem-description"]');if (!content) return;// 3. 排除 iframe 等嵌套文档if (window.top !== window.self) return;153 行未改动全部展开background: #56758f; color: #fff; border-color: #56758f;}/* ============ 块内 MD 源码视图(替换题面 HTML) ============ */.bzoj-md-inline-view {padding: 16px 20px; margin: 0;font-family: "JetBrains Mono", "Cascadia Code", Consolas, "Source Code Pro", "Microsoft YaHei", monospace;font-size: 13px; line-height: 1.6;white-space: pre-wrap; word-break: break-word;background: rgba(86,117,143,0.03); border-radius: 6px;color: #333;}.theme--dark .bzoj-md-inline-view,html[data-mantine-color-scheme="dark"] .bzoj-md-inline-view {background: rgba(255,255,255,0.04); color: #ddd;}.bzoj-md-restored-banner {display: flex; align-items: center; gap: 8px;padding: 8px 14px; margin-bottom: 10px;16 行未改动self.addSidebarButton(menu);} else {self.addFloatingButton();}},/** 在题目块右上角注入两个浮动按钮:「显示 MD」「复制 MD」 */addActionButtons: function () {const self = this;if (document.querySelector('.bzoj-md-actions')) return; // 防止重复注入// 定位题目内容容器,按钮组将绝对定位在其右上角const anchor =document.querySelector('.problem-content-container') ||(document.querySelector('.problem-content')?.closest('.section')) ||document.querySelector('.problem-content');if (!anchor) return;27 行未改动anchor.appendChild(actions);},/*** 在题面块内切换 Markdown 源码视图(可撤销)。* - 首次点击:保存原始 HTML,将题面正文替换为 <pre class="bzoj-md-inline-view"> 显示 MD 源码* - 再次点击:恢复原始 HTML*/_inlineMdState: null, // { originalHtml, viewEl, anchor }toggleInlineMd: function (btn) {const self = this;// 定位题面正文容器(与 getProblemMarkdown 一致)const fragment =document.querySelector('[data-fragment-id="problem-description"]') ||document.querySelector('.problem-content .section__body') ||document.querySelector('.problem-content');if (!fragment) {122 行未改动全部展开},/** 提取题面 HTML 并转换为 Markdown */getProblemMarkdown: function () {const fragment =document.querySelector('[data-fragment-id="problem-description"]') ||document.querySelector('.problem-content .section__body') ||document.querySelector('.problem-content');if (!fragment) return '';341 行未改动全部展开}};// ================================================================// 模块三:网页字体更换器(所有站点运行)// ================================================================// ==================== 默认常量 ====================const FS_DEFAULT_BTN_SIZE = 42;const FS_COLLAPSED_VISIBLE = 6;1,650 行未改动全部展开fsResetIdleTimer();}// ================================================================// 主入口:初始化三个模块// ================================================================function main() {// 字体更换器:所有站点运行3 行未改动BZOJ_TestcaseModule.init();// BZOJ 题目 Markdown 查看/复制:仅 /p/<id> 题目详情页运行(init 内部有路径与结构双重判断)BZOJ_ProblemMarkdownModule.init();}if (document.readyState === 'complete' || document.readyState === 'interactive') {main();6 行未改动123456789101112680 行未改动全部展开69369469569669769869970070170270370470570670729 行未改动73773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478530 行未改动816817818819820821822823824825826827828829830831832833834153 行未改动全部展开98898999099199299399499599699799899910001001100210031004100510061007100816 行未改动10251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105727 行未改动1085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121122 行未改动全部展开1244124512461247124812491250125112521253125412551256341 行未改动全部展开15981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122821,650 行未改动全部展开3933393439353936393739383939394039413 行未改动394539463947394839493950395139523953395439553956395739586 行未改动配置:下载油猴插件,谷歌浏览器开fq或者下载[安装包](https://pan.quark.cn/s/1ac7209c3f94#/list/share)\点击油猴-->添加新脚本->ctrl+a再ctrl+v然后ctrl+s就行了```js// ==UserScript==// @name Hydro OJ 增强工具 + 网页字体更换器// @namespace https://bzoj.org/// @version 2.5.3// @description 整合 Hydro OJ 测试点大方块(自动轮询、完成通知、亮暗模式适配、总分数垂直对齐,兼容所有 Hydro 系 OJ)、全站网页字体更换器、题目 Markdown 块内查看/复制功能(右上角按钮,可撤销,兼容所有 Hydro 系 OJ,支持在线编程模式)、题目列表「提交」快捷列(仅在题库/比赛/作业/训练列表页显示)、以及比赛/作业成绩表增强(黄色高亮当前用户 + 详细状态方块)// @author bzoj-enhancer & FontSwitcher// @match *://*/*// @grant GM_notification// @grant GM_addStyle680 行未改动全部展开}}, 2000);},installObserver: function () {const self = this;if (this.observer) return;this.observer = new MutationObserver(() => {// 立即隐藏表格(不防抖,避免闪烁)self._hideTables();// 重建方块需要防抖,等 DOM 稳定后再处理clearTimeout(self._observerDebounce);self._observerDebounce = setTimeout(() => {29 行未改动.bzoj-hide-table { display: none !important; }.bzoj-hide-container { display: none !important; }.bzoj-hide-section-body { display: none !important; }/* ============ 修复 record 状态栏框太扁的问题 ============ *//* Hydro 的 record 状态栏 <h1 class="section__title"> 内有图标、分数、状态文本,默认 section__header 的 padding 不足,导致框太扁、内容显得没居中。策略:增加 section__header 的上下 padding,让框变高,内容自然垂直居中。 *//* 1. 增加 section__header 的上下 padding,让框变高 */#status > .section__header,.section[data-status] > .section__header {padding-top: 14px !important;padding-bottom: 14px !important;}/* 2. 让状态栏 h1 使用 flex 居中 */#status .section__title,.section[data-status] > .section__header > .section__title {display: flex !important;align-items: center !important;gap: 8px !important;line-height: 1.4 !important;margin: 0 !important;}/* 3. 所有子元素统一为 inline-block + 垂直居中 */#status .section__title > *,.section[data-status] > .section__header > .section__title > * {display: inline-block !important;vertical-align: middle !important;align-self: center !important;line-height: 1.4 !important;margin-top: 0 !important;margin-bottom: 0 !important;}/* 4. 图标保留 Hydro 原有尺寸 */#status .section__title .record-status--icon,.section[data-status] .section__title .record-status--icon {flex-shrink: 0 !important;line-height: 1 !important;}`);const initialResult = self.extractTestCases(document);if (initialResult) {self._lastResult = initialResult;const allDone = self.updateBlocks(initialResult);30 行未改动_modal: null,_lastMarkdown: '',init: function () {// 自动检测 Hydro OJ 题目详情页(兼容 bzoj.org / hydro.ac 及所有 Hydro 系 OJ)// 1. 路径匹配:/p/[id] 或 /d/[domain]/p/[id](排除 /p/[id]/submit、/p/[id]/solution 等子路径)const path = window.location.pathname;const match = path.match(/\/p\/([^\/]+)$/);if (!match) return;// 2. 结构检测:页面是否有 Hydro 题目特征元素const hasHydroElements = document.querySelector('.problem-content') ||document.querySelector('[data-fragment-id="problem-description"]') ||document.querySelector('.problem-content-container');if (!hasHydroElements) return;// 3. 排除 iframe 等嵌套文档if (window.top !== window.self) return;153 行未改动全部展开background: #56758f; color: #fff; border-color: #56758f;}/* ============ 块内 MD 源码视图(替换题面 HTML) ============ *//* 透明背景 + 继承字号,直接融入题目块容器,不出现单独的「灰色框」 */.bzoj-md-inline-view {padding: 0; margin: 0;font-family: "JetBrains Mono", "Cascadia Code", Consolas, "Source Code Pro", "Microsoft YaHei", monospace;font-size: inherit; line-height: inherit;white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;background: transparent; border: none; border-radius: 0;color: inherit;overflow: visible;}.theme--dark .bzoj-md-inline-view,html[data-mantine-color-scheme="dark"] .bzoj-md-inline-view {background: transparent; color: inherit;}.bzoj-md-restored-banner {display: flex; align-items: center; gap: 8px;padding: 8px 14px; margin-bottom: 10px;16 行未改动self.addSidebarButton(menu);} else {self.addFloatingButton();}// 监听 DOM 变化:用户进入/退出在线编程模式(scratchpad)时重新注入按钮self._installModeObserver();},/** 在题目块右上角注入两个浮动按钮:「显示 MD」「复制 MD」 */addActionButtons: function () {const self = this;// 移除已存在但已失效的按钮(如 scratchpad 模式切换导致旧按钮在隐藏容器中)const existing = document.querySelector('.bzoj-md-actions');if (existing) {const parent = existing.parentElement;if (parent) {const cs = getComputedStyle(parent);const invisible = cs.display === 'none' || parseFloat(cs.opacity) < 0.1;if (invisible) existing.remove();else return; // 已有可见按钮,不重复注入}}// 定位题目内容容器:优先 scratchpad 模式下的可见 .problem-content,// 其次普通模式的 .problem-content-containerconst scratchpadContent = document.querySelector('.scratchpad__problem .problem-content, .scratchpad__problem [data-fragment-id="problem-description"]');const anchor =scratchpadContent ||document.querySelector('.problem-content-container') ||(document.querySelector('.problem-content')?.closest('.section')) ||document.querySelector('.problem-content');if (!anchor) return;27 行未改动anchor.appendChild(actions);},/** 安装模式切换监听器:scratchpad 模式切换时重新注入按钮 */_installModeObserver: function () {const self = this;if (self._mdObserver) return;self._mdObserver = new MutationObserver(function () {clearTimeout(self._mdObserverDebounce);self._mdObserverDebounce = setTimeout(function () {self.addActionButtons();}, 200);});self._mdObserver.observe(document.body, { attributes: true, attributeFilter: ['class'] });self._mdObserver.observe(document.body, { childList: true, subtree: true });},/*** 在题面块内切换 Markdown 源码视图(可撤销)。* - 首次点击:保存原始 HTML,将题面正文替换为 <pre class="bzoj-md-inline-view"> 显示 MD 源码* - 再次点击:恢复原始 HTML*/_inlineMdState: null, // { originalHtml, viewEl, anchor }toggleInlineMd: function (btn) {const self = this;// 定位题面正文容器(优先 scratchpad 模式下的可见题面)const fragment =document.querySelector('.scratchpad__problem [data-fragment-id="problem-description"]') ||document.querySelector('.scratchpad__problem .problem-content .section__body') ||document.querySelector('.scratchpad__problem .problem-content') ||document.querySelector('[data-fragment-id="problem-description"]') ||document.querySelector('.problem-content .section__body') ||document.querySelector('.problem-content');if (!fragment) {122 行未改动全部展开},/** 提取题面 HTML 并转换为 Markdown */getProblemMarkdown: function () {// 优先 scratchpad 模式下的可见题面,其次普通模式const fragment =document.querySelector('.scratchpad__problem [data-fragment-id="problem-description"]') ||document.querySelector('.scratchpad__problem .problem-content .section__body') ||document.querySelector('.scratchpad__problem .problem-content') ||document.querySelector('[data-fragment-id="problem-description"]') ||document.querySelector('.problem-content .section__body') ||document.querySelector('.problem-content');if (!fragment) return '';341 行未改动全部展开}};// ================================================================// 模块三:题目列表「提交」快捷列// 仅在以下页面运行:// - /contest/<hex>/problems (比赛题目列表)// - /p (题库)// - /p?page=<num> (题库分页)// - /homework/<hex> (作业题目列表)// - /training/<hex> (训练题目列表)// 在题目列表表格中新增一列「提交」,显示指向 /p/<id>/submit 的链接。// 兼容所有 Hydro 系 OJ。// ================================================================const BZOJ_SubmitLinkModule = {/** 判断当前页面是否应该启用此模块 */shouldRun: function () {const path = window.location.pathname;// /contest/<hex>/problemsif (/\/contest\/[^\/]+\/problems\/?$/.test(path)) return true;// /p 或 /p?page=<num>(精确匹配 /p 结尾,排除 /p/<id> 详情页)if (/^\/p\/?$/.test(path)) return true;// /homework/<hex>if (/\/homework\/[^\/]+\/?$/.test(path)) return true;// /training/<hex>if (/\/training\/[^\/]+\/?$/.test(path)) return true;return false;},init: function () {const self = this;if (!self.shouldRun()) return;GM_addStyle(`.bzoj-submit-col-link {display: inline-block;padding: 2px 12px;border-radius: 4px;background: rgba(86,117,143,0.1);color: #56758f;font-size: 13px;font-weight: 600;text-decoration: none;font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;transition: all .15s;}.bzoj-submit-col-link:hover {background: #56758f;color: #fff;text-decoration: none;}.theme--dark .bzoj-submit-col-link,html[data-mantine-color-scheme="dark"] .bzoj-submit-col-link {background: rgba(142,179,208,0.15);color: #8eb3d0;}.theme--dark .bzoj-submit-col-link:hover,html[data-mantine-color-scheme="dark"] .bzoj-submit-col-link:hover {background: #56758f;color: #fff;}`);self.injectColumns();// 监听 DOM 变化(Hydro 可能动态加载/重建表格)self._installObserver();},/** 判断一个 URL 是否是题目链接:/p/<id>(排除 submit 等子路径) */isProblemLink: function (href) {if (!href) return false;if (/\/p\/[^\/]+\/(submit|solution|edit|files|manage)/.test(href)) return false;return /\/p\/[^\/]+/.test(href);},/** 从题目链接 href 构建 submit URL(保留 tid 参数) */buildSubmitUrl: function (href) {const url = new URL(href, location.href);return url.pathname.replace(/\/$/, '') + '/submit' + (url.search || '');},/** 在题目列表表格中新增「提交」列(不修改原有列,只在最右侧追加) */injectColumns: function () {const self = this;// 第一步:移除页面中所有 Hydro 自带的「递交」链接(class="typo-a" 且指向 submit),// 这些链接通常是 float:right 的纯文字+图标,样式较陋,用我们新增的列替代。// 独立于表格处理执行,确保即使行已被标记也能清理。const allOldLinks = document.querySelectorAll('a.typo-a[href*="/submit"]');for (const oldLink of allOldLinks) {oldLink.remove();}// 查找所有包含题目链接的表格const tables = document.querySelectorAll('table.data-table');let count = 0;for (const table of tables) {if (table.dataset.bzojSubmitCol === '1') continue; // 已处理const tbody = table.querySelector('tbody');if (!tbody) continue;// 检查表格是否包含题目链接(决定是否处理此表格)const rows = tbody.querySelectorAll('tr');let hasProblemRow = false;for (const row of rows) {const link = row.querySelector('a[href*="/p/"]');if (link && self.isProblemLink(link.getAttribute('href') || '')) {hasProblemRow = true;break;}}if (!hasProblemRow) continue;// 找到表头行(thead > tr),也在表头加一列let headerRow = null;const thead = table.querySelector('thead');if (thead) headerRow = thead.querySelector('tr');// Hydro 可能还有独立的 sticky 表头表(section__table-header),也要同步加列let stickyHeaderRow = null;const container = table.closest('.section__body, .section, .problem-list-container, .col-container');if (container) {const stickyTable = container.querySelector('table.section__table-header');if (stickyTable) {const stickyThead = stickyTable.querySelector('thead');if (stickyThead) stickyHeaderRow = stickyThead.querySelector('tr');}}// 同步 colgroup:如果有 <colgroup>,需要加一个 <col> 保持列数一致const colgroup = table.querySelector('colgroup');if (colgroup && !colgroup.dataset.bzojSubmitCol) {const col = document.createElement('col');col.style.width = '80px';colgroup.appendChild(col);colgroup.dataset.bzojSubmitCol = '1';}// sticky 表头的 colgroup 也要同步if (container) {const stickyTable = container.querySelector('table.section__table-header');if (stickyTable) {const stickyColgroup = stickyTable.querySelector('colgroup');if (stickyColgroup && !stickyColgroup.dataset.bzojSubmitCol) {const col = document.createElement('col');col.style.width = '80px';stickyColgroup.appendChild(col);stickyColgroup.dataset.bzojSubmitCol = '1';}}}// 在表头加一列「提交」// 表头文字右对齐,padding-right 设为 28px(= td 的 16px + 按钮自身的 12px padding),// 使「提交」文字与下方按钮内文字的垂直中线对齐if (headerRow && !headerRow.dataset.bzojSubmitHeader) {const th = document.createElement('th');th.textContent = '提交';th.style.cssText = 'text-align: right; white-space: nowrap; width: 80px; padding-right: 28px;';headerRow.appendChild(th);headerRow.dataset.bzojSubmitHeader = '1';}// sticky 表头也加一列if (stickyHeaderRow && !stickyHeaderRow.dataset.bzojSubmitHeader) {const th = document.createElement('th');th.textContent = '提交';th.style.cssText = 'text-align: right; white-space: nowrap; width: 80px; padding-right: 28px;';stickyHeaderRow.appendChild(th);stickyHeaderRow.dataset.bzojSubmitHeader = '1';}// 遍历所有行:有题目链接的加「提交」链接,无题目链接的(如 * 占位行)补空 td 保持列数一致for (const row of rows) {if (row.dataset.bzojSubmitCell === '1') continue;const link = row.querySelector('a[href*="/p/"]');const isValidProblem = link && self.isProblemLink(link.getAttribute('href') || '');const td = document.createElement('td');td.style.cssText = 'text-align: right; white-space: nowrap; padding-right: 16px;';if (isValidProblem) {// 有题目链接:加「提交」按钮const href = link.getAttribute('href') || '';const submitUrl = self.buildSubmitUrl(href);const a = document.createElement('a');a.href = submitUrl;a.className = 'bzoj-submit-col-link';a.textContent = '提交';a.title = '递交此题';a.target = link.target || '_self';td.appendChild(a);count++;} else {// 无题目链接(如 * 占位行):补空 td,保持列数一致,不破坏行的灰色背景td.innerHTML = ' ';}row.appendChild(td);row.dataset.bzojSubmitCell = '1';}table.dataset.bzojSubmitCol = '1';}return count;},_observer: null,_debounce: null,_installObserver: function () {const self = this;if (self._observer) return;self._observer = new MutationObserver(function () {clearTimeout(self._debounce);self._debounce = setTimeout(function () {self.injectColumns();}, 300);});self._observer.observe(document.body, { childList: true, subtree: true });}};// ================================================================// 模块四:比赛/作业成绩表增强(scoreboard)// 适用页面:// - /contest/<hex>/scoreboard// - /homework/<hex>/scoreboard// 功能:// 1. 黄色高亮当前登录用户所在行// 2. 对当前用户行的每道题,异步 fetch 该题的提交记录页面,// 提取最新一次提交的详细信息(状态、分数、耗时、内存),// 用直角状态方块显示在单元格内。// 兼容所有 Hydro 系 OJ。// ================================================================const BZOJ_ScoreboardModule = {/** 状态信息(复用 testcase 模块的颜色定义,方块改为直角) */STATUS_MAP: {'accepted': { bg: '#f6ffed', text: 'AC', color: '#389e0d', border: '#b7eb8f' },'wrong answer': { bg: '#fff2f0', text: 'WA', color: '#cf1322', border: '#ffccc7' },'time limit exceeded': { bg: '#e6f7ff', text: 'TLE', color: '#0958d9', border: '#91d5ff' },'memory limit exceeded': { bg: '#e6f7ff', text: 'MLE', color: '#0958d9', border: '#91d5ff' },'runtime error': { bg: '#f9f0ff', text: 'RE', color: '#722ed1', border: '#d3adf7' },'compile error': { bg: '#fffbe6', text: 'CE', color: '#d48806', border: '#ffe58f' },'output limit exceeded': { bg: '#e6f7ff', text: 'OLE', color: '#0958d9', border: '#91d5ff' },'system error': { bg: '#f5f5f5', text: 'SE', color: '#434343', border: '#d9d9d9' },'judging': { bg: '#e6f7ff', text: '⟳', color: '#0958d9', border: '#91d5ff', spin: true },'compiling': { bg: '#e6f7ff', text: '⟳', color: '#0958d9', border: '#91d5ff', spin: true },'waiting': { bg: '#e6f7ff', text: '⟳', color: '#0958d9', border: '#91d5ff', spin: true },'running': { bg: '#e6f7ff', text: '⟳', color: '#0958d9', border: '#91d5ff', spin: true },},DARK_STATUS_MAP: {'accepted': { bg: '#1e3a1e', text: 'AC', color: '#95de64', border: '#389e0d' },'wrong answer': { bg: '#3d1f22', text: 'WA', color: '#ff9c9c', border: '#a8071a' },'time limit exceeded': { bg: '#1a2d42', text: 'TLE', color: '#69c0ff', border: '#003a8c' },'memory limit exceeded': { bg: '#1a2d42', text: 'MLE', color: '#69c0ff', border: '#003a8c' },'runtime error': { bg: '#2d1f3d', text: 'RE', color: '#c9a0f5', border: '#531dab' },'compile error': { bg: '#3d321e', text: 'CE', color: '#ffd666', border: '#ad6800' },'output limit exceeded': { bg: '#1a2d42', text: 'OLE', color: '#69c0ff', border: '#003a8c' },'system error': { bg: '#2e2e2e', text: 'SE', color: '#d9d9d9', border: '#434343' },},/** 判断当前页面是否是成绩表页 */shouldRun: function () {const path = window.location.pathname;return /\/(contest|homework)\/[^\/]+\/scoreboard\/?$/.test(path);},/** 从 URL 提取 tid(比赛/作业 ID) */getTid: function () {const m = window.location.pathname.match(/\/(contest|homework)\/([^\/]+)\/scoreboard/);return m ? m[2] : '';},/** 检测暗色模式 */isDarkMode: function () {const html = document.documentElement;if (html.classList.contains('theme--dark')) return true;if (html.classList.contains('theme--light')) return false;if (html.getAttribute('data-mantine-color-scheme') === 'dark') return true;if (html.getAttribute('data-mantine-color-scheme') === 'light') return false;try {const bgColor = getComputedStyle(document.body).backgroundColor;const match = bgColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if (match) {return (0.299 * +match[1] + 0.587 * +match[2] + 0.114 * +match[3]) / 255 < 0.5;}} catch (e) {}return false;},/** 获取当前登录用户的 uid */getCurrentUid: function () {// Hydro 导航栏: nav .nav__list--secondary a[href^="/user/"]const userLink = document.querySelector('nav .nav__list--secondary a[href^="/user/"]');if (userLink) {const m = userLink.getAttribute('href').match(/\/user\/(\w+)/);if (m) return m[1];}// 兜底const altLink = document.querySelector('a[href^="/user/"][class*="user-profile"], a.uname[href^="/user/"]');if (altLink) {const m = altLink.getAttribute('href').match(/\/user\/(\w+)/);if (m) return m[1];}return null;},init: function () {const self = this;if (!self.shouldRun()) return;GM_addStyle(`/* 当前用户行高亮 */.bzoj-scoreboard-highlight {background-color: rgba(255, 230, 0, 0.25) !important;}.theme--dark .bzoj-scoreboard-highlight,html[data-mantine-color-scheme="dark"] .bzoj-scoreboard-highlight {background-color: rgba(255, 200, 0, 0.18) !important;}/* 详细状态方块(直角,填满单元格,契合表格) */.bzoj-score-cell {display: flex;flex-direction: column;align-items: center;justify-content: center;width: 100%;box-sizing: border-box;padding: 4px 2px;border: 1px solid;border-radius: 0;font-family: system-ui, -apple-system, sans-serif;font-weight: 600;line-height: 1.2;cursor: default;transition: transform 0.1s;text-decoration: none;}.bzoj-score-cell:hover {transform: scale(1.05);}/* 让 td 本身也成为 flex 容器,确保方块填满 */td.col--problem:has(.bzoj-score-cell) {padding: 2px !important;}.bzoj-score-cell__text {font-size: 11px;font-weight: 700;}.bzoj-score-cell__score {font-size: 13px;font-weight: 700;}.bzoj-score-cell__detail {font-size: 9px;font-weight: 400;opacity: 0.8;white-space: nowrap;}@keyframes bzoj-score-spin {from { transform: rotate(0deg); } to { transform: rotate(360deg); }}.bzoj-score-cell__text--spin {animation: bzoj-score-spin 1.5s linear infinite;}/* 加载中占位 */.bzoj-score-loading {display: inline-block;width: 14px;height: 14px;border: 2px solid rgba(86,117,143,0.2);border-top-color: #56758f;border-radius: 50%;animation: bzoj-score-spin 0.8s linear infinite;}`);self.enhanceScoreboard();self._installObserver();},/** 标准化状态文本 */normalizeStatus: function (raw) {if (!raw) return '';const text = raw.trim().toLowerCase();const aliases = {'time exceeded': 'time limit exceeded','memory exceeded': 'memory limit exceeded','ac': 'accepted', 'wa': 'wrong answer','tle': 'time limit exceeded', 'mle': 'memory limit exceeded','re': 'runtime error', 'ce': 'compile error','ole': 'output limit exceeded', 'se': 'system error',};if (aliases[text]) return aliases[text];for (const key of Object.keys(this.STATUS_MAP)) {if (text.includes(key)) return key;}return text;},/** 获取状态信息 */getStatusInfo: function (key) {const isDark = this.isDarkMode();const map = isDark ? this.DARK_STATUS_MAP : this.STATUS_MAP;return map[key] || {bg: isDark ? '#2e2e2e' : '#f5f5f5',text: key.substring(0, 3).toUpperCase(),color: isDark ? '#d9d9d9' : '#434343',border: isDark ? '#434343' : '#d9d9d9',};},/** 从表头提取每道题的 pid 列表 */extractProblemIds: function () {// Hydro 成绩表表头在独立的 sticky 表 (table.section__table-header) 或同表 theadconst headerLinks = document.querySelectorAll('table.section__table-header thead th.col--problem a[href*="/p/"], ' +'table thead th.col--problem a[href*="/p/"]');const pids = [];for (const a of headerLinks) {const m = a.getAttribute('href').match(/\/p\/([^\/?]+)/);if (m) pids.push(m[1]);}return pids;},/** 增强成绩表:高亮当前用户行 + 异步加载提交详情 */enhanceScoreboard: function () {const self = this;const uid = self.getCurrentUid();const tid = self.getTid();// 查找成绩表 tbody(Hydro 用 table.data-table,tbody 里有行)const tables = document.querySelectorAll('table.data-table');for (const table of tables) {const tbody = table.querySelector('tbody');if (!tbody) continue;const rows = tbody.querySelectorAll('tr');if (rows.length === 0) continue;// 检查是否是成绩表(有 col--rank / col--user 列)if (!table.querySelector('col.col--rank, col.col--user, td.col--rank, td.col--user')) continue;if (table.dataset.bzojScoreboard === '1') continue;table.dataset.bzojScoreboard = '1';// 提取每题 pid(从表头)const pids = self.extractProblemIds();for (const row of rows) {if (row.dataset.bzojScoreRow === '1') continue;row.dataset.bzojScoreRow = '1';// 高亮当前用户行if (uid) {const userBtn = row.querySelector('[data-uid]');const userLink = row.querySelector('a[href^="/user/"]');let rowUid = null;if (userBtn) rowUid = userBtn.getAttribute('data-uid');else if (userLink) {const m = userLink.getAttribute('href').match(/\/user\/(\w+)/);if (m) rowUid = m[1];}if (rowUid && rowUid === uid) {row.classList.add('bzoj-scoreboard-highlight');// 对当前用户行,异步加载每题提交详情self._loadUserSubmissionDetails(row, uid, tid, pids);}}}}},/** 异步加载当前用户每道题的提交详情 */_loadUserSubmissionDetails: async function (row, uid, tid, pids) {const self = this;// 获取当前行的题目单元格(col--problem)const problemCells = row.querySelectorAll('td.col--problem');if (problemCells.length === 0) return;// 为每个题目单元格先放加载占位problemCells.forEach((cell, idx) => {if (cell.querySelector('.bzoj-score-cell, .bzoj-score-loading')) return;// 保留原始分数文本const originalScore = cell.textContent.trim();cell.dataset.bzojOriginalScore = originalScore;const loader = document.createElement('span');loader.className = 'bzoj-score-loading';cell.innerHTML = '';cell.appendChild(loader);});// 逐题 fetch 提交记录for (let i = 0; i < problemCells.length && i < pids.length; i++) {const cell = problemCells[i];const pid = pids[i];try {await self._fetchAndShowDetail(cell, pid, uid, tid);} catch (e) {self._restoreCell(cell);}}},/** fetch 单题提交记录,提取最新提交的 record 链接,再 fetch record 详情 */_fetchAndShowDetail: async function (cell, pid, uid, tid) {const self = this;// Hydro 提交记录列表: /record?pid=<pid>&uidOrName=<uid>&tid=<tid>const listUrl = `/record?pid=${encodeURIComponent(pid)}&uidOrName=${encodeURIComponent(uid)}${tid ? '&tid=' + tid : ''}`;const resp = await fetch(listUrl, { credentials: 'same-origin' });const html = await resp.text();const doc = new DOMParser().parseFromString(html, 'text/html');// 找到第一条提交记录的链接 /record/<rid>const recordLink = doc.querySelector('a[href^="/record/"]');if (!recordLink) {self._restoreCell(cell);return;}const ridMatch = recordLink.getAttribute('href').match(/\/record\/(\w+)/);if (!ridMatch) {self._restoreCell(cell);return;}const rid = ridMatch[1];// fetch record 详情页const recordUrl = `/record/${rid}`;const resp2 = await fetch(recordUrl, { credentials: 'same-origin' });const html2 = await resp2.text();const doc2 = new DOMParser().parseFromString(html2, 'text/html');// 从 record 页面提取状态、分数、耗时、内存const detail = self._extractRecordDetail(doc2);self._renderDetailCell(cell, detail, recordUrl);},/** 从 record 详情页提取状态/分数/耗时/内存* 页面结构:* 顶栏 #status .section__title 内含 .record-status--text(状态文字,如 Accepted)* 和 .float-right 或无 class 的 span(分数,如 60)* 侧边栏 #summary 的 dl.horizontal 内:* <dt>分数</dt><dd>60</dd>* <dt>总耗时</dt><dd>39ms</dd>* <dt>峰值时间</dt><dd>1ms</dd>* <dt>峰值内存</dt><dd>768 KiB</dd>*/_extractRecordDetail: function (doc) {const self = this;// 状态:顶栏的 .record-status--text(排除 .float-right 分数部分)let statusKey = '';const statusEls = doc.querySelectorAll('#status .record-status--text, .record-status--text');for (const el of statusEls) {// 克隆后移除 .float-right 子元素,只取状态文字const clone = el.cloneNode(true);clone.querySelectorAll('.float-right').forEach(e => e.remove());const text = clone.textContent.trim();if (text) {statusKey = self.normalizeStatus(text);if (statusKey) break;}}// 从 #summary 的 dl.horizontal 提取分数/时间/内存let score = '', time = '', memory = '';const summaryDl = doc.querySelector('#summary, dl#summary');if (summaryDl) {const dts = summaryDl.querySelectorAll('dt');const dds = summaryDl.querySelectorAll('dd');for (let i = 0; i < dts.length && i < dds.length; i++) {const label = dts[i].textContent.trim().toLowerCase();const value = dds[i].textContent.trim();if (label === '分数' || label === 'score') {score = value;} else if (label === '峰值时间' || label === '总耗时' || label.includes('时间') || label.includes('time')) {if (!time) time = value; // 优先取峰值时间/总耗时} else if (label === '峰值内存' || label.includes('内存') || label.includes('memory')) {memory = value;}}}// 兜底:分数从顶栏 .float-right 或 section__title 提取if (!score) {const floatRight = doc.querySelector('#status .float-right, .record-status--text .float-right');if (floatRight) {score = floatRight.textContent.trim();}}if (!score) {const titleEl = doc.querySelector('#status .section__title');if (titleEl) {const m = titleEl.textContent.match(/(\d+)/);if (m) score = m[1];}}return { statusKey, score, time, memory };},/** 渲染详细状态方块到单元格 */_renderDetailCell: function (cell, detail, recordUrl) {const self = this;const originalScore = cell.dataset.bzojOriginalScore || '';cell.innerHTML = '';if (!detail.statusKey && !detail.score && !originalScore) {self._restoreCell(cell);return;}const statusKey = detail.statusKey || '';const info = statusKey ? self.getStatusInfo(statusKey) : {bg: this.isDarkMode() ? '#2e2e2e' : '#f5f5f5',text: '', color: this.isDarkMode() ? '#d9d9d9' : '#434343',border: this.isDarkMode() ? '#434343' : '#d9d9d9',};const block = document.createElement('a');block.href = recordUrl;block.target = '_blank';block.className = 'bzoj-score-cell';block.style.background = info.bg;block.style.color = info.color;block.style.borderColor = info.border;// 状态缩写if (info.text) {const textEl = document.createElement('span');textEl.className = 'bzoj-score-cell__text';if (info.spin) textEl.classList.add('bzoj-score-cell__text--spin');textEl.textContent = info.text;block.appendChild(textEl);}// 分数const scoreVal = detail.score || originalScore;if (scoreVal) {const scoreEl = document.createElement('span');scoreEl.className = 'bzoj-score-cell__score';scoreEl.textContent = scoreVal;block.appendChild(scoreEl);}// 耗时 / 内存if (detail.time || detail.memory) {const detailEl = document.createElement('span');detailEl.className = 'bzoj-score-cell__detail';detailEl.textContent = [detail.time, detail.memory].filter(Boolean).join(' / ');block.appendChild(detailEl);}cell.appendChild(block);},/** 恢复原始分数显示 */_restoreCell: function (cell) {const original = cell.dataset.bzojOriginalScore;if (original !== undefined) {cell.innerHTML = '';cell.textContent = original;}},_observer: null,_debounce: null,_installObserver: function () {const self = this;if (self._observer) return;self._observer = new MutationObserver(function () {clearTimeout(self._debounce);self._debounce = setTimeout(function () {self.enhanceScoreboard();}, 500);});self._observer.observe(document.body, { childList: true, subtree: true });}};// ================================================================// 模块五:网页字体更换器(所有站点运行)// ================================================================// ==================== 默认常量 ====================const FS_DEFAULT_BTN_SIZE = 42;const FS_COLLAPSED_VISIBLE = 6;1,650 行未改动全部展开fsResetIdleTimer();}// ================================================================// 主入口:初始化五个模块// ================================================================function main() {// 字体更换器:所有站点运行3 行未改动BZOJ_TestcaseModule.init();// BZOJ 题目 Markdown 查看/复制:仅 /p/<id> 题目详情页运行(init 内部有路径与结构双重判断)BZOJ_ProblemMarkdownModule.init();// BZOJ 题目列表「提交」快捷列:仅题库/比赛/作业/训练列表页运行BZOJ_SubmitLinkModule.init();// BZOJ 成绩表增强:仅 /contest/<hex>/scoreboard 和 /homework/<hex>/scoreboard 运行BZOJ_ScoreboardModule.init();}if (document.readyState === 'complete' || document.readyState === 'interactive') {main();6 行未改动