版本比较
BZOJ字体更换器+测评记录仿洛谷
标题
增加 1 行删除 1 行
11BZOJ字体更换器+测评记录仿洛谷(内测版)BZOJ字体更换器+测评记录仿洛谷正文
增加 67 行删除 90 行
11234567821 行未改动303132333134353334363738394020 行未改动6162636465636667686970145 行未改动全部展开21621721821921721822022122222322422522622722822923023123223323423523623723823924024124224322322422522622724424524624711 行未改动2592602612622472482632642652662672682532692702712722732742592752762772782792802652662672812822832842852862732742752762772782792802872882892902822832912922932942953 行未改动2993003013023033042963053062983073083093103115 行未改动3173183193203123133213223233243253263273203213283293303313323263333343353363313373383393403413373383423433443453463473423483443493503473513523533513543553543553563573573583593603613623633583593603613623633643653653663673663673683703693723703713723733743753793803763773783793833843853863873883893903803813823923833843853863873973883894003903914033923933943953963973984113994004014024034174184194044054064074086 行未改动4154164174184344194204214229 行未改动43243343443545245343643743843944044144244346044444544644744815 行未改动46446546646748448546848646947047147242 行未改动51551651751853751952052152252320 行未改动54454554654756656754854955055155255355455555657755755855956056156256358556456556656717 行未改动58558658758861158959059159210 行未改动603604605606630631607608# BZOJ字体更换器+测评记录仿洛谷(内测版)# BZOJ字体更换器+测评记录仿洛谷(AI写的油猴插件,增加支持Hydro,bug已修,发现有bug请联系@[xiaxiang2014](luogu://user/2058296))## 开发者:夏翔(luogu:[xiaxiang2014](https://www.luogu.com.cn/user/2058296))(BZOJ:[2025xf29](https://bzoj.org/user/2575))## 后续开发者:杨皓然(luogu:[woshiyhr](https://www.luogu.com.cn/user/1584704))(BZOJ:[123](https://bzoj.org/user/2306))## 可以用杨皓然后续开发的[BZOJ 增强工具 + 网页字体更换器](https://www.luogu.me/article/mdpqqgoq),他又往里面增加了其它的一些功能。## 功能### 可以为[bzoj](https://bzoj.org/)的代码块和界面分别更换字体,且能在测评记录页面提供仿洛谷的小方块样式。## 效果21 行未改动// ==UserScript==// @name BZOJ 综合增强:测试点大方块 + 分区字体恢复// @namespace https://bzoj.org/// @version 1.0.0// @description 记录详情页显示测试点大方块(修复混合子任务显示)、自动轮询;偏好设置页恢复界面/代码字体独立设置;修复亮色模式小方块背景异常// @description 适用于任意 Hydro OJ 的测试点大方块、自动轮询、字体独立设置;无分数显示;悬停仅显示状态名+耗时+内存// @author bzoj-enhancer// @match https://bzoj.org/*// @match https://*.bzoj.org/*// @match https://*/*// @grant GM_notification// @grant GM_addStyle// @grant GM_getValue// @grant GM_setValue20 行未改动 if (window.location.pathname.includes('/home/settings/preference')) { this.wakeUpPreferencePage(); } GM_registerMenuCommand('⚙️ 前往字体偏好设置', () => { const domain = window.location.origin; window.open('https://bzoj.org/home/settings/preference', '_blank'); window.open(domain + '/home/settings/preference', '_blank'); }); },
applyFonts: function (uiFont, codeFont) {145 行未改动全部展开 lastBannerKey: '', pollTimer: null, lastOverallStatus: '', observer: null, themeObserver: null, // 监听主题变化 containerElem: null, // 保存容器引用 themeObserver: null, containerElem: null,
// 提取纯净状态名(用于方块缩写和通知) extractStatus: function(raw) { if (!raw) return ''; const firstLine = raw.trim().split('\n')[0]; const statusNames = [ 'Accepted', 'Wrong Answer', 'Time Limit Exceeded', 'Memory Limit Exceeded', 'Runtime Error', 'Compile Error', 'Output Limit Exceeded', 'System Error', 'Judging', 'Compiling', 'Waiting', 'Running', 'Fetched' ]; for (const name of statusNames) { if (firstLine.toLowerCase().includes(name.toLowerCase())) return name; } for (const alias of Object.keys(this.ALIAS_MAP)) { if (firstLine.toLowerCase().includes(alias)) return alias; } return firstLine.substring(0, 40); },
normalizeStatus: function(raw) { if (!raw) return ''; let text = raw.trim().toLowerCase(); if (text.length > 40) { for (const kw of Object.keys(this.ALIAS_MAP).concat(Object.keys(this.STATUS_MAP))) { if (text.includes(kw)) { text = kw; break; } } } if (this.ALIAS_MAP[text]) return this.ALIAS_MAP[text]; if (this.STATUS_MAP[text]) return text; for (const key of Object.keys(this.STATUS_MAP)) { if (text.includes(key)) return key;11 行未改动
getOverallStatusKey: function(doc = document) { const primary = doc.querySelector('.record-status--text'); if (primary) { const raw = primary.textContent.trim(); if (raw) return this.normalizeStatus(raw); const status = this.extractStatus(primary.textContent.trim()); return this.normalizeStatus(status); } const dataEl = doc.querySelector('[data-status]'); if (dataEl) { const ds = dataEl.getAttribute('data-status'); if (ds) return this.normalizeStatus(ds); if (ds) return this.normalizeStatus(this.extractStatus(ds)); } const cells = doc.querySelectorAll('.detail-status, td[class*="status"]'); for (const cell of cells) { const text = cell.textContent.trim(); if (text.includes('#') && text.includes('ms')) continue; if (text.length < 40 && text.length > 0) return this.normalizeStatus(text); if (text.length < 40 && text.length > 0) return this.normalizeStatus(this.extractStatus(text)); } const bodyText = doc.body.innerText.toLowerCase(); const checkOrder = ['accepted', 'wrong answer', 'time limit exceeded', 'memory limit exceeded', 'runtime error', 'compile error', 'output limit exceeded', 'system error', 'judging', 'compiling', 'waiting', 'running', 'fetched']; for (const kw of checkOrder) { if (bodyText.includes(kw)) return kw; } for (const kw of checkOrder) if (bodyText.includes(kw)) return kw; return ''; },
getWorstStatus: function(testcases) { const severity = { 'system error': 10, 'runtime error': 9, 'memory limit exceeded': 8, 'time limit exceeded': 7, 'output limit exceeded': 6, 'wrong answer': 5, 'compile error': 4, 'accepted': 3, 'system error': 10, 'runtime error': 9, 'memory limit exceeded': 8, 'time limit exceeded': 7, 'output limit exceeded': 6, 'wrong answer': 5, 'compile error': 4, 'accepted': 3, }; let worst = 'accepted'; let worstScore = 0; let worst = 'accepted', worstScore = 0; for (const tc of testcases) { const s = severity[tc.key] || 0; if (s > worstScore) { worstScore = s; worst = tc.key; } }3 行未改动 notifyAndBanner: function(statusKey) { if (statusKey === this.lastBannerKey) return; this.lastBannerKey = statusKey; const info = this.getStatusInfo(statusKey); const notifyTitle = '评测状态更新'; if (typeof GM_notification !== 'undefined') { GM_notification({ title: 'BZOJ 状态更新', text: info.display, timeout: 5000 }); GM_notification({ title: notifyTitle, text: info.display, timeout: 5000 }); } else if ('Notification' in window && Notification.permission === 'granted') { new Notification('BZOJ 状态更新', { body: info.display }); new Notification(notifyTitle, { body: info.display }); } const old = document.getElementById('bzoj-auto-banner'); if (old) old.remove(); const banner = document.createElement('div');5 行未改动 `; banner.textContent = `📢 评测状态:${info.display}`; document.body.prepend(banner); setTimeout(() => { banner.style.opacity = '0'; banner.style.transition = 'opacity 0.5s'; banner.style.opacity = '0'; banner.style.transition = 'opacity 0.5s'; setTimeout(() => banner.remove(), 500); }, 4000); },
getColumnMap: function(table) { const ths = table.querySelectorAll('thead th, thead td'); const map = { status: -1, score: -1, time: -1, memory: -1 };
const map = { status: -1, time: -1, memory: -1 }; if (ths.length > 0) { for (let i = 0; i < ths.length; i++) { const text = ths[i].textContent.trim().toLowerCase(); if (text.includes('状态') || text.includes('status')) map.status = i; if (text.includes('分数') || text.includes('score') || text.includes('point')) map.score = i; if (text.includes('耗时') || text.includes('时间') || text.includes('time')) map.time = i; if (text.includes('内存') || text.includes('memory') || text.includes('空间')) map.memory = i; } }
const rows = table.querySelectorAll('tbody tr'); for (const row of rows) { const cells = row.cells; for (let i = 0; i < cells.length; i++) { const t = cells[i].textContent.trim().toLowerCase(); if (map.time < 0 && /(ms|sec|s|秒)/.test(t) && /\d/.test(t)) map.time = i; if (map.memory < 0 && /(mib|kib|mb|kb)/.test(t) && /\d/.test(t)) map.memory = i; if (/(error|line|read|expect|on line)/i.test(t)) continue; if (map.time < 0 && /(\d+(\.\d+)?\s*(ms|sec|s|秒))/.test(t)) map.time = i; if (map.memory < 0 && /(\d+(\.\d+)?\s*(mib|kib|mb|kb|gib|gb))/i.test(t)) map.memory = i; } if (map.time >= 0 && map.memory >= 0) break; }
if (map.status < 0) map.status = 1; if (map.score < 0) map.score = 2; if (map.time < 0) map.time = 3; if (map.memory < 0) map.memory = 4;
return map; },
// 改进的提取逻辑,同时支持子测试点和普通测试点 extractTestCases: function(doc) { const rows = doc.querySelectorAll('table tbody tr'); let testRows = [];
const testRows = []; for (const row of rows) { const first = row.cells[0]?.textContent.trim(); if (/^#\d+-\d+$/.test(first)) testRows.push(row); }
for (const row of rows) { const first = row.cells[0]?.textContent.trim(); if (/^#\d+$/.test(first)) { const firstCell = row.cells[0]; if (!firstCell) continue; const id = firstCell.textContent.trim(); if (/^#\d+-\d+$/.test(id)) { testRows.push(row); continue; } if (/^#\d+$/.test(id)) { const rowText = row.textContent.toLowerCase(); if (/(ms|sec|s|mib|kib|mb|kb)/.test(rowText)) { testRows.push(row); } if (/(ms|sec|s|mib|kib|mb|kb)/.test(rowText)) testRows.push(row); } }
if (testRows.length === 0) return null;
const table = testRows[0].closest('table'); const colMap = this.getColumnMap(table); const cases = []; for (const row of testRows) { const cells = row.cells; const id = cells[0]?.textContent.trim() || '?'; let rawStatus = cells[colMap.status]?.textContent.trim() || ''; let score = cells[colMap.score]?.textContent.trim() || '0'; const rawFull = cells[colMap.status]?.textContent.trim() || ''; const status = this.extractStatus(rawFull); // 只取状态名 const time = cells[colMap.time]?.textContent.trim() || ''; const memory = cells[colMap.memory]?.textContent.trim() || '';
const statusMatch = rawStatus.match(/^(\D+)\s*(\d+)$/); if (statusMatch) { rawStatus = statusMatch[1].trim(); score = statusMatch[2]; }
const key = this.normalizeStatus(rawStatus); const key = this.normalizeStatus(status); const info = this.getStatusInfo(key); // 不再保留 fullStatus,直接使用 info.display 作为悬停的状态名 cases.push({ id, key, info, score, time, memory }); cases.push({ id, key, info, time, memory }); } return cases; },
// 根据页面主题更新容器背景色 updateContainerTheme: function() { if (!this.containerElem) return; // 检测是否为亮色主题:优先检查 body 的 class 或 data-theme,其次计算背景亮度 const body = document.body; let isLight = false; // 常见 Hydro 暗色主题 class if (body.classList.contains('dark') || body.classList.contains('theme-dark') || (body.getAttribute('data-theme') === 'dark')) { isLight = false; } else if (body.classList.contains('light') || body.classList.contains('theme-light') || (body.getAttribute('data-theme') === 'light')) { isLight = true; } else { // 回退:计算 body 背景色的亮度 const bgColor = window.getComputedStyle(body).backgroundColor; const rgb = bgColor.match(/\d+/g); if (rgb) { const brightness = (parseInt(rgb[0]) * 299 + parseInt(rgb[1]) * 587 + parseInt(rgb[2]) * 114) / 1000; isLight = brightness > 128; } else { isLight = true; // 默认亮色模式 } } else isLight = true; } this.containerElem.style.backgroundColor = isLight ? '#f5f7fa' : '#323334'; this.containerElem.style.border = isLight ? '1px solid #e2e4e8' : 'none'; },6 行未改动 const first = row.cells[0]?.textContent.trim(); if (first && /^#\d+(-\d+)?$/.test(first)) { table.style.display = 'none'; break; } } }
let container = document.getElementById('bzoj-testcase-blocks'); if (!container) { container = document.createElement('div'); container.id = 'bzoj-testcase-blocks';9 行未改动 (document.querySelector('.record-container') || document.body).prepend(container); } } this.containerElem = container; this.updateContainerTheme(); // 应用正确的背景色
this.updateContainerTheme(); container.innerHTML = ''; let allFinished = true; for (const tc of testcases) { if (!this.isFinished(tc.key)) allFinished = false; const block = document.createElement('div'); block.className = 'bzoj-testcase-block'; // 悬停仅显示状态全名、耗时、内存 block.title = `${tc.info.display}\n得分: ${tc.score}\n耗时: ${tc.time}\n内存: ${tc.memory}`; block.title = `${tc.info.display}\n耗时: ${tc.time}\n内存: ${tc.memory}`; block.style.cssText = ` display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100px; height: 100px; font-weight: bold; background: ${tc.info.bg}; color: ${tc.info.color};15 行未改动 statusSpan.style.cssText = 'font-size:24px; font-weight:normal; margin-bottom:8px;'; if (tc.info.spin) { statusSpan.textContent = tc.info.text; statusSpan.style.animation = 'bzoj-spin 1.5s linear infinite'; } else { statusSpan.textContent = tc.info.text; } else statusSpan.textContent = tc.info.text; } block.appendChild(statusSpan); const detail = document.createElement('span'); detail.style.cssText = 'font-size:12px; font-weight:normal; text-align:center; white-space:nowrap;'; let dt = '';42 行未改动 self.lastOverallStatus = overall; } } } } catch (e) { console.error('[BZOJ轮询] 网络错误', e); } } catch (e) { console.error('[轮询] 网络错误', e); } },
startPolling: function() { if (this.pollTimer) return;20 行未改动 } } }); this.observer.observe(document.body, { childList: true, subtree: true });
// 监听主题变化(body class 或 data-theme 变化) if (this.themeObserver) this.themeObserver.disconnect(); this.themeObserver = new MutationObserver(() => { if (this.containerElem) this.updateContainerTheme(); }); this.themeObserver.observe(document.body, { attributes: true, attributeFilter: ['class', 'data-theme'] }); },
init: function() { if (!/\/record\/[a-f0-9]+/i.test(window.location.pathname)) return;
const self = this; GM_addStyle(` @keyframes bzoj-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .bzoj-testcase-block { transition: transform 0.2s; } .bzoj-testcase-block:hover { transform: scale(1.1); } table thead { display: none !important; } `);
const initialCases = self.extractTestCases(document); if (initialCases) { const allDone = self.updateBlocks(initialCases); if (!allDone) {17 行未改动 } }, 1000); } }
self.installObserver(); } };
10 行未改动 }})();```## 附件### [BZOJ 综合增强:测试点大方块 + 分区字体恢复-1.0.0.user.js](https://www.luogu.com.cn/fe/api/problem/downloadAttachment/3ma8c8zg)# ©版权声明:本脚本由AI生成,内测阶段请不要公开!### [BZOJ 综合增强:测试点大方块 + 分区字体恢复-1.0.0.user.js](https://www.luogu.com.cn/fe/api/problem/downloadAttachment/e7iys27x)# ©版权声明:本脚本由AI生成!