正文
增加 38 行删除 85 行
1234567818 行未改动27282930313233343536373822 行未改动616263646566676869150 行未改动全部展开22022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225311 行未改动2652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093 行未改动31331431531631731831932032110 行未改动33233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442512 行未改动4384394404414424434444454464474486 行未改动45545645745845946046146246310 行未改动47447547647747847948048148248348448548648748848915 行未改动50550650750850951051151251351451542 行未改动55855956056156256356456556620 行未改动58758858959059159259359459559659759859960060160260360460560660760860961061161261317 行未改动63163263363463563663763863910 行未改动650651652653654655# BZOJ字体更换器+测评记录仿洛谷(AI写的油猴插件,增加支持Hydro,bug已修)## 开发者:夏翔(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/artugicle/mdpqqgoq),他又往里面增加了其它的一些功能。## 功能### 可以为[bzoj](https://bzoj.org/)的代码块和界面分别更换字体,且能在测评记录页面提供仿洛谷的小方块样式。## 效果18 行未改动#### 点击油猴图标,点击【前往字体偏好设置】,或点击[这里](https://bzoj.org/home/settings/preference)前往字体偏好设置,往下滑,点击【Using custom font】按钮可更换界面字体,点击【Find custom font】可以更换代码字体。## 脚本```javascript// ==UserScript==// @name BZOJ 综合增强:测试点大方块 + 分区字体恢复(通用 Hydro 版)// @namespace https://bzoj.org/// @version 1.0.0// @description 适用于任意 Hydro OJ 的测试点大方块、自动轮询、字体独立设置;亮色模式自适应;通知标题通用化// @author bzoj-enhancer// @match https://*/*// @grant GM_notification// @grant GM_addStyle22 行未改动if (window.location.pathname.includes('/home/settings/preference')) {this.wakeUpPreferencePage();}GM_registerMenuCommand('⚙️ 前往字体偏好设置', () => {// 动态获取当前网站域名const domain = window.location.origin;window.open(domain + '/home/settings/preference', '_blank');});},150 行未改动全部展开observer: null,themeObserver: null,containerElem: null,cleanStatusText: function(raw) {if (!raw) return '';const firstLine = raw.split('\n')[0].trim();const fullNames = ['Accepted', 'Wrong Answer', 'Time Limit Exceeded', 'Memory Limit Exceeded','Runtime Error', 'Compile Error', 'Output Limit Exceeded', 'System Error','Judging', 'Compiling', 'Waiting', 'Running', 'Fetched'];const lower = firstLine.toLowerCase();for (const name of fullNames) {if (lower.includes(name.toLowerCase())) return name;}for (const alias of Object.keys(this.ALIAS_MAP)) {if (lower.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(this.cleanStatusText(raw));}const dataEl = doc.querySelector('[data-status]');if (dataEl) {const ds = dataEl.getAttribute('data-status');if (ds) return this.normalizeStatus(this.cleanStatusText(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(this.cleanStatusText(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;}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,};let worst = 'accepted';let 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: notifyTitle, text: info.display, timeout: 5000 });} else if ('Notification' in window && Notification.permission === 'granted') {10 行未改动`;banner.textContent = `📢 评测状态:${info.display}`;document.body.prepend(banner);setTimeout(() => {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 };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 && /(\d+(\.\d+)?\s*(ms|sec|s|秒))/.test(t) && !/error|line|read|expect/i.test(t)) {map.time = i;}if (map.memory < 0 && /(\d+(\.\d+)?\s*(mib|kib|mb|kb|gib|gb))/i.test(t) && !/error|line|read|expect/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');const testRows = [];for (const row of rows) {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 (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() || '';rawStatus = this.cleanStatusText(rawStatus);let score = cells[colMap.score]?.textContent.trim() || '0';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 info = this.getStatusInfo(key);cases.push({ id, key, info, score, time, memory });}return cases;},12 行未改动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;}}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';10 行未改动}}this.containerElem = container;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.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;}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); }},startPolling: function() {if (this.pollTimer) return;20 行未改动}}});this.observer.observe(document.body, { childList: true, subtree: true });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/vcbuxet2)# ©版权声明:本脚本由AI生成!1234567818 行未改动27282930313233343536373822 行未改动6162636465666768150 行未改动全部展开21922022122222322422522622722822923023123223323423523623723823924024124224324424524624711 行未改动2592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942953 行未改动29930030130230330430530610 行未改动31731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638712 行未改动4004014024034044054064074086 行未改动41541641741841942042142210 行未改动43343443543643743843944044144244344444544644744815 行未改动46446546646746846947047147242 行未改动51551651751851952052152252320 行未改动54454554654754854955055155255355455555655755855956056156256356456556656717 行未改动58558658758858959059159210 行未改动603604605606607608# 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/)的代码块和界面分别更换字体,且能在测评记录页面提供仿洛谷的小方块样式。## 效果18 行未改动#### 点击油猴图标,点击【前往字体偏好设置】,或点击[这里](https://bzoj.org/home/settings/preference)前往字体偏好设置,往下滑,点击【Using custom font】按钮可更换界面字体,点击【Find custom font】可以更换代码字体。## 脚本```javascript// ==UserScript==// @name BZOJ 综合增强:测试点大方块 + 分区字体恢复// @namespace https://bzoj.org/// @version 1.0.0// @description 适用于任意 Hydro OJ 的测试点大方块、自动轮询、字体独立设置;无分数显示;悬停仅显示状态名+耗时+内存// @author bzoj-enhancer// @match https://*/*// @grant GM_notification// @grant GM_addStyle22 行未改动if (window.location.pathname.includes('/home/settings/preference')) {this.wakeUpPreferencePage();}GM_registerMenuCommand('⚙️ 前往字体偏好设置', () => {const domain = window.location.origin;window.open(domain + '/home/settings/preference', '_blank');});},150 行未改动全部展开observer: 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 (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 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(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(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;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,};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: notifyTitle, text: info.display, timeout: 5000 });} else if ('Notification' in window && Notification.permission === 'granted') {10 行未改动`;banner.textContent = `📢 评测状态:${info.display}`;document.body.prepend(banner);setTimeout(() => {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, 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('时间') || 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 (/(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.time < 0) map.time = 3;if (map.memory < 0) map.memory = 4;return map;},extractTestCases: function(doc) {const rows = doc.querySelectorAll('table tbody tr');const testRows = [];for (const row of rows) {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 (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() || '?';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 key = this.normalizeStatus(status);const info = this.getStatusInfo(key);// 不再保留 fullStatus,直接使用 info.display 作为悬停的状态名cases.push({ id, key, info, time, memory });}return cases;},12 行未改动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;}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';10 行未改动}}this.containerElem = container;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.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;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('[轮询] 网络错误', e); }},startPolling: function() {if (this.pollTimer) return;20 行未改动}}});this.observer.observe(document.body, { childList: true, subtree: true });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/e7iys27x)# ©版权声明:本脚本由AI生成!