正文
增加 86 行删除 40 行
12345616 行未改动232425262728293031323334353637383940414243444546474849505152535455565758596013 行未改动7475767778798081829 行未改动92939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341354 行未改动14014114214314414514614734 行未改动1821831841851861871881891901911921931941951961971981992002012022032042052062072085 行未改动21421521621721821922022122267 行未改动290291292293294295296::::warning{open}本脚本需要油猴插件,请自行下载。::::::::info{open}为什么我不去申请全站推荐,因为这是Deepseek生成的。::::16 行未改动// ====================```但是这个插件会卡顿一下子,这个也已经做到最优了,没法优化了。# 插件下载地址:飞书链接:<https://icnuq91erjxa.feishu.cn/drive/folder/QPkxfQ5fNlgFPbdVIR5c5M2mnoe?from=from_copylink> 密码:3c554&67在插件文件夹里的名叫"用户名改色-15.0.user.js"。或者可以直接使用下面的代码:```javascript line-numbers lines=13-16// ==UserScript==// @name 洛谷用户名改色// @namespace http://www.luogu.com.cn/user/1831977// @version 15.0// @description 洛谷用户名改色工具// @match https://www.luogu.com.cn/*// @grant none// ==/UserScript==(function() {'use strict';// ===== 配置区域 =====const CONFIG = {username: 'is_ware', // 要匹配的用户名highlightColor: '红', // 高亮颜色// 原色(默认链接颜色),这些颜色的链接会被跳过originalColors: ['rgb(52, 152, 219)', // 洛谷默认蓝色'rgb(52,152,219)','#3498db','#3498DB','rgb(0, 102, 204)','rgb(0,102,204)']};// ====================const COLOR_MAP = {13 行未改动}const username = CONFIG.username;console.log(`[文字高亮] 目标用户名: "${username}"`);console.log(`[文字高亮] 原色: ${CONFIG.originalColors.join(', ')}`);// 标准化颜色字符串function normalizeColor(color) {if (!color) return '';9 行未改动return 'rgb(0,0,0)';}}// 检查颜色是否是原色(默认链接颜色)function isOriginalColor(element) {const color = getElementColor(element);return CONFIG.originalColors.some(original => {return color === normalizeColor(original);});}// 检查是否是大用户名(要排除的)function isBigUsername(element) {if (!element) return false;if (element.tagName === 'SPAN') {const parent = element.parentElement;if (parent && parent.className && typeof parent.className === 'string') {const classes = parent.className.split(' ');if (classes.includes('luogu-username') && classes.includes('user-name')) {console.log(`[文字高亮] ⚠️ 排除: 大用户名 "${element.textContent.trim()}"`);return true;}}}return false;}// 检查是否应该高亮function shouldHighlight(element) {// 如果是大用户名,排除if (isBigUsername(element)) {return false;}// 如果是链接且颜色是原色,排除if (element.tagName === 'A') {if (isOriginalColor(element)) {console.log(`[文字高亮] ⚠️ 跳过: 原色链接 "${element.textContent.trim()}"`);return false;}}4 行未改动function highlightTexts() {let count = 0;let skippedBigUser = 0;let skippedOriginal = 0;let processed = 0;const maxProcess = 200;const walker = document.createTreeWalker(34 行未改动nodes.forEach(textNode => {const parent = textNode.parentElement;if (!parent) return;// 检查是否应该高亮if (!shouldHighlight(parent)) {if (isBigUsername(parent)) {skippedBigUser++;} else if (parent.tagName === 'A' && isOriginalColor(parent)) {skippedOriginal++;}return;}if (parent.dataset.highlighted === 'true') return;if (parent.tagName === 'A') {parent.style.color = targetColor;parent.style.fontWeight = 'bold';parent.style.setProperty('color', targetColor, 'important');parent.dataset.highlighted = 'true';count++;console.log(`[文字高亮] ✅ 高亮链接(非原色): "${textNode.textContent.trim()}"`);} else {const span = document.createElement('span');span.style.color = targetColor;span.style.fontWeight = 'bold';5 行未改动console.log(`[文字高亮] ✅ 高亮文字: "${textNode.textContent.trim()}"`);}});console.log(`[文字高亮] 结果: 高亮 ${count} 个,跳过 ${skippedBigUser} 个(大用户名),跳过 ${skippedOriginal} 个(原色链接)`);return count;}// 清除高亮标记67 行未改动setTimeout(runHighlight, 500);};console.log('[文字高亮] 脚本已启动');console.log('[文字高亮] 规则: 只高亮非原色链接');})();```123456716 行未改动24252627282930313233343536373839404142434445464748495013 行未改动6465666768697071729 行未改动8283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641654 行未改动17017117217317417517617717834 行未改动2132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542555 行未改动26126226326426526626726826967 行未改动337338339340341342::::warning{open}本脚本需要油猴插件,请自行下载。本插件可能会被洛谷自动封禁AI封禁,请谨慎使用,被封禁概不负责。::::::::info{open}为什么我不去申请全站推荐,因为这是Deepseek生成的。::::16 行未改动// ====================```但是这个插件会卡顿一下子,这个也已经做到最优了,没法优化了。# 插件下载地址:直接使用下面的代码:```javascript line-numbers lines=13-17// ==UserScript==// @name 洛谷用户名改色// @namespace https://luogu.com.cn/user/1831977// @version 17.0// @description 跳过渲染的用户名也修改牌子颜色// @match https://www.luogu.com.cn/*// @grant none// ==/UserScript==(function() {'use strict';// ===== 配置区域 =====const CONFIG = {username: 'is_ware', // 要匹配的用户名highlightColor: '红' // 高亮颜色};// ====================const COLOR_MAP = {13 行未改动}const username = CONFIG.username;console.log(`[文字高亮] 目标用户名: "${username}"`);console.log(`[文字高亮] 目标颜色: ${targetColor}`);// 标准化颜色字符串function normalizeColor(color) {if (!color) return '';9 行未改动return 'rgb(0,0,0)';}}// 检查是否是原色链接(蓝色)function isOriginalColor(element) {const color = getElementColor(element);const originalColors = ['rgb(52,152,219)','#3498db','#3498db'];return originalColors.some(original => color === normalizeColor(original));}// 检查是否是大用户名(主页顶部)function isBigUsername(element) {if (!element) return false;if (element.tagName === 'SPAN') {const parent = element.parentElement;if (parent && parent.className && typeof parent.className === 'string') {const classes = parent.className.split(' ');if (classes.includes('luogu-username') && classes.includes('user-name')) {return true;}}}return false;}// 查找并修改用户名旁边的牌子function modifyBadge(usernameElement) {// 向上查找 luogu-username 容器let container = usernameElement;let depth = 0;const maxDepth = 5;let modified = false;while (container && depth < maxDepth) {if (container.className && typeof container.className === 'string') {const classes = container.className.split(' ');if (classes.includes('luogu-username')) {// 找到容器内的所有 span 标签(通常是牌子)const spans = container.querySelectorAll('span');spans.forEach(span => {// 检查是否是牌子(通常有背景色,且不是用户名本身)const style = window.getComputedStyle(span);const bgColor = style.backgroundColor;// 如果有背景色,且不是白色/透明,认为是牌子if (bgColor && bgColor !== 'rgba(0, 0, 0, 0)' && bgColor !== 'transparent' && bgColor !== 'rgba(255, 255, 255, 0)') {// 修改牌子的颜色span.style.backgroundColor = targetColor;span.style.borderColor = targetColor;span.style.color = '#FFFFFF';span.style.setProperty('background-color', targetColor, 'important');span.style.setProperty('border-color', targetColor, 'important');console.log(`[文字高亮] 🏷️ 修改牌子颜色: "${span.textContent.trim()}" -> ${targetColor}`);modified = true;}});break;}}container = container.parentElement;depth++;}return modified;}// 检查是否应该高亮用户名function shouldHighlight(element) {// 如果是大用户名,跳过if (isBigUsername(element)) {return false;}// 如果是链接且颜色是原色,跳过if (element.tagName === 'A') {if (isOriginalColor(element)) {return false;}}4 行未改动function highlightTexts() {let count = 0;let skippedBigUser = 0;let skippedOriginal = 0;let badgeModified = 0;let processed = 0;const maxProcess = 200;const walker = document.createTreeWalker(34 行未改动nodes.forEach(textNode => {const parent = textNode.parentElement;if (!parent) return;// 检查是否应该高亮用户名const highlight = shouldHighlight(parent);// 如果是大用户名,跳过渲染但修改牌子if (isBigUsername(parent)) {skippedBigUser++;// 仍然尝试修改牌子const modified = modifyBadge(parent);if (modified) badgeModified++;return;}// 如果是原色链接,跳过渲染但修改牌子if (parent.tagName === 'A' && isOriginalColor(parent)) {skippedOriginal++;// 仍然尝试修改牌子const modified = modifyBadge(parent);if (modified) badgeModified++;return;}// 正常高亮if (parent.dataset.highlighted === 'true') return;if (parent.tagName === 'A') {parent.style.color = targetColor;parent.style.fontWeight = 'bold';parent.style.setProperty('color', targetColor, 'important');parent.dataset.highlighted = 'true';count++;console.log(`[文字高亮] ✅ 高亮链接: "${textNode.textContent.trim()}"`);// 修改旁边的牌子const modified = modifyBadge(parent);if (modified) badgeModified++;} else {const span = document.createElement('span');span.style.color = targetColor;span.style.fontWeight = 'bold';5 行未改动console.log(`[文字高亮] ✅ 高亮文字: "${textNode.textContent.trim()}"`);}});console.log(`[文字高亮] 结果: 高亮 ${count} 个,跳过 ${skippedBigUser} 个(大用户名),跳过 ${skippedOriginal} 个(原色链接),修改 ${badgeModified} 个牌子`);return count;}// 清除高亮标记67 行未改动setTimeout(runHighlight, 500);};console.log('[文字高亮] 脚本已启动');})();```