版本比较
洛谷题目难度自定义脚本
标题
增加 1 行删除 1 行
1洛谷题目难度自定义(稳定版)1洛谷题目难度自定义脚本
正文
增加 1497 行删除 229 行
12345678910114 行未改动161718192021222324252627282930313233343536373821 行未改动606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892906 行未改动297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471```// ==UserScript==// @name 洛谷题目难度自定义(稳定版)// @namespace http://tampermonkey.net/// @version 8.2// @description 自定义洛谷题目难度图标,稳定可靠// @author You// @match https://www.luogu.com.cn/*// @match https://luogu.com.cn/*// @grant GM_getValue// @grant GM_setValue4 行未改动(function() {'use strict';// 默认配置const defaultConfig = {'入门': { type: 'text', value: '🔰入门', color: '#3498db' },'普及-': { type: 'text', value: '📘普及-', color: '#2ecc71' },'普及/提高-': { type: 'text', value: '📗普及/提高-', color: '#f1c40f' },'普及+/提高': { type: 'text', value: '📒普及+/提高', color: '#f39c12' },'提高+/省选-': { type: 'text', value: '📙提高+/省选-', color: '#e67e22' },'省选/NOI-': { type: 'text', value: '📕省选/NOI-', color: '#e74c3c' },'NOI/NOI+/CTSC': { type: 'text', value: '💎NOI/NOI+/CTSC', color: '#9b59b6' },'暂无评定': { type: 'text', value: '❓暂无评定', color: '#95a5a6' }};// 加载配置let config = GM_getValue('luogu_difficulty_config', defaultConfig);// 添加样式GM_addStyle(`/* 自定义难度标签样式 */.luogu-custom-difficulty {21 行未改动margin: 0 !important;display: inline-block !important;}/* 设置面板样式 */#luogu-settings-panel {position: fixed !important;top: 50% !important;left: 50% !important;transform: translate(-50%, -50%) !important;background: white !important;padding: 20px !important;border-radius: 8px !important;box-shadow: 0 0 20px rgba(0,0,0,0.3) !important;z-index: 10000 !important;width: 500px !important;max-width: 90vw !important;max-height: 80vh !important;overflow-y: auto !important;}.luogu-settings-overlay {position: fixed !important;top: 0 !important;left: 0 !important;right: 0 !important;bottom: 0 !important;background: rgba(0,0,0,0.5) !important;z-index: 9999 !important;}.luogu-refresh-btn {position: fixed !important;bottom: 15px !important;right: 15px !important;padding: 6px 12px !important;background: #4CAF50 !important;color: white !important;border: none !important;border-radius: 4px !important;cursor: pointer !important;font-size: 12px !important;z-index: 1000 !important;font-weight: bold !important;}`);// 注册菜单命令GM_registerMenuCommand('自定义难度显示', showSettings);// 标准化难度文本function normalizeDifficultyText(text) {if (!text) return '';// 移除空白字符text = text.replace(/\s+/g, '');// 将Unicode减号转换为普通减号text = text.replace(/[\u2212]/g, '-');return text;}// 获取难度等级function getDifficultyLevel(text) {const normalized = normalizeDifficultyText(text);const difficulties = ['入门', '普及-', '普及/提高-', '普及+/提高','提高+/省选-', '省选/NOI-', 'NOI/NOI+/CTSC', '暂无评定'];for (const diff of difficulties) {if (normalized === normalizeDifficultyText(diff)) {return diff;}}return null;}// 查找难度元素 - 简化版function findDifficultyElements() {const elements = [];// 1. 题目列表页的难度标签const difficultySpans = document.querySelectorAll('.difficulty');difficultySpans.forEach(el => {if (!el.classList.contains('luogu-processed')) {elements.push(el);}});// 2. 包含难度文本的spanconst allSpans = document.querySelectorAll('span');allSpans.forEach(span => {if (span.classList.contains('luogu-processed')) return;const text = span.textContent.trim();const difficulty = getDifficultyLevel(text);if (difficulty) {// 检查是否有背景色或特定类名,避免误匹配const style = span.getAttribute('style') || '';const className = span.className || '';if (style.includes('background-color') ||className.includes('lcolor--') ||span.parentElement?.classList?.contains('difficulty') ||span.closest('a[href*="difficulty"]')) {elements.push(span);}}});// 3. 包含难度文本的a标签const allLinks = document.querySelectorAll('a');allLinks.forEach(link => {if (link.classList.contains('luogu-processed')) return;const text = link.textContent.trim();const difficulty = getDifficultyLevel(text);if (difficulty && link.href.includes('difficulty')) {elements.push(link);}});// 去重return [...new Set(elements)];}// 获取对比色function getContrastColor(hexColor) {if (!hexColor) return '#ffffff';hexColor = hexColor.replace('#', '');if (hexColor.length === 3) {hexColor = hexColor.split('').map(c => c + c).join('');}try {const r = parseInt(hexColor.substr(0, 2), 16);const g = parseInt(hexColor.substr(2, 2), 16);const b = parseInt(hexColor.substr(4, 2), 16);const brightness = (r * 299 + g * 587 + b * 114) / 1000;return brightness > 128 ? '#000000' : '#ffffff';} catch (e) {return '#ffffff';}}// 替换难度元素function replaceDifficultyElement(element) {const text = element.textContent.trim();const difficulty = getDifficultyLevel(text);if (!difficulty) return false;const configItem = config[difficulty];if (!configItem) return false;try {// 标记为已处理element.classList.add('luogu-processed');// 保存原始内容element.setAttribute('data-luogu-original', element.innerHTML);// 清空内容element.innerHTML = '';// 清除样式element.style.cssText = '';element.style.display = 'inline-block';element.style.verticalAlign = 'middle';// 创建新内容if (configItem.type === 'image' && configItem.value) {// 图片模式const img = document.createElement('img');img.src = configItem.value;img.alt = difficulty;img.title = difficulty;img.className = 'luogu-custom-img';element.appendChild(img);} else {// 文字模式const span = document.createElement('span');span.textContent = configItem.value || difficulty;span.className = 'luogu-custom-difficulty';span.style.backgroundColor = configItem.color;span.style.color = getContrastColor(configItem.color);element.appendChild(span);}return true;} catch (error) {console.error('替换难度元素出错:', error);return false;}}// 恢复难度元素function restoreDifficultyElement(element) {const original = element.getAttribute('data-luogu-original');if (original) {element.innerHTML = original;}element.classList.remove('luogu-processed');element.removeAttribute('data-luogu-original');element.style.cssText = '';}// 主处理函数function processAllDifficulties() {console.log('开始处理难度标签...');// 查找所有难度元素const elements = findDifficultyElements();console.log(`找到 ${elements.length} 个难度元素`);if (elements.length === 0) {// 如果没有找到,稍后再试一次setTimeout(processAllDifficulties, 1000);return;}// 处理每个元素6 行未改动console.log(`成功处理 ${processedCount} 个难度标签`);}// 强制刷新function forceRefresh() {// 恢复所有已处理的元素const processedElements = document.querySelectorAll('.luogu-processed');processedElements.forEach(restoreDifficultyElement);// 重新处理setTimeout(processAllDifficulties, 100);}// 添加刷新按钮function addRefreshButton() {// 移除已存在的按钮const existingBtn = document.querySelector('.luogu-refresh-btn');if (existingBtn) existingBtn.remove();// 创建新按钮const btn = document.createElement('button');btn.className = 'luogu-refresh-btn';btn.textContent = '🔄 刷新难度显示';btn.onclick = forceRefresh;document.body.appendChild(btn);}// 显示设置面板function showSettings() {// 移除已存在的面板const oldOverlay = document.querySelector('.luogu-settings-overlay');const oldPanel = document.querySelector('#luogu-settings-panel');if (oldOverlay) oldOverlay.remove();if (oldPanel) oldPanel.remove();// 创建遮罩层const overlay = document.createElement('div');overlay.className = 'luogu-settings-overlay';// 创建面板const panel = document.createElement('div');panel.id = 'luogu-settings-panel';// 构建设置内容let html = '<h2 style="margin-top:0">洛谷难度自定义设置</h2>';html += '<p>为每个难度等级设置自定义显示:</p>';html += '<div style="max-height:400px;overflow-y:auto">';const difficulties = Object.keys(defaultConfig);difficulties.forEach(diff => {const configItem = config[diff] || defaultConfig[diff];html += `<div style="margin-bottom:10px;padding:10px;border:1px solid #ddd;border-radius:5px"><div style="font-weight:bold;margin-bottom:5px">${diff}</div><div><select style="margin-right:10px" data-diff="${diff}"><option value="text" ${configItem.type === 'text' ? 'selected' : ''}>文字</option><option value="image" ${configItem.type === 'image' ? 'selected' : ''}>图片</option></select><input type="text" data-diff="${diff}" value="${configItem.value || ''}"placeholder="${configItem.type === 'text' ? '输入文字' : '输入图片URL'}"style="width:200px;margin-right:10px">${configItem.type === 'text' ?`<input type="color" data-diff="${diff}" value="${configItem.color}" style="vertical-align:middle">` : ''}</div></div>`;});html += '</div>';html += `<div style="margin-top:15px;text-align:right"><button id="luogu-save" style="margin-right:10px">保存</button><button id="luogu-reset">恢复默认</button><button id="luogu-close" style="margin-left:10px">关闭</button></div>`;panel.innerHTML = html;// 添加到页面document.body.appendChild(overlay);document.body.appendChild(panel);// 事件处理panel.querySelectorAll('select').forEach(select => {select.addEventListener('change', function() {const diff = this.getAttribute('data-diff');const input = panel.querySelector(`input[type="text"][data-diff="${diff}"]`);input.placeholder = this.value === 'image' ? '输入图片URL' : '输入文字';});});panel.querySelector('#luogu-save').addEventListener('click', function() {const newConfig = {};difficulties.forEach(diff => {const select = panel.querySelector(`select[data-diff="${diff}"]`);const input = panel.querySelector(`input[type="text"][data-diff="${diff}"]`);const colorInput = panel.querySelector(`input[type="color"][data-diff="${diff}"]`);if (select && input) {const type = select.value;const value = input.value.trim();const color = colorInput ? colorInput.value : undefined;newConfig[diff] = {type: type,value: value || defaultConfig[diff].value,color: type === 'text' ? (color || defaultConfig[diff].color) : undefined};}});GM_setValue('luogu_difficulty_config', newConfig);config = newConfig;forceRefresh();alert('设置已保存!');overlay.remove();panel.remove();});panel.querySelector('#luogu-reset').addEventListener('click', function() {if (confirm('恢复默认设置?')) {GM_setValue('luogu_difficulty_config', defaultConfig);config = defaultConfig;forceRefresh();alert('已恢复默认');overlay.remove();panel.remove();}});panel.querySelector('#luogu-close').addEventListener('click', function() {overlay.remove();panel.remove();});overlay.addEventListener('click', function() {overlay.remove();panel.remove();});}// 初始化function init() {console.log('洛谷难度自定义脚本启动');// 初始处理setTimeout(() => {processAllDifficulties();addRefreshButton();}, 2000);// 监听DOM变化const observer = new MutationObserver(() => {// 延迟处理,避免频繁执行setTimeout(processAllDifficulties, 500);});observer.observe(document.body, {childList: true,subtree: true});}// 启动if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', init);} else {setTimeout(init, 1000);}})();```12345678910111213141516171819202122232425262728294 行未改动34353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719821 行未改动2202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049056 行未改动91291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739我看了许多优化,可以让洛谷更美丽,比如氧洛谷,或是[洛谷提交优化](https://www.luogu.com.cn/article/xscqjzbk),对于我这个喜爱后室的人来说,这些可以帮我体验后室风格的洛谷。我用氧洛谷将背景改为了后室层级 level 0,提交记录改成了别的层级,让洛谷更具有后室味。但,我总觉得还是少了点什么。可到底少了什么呢?我想啊想,终于,我想到了,对啊,后室那么多个层级是有生存等级的,洛谷的这些难度显然对不上,没感觉,所以,我决定,在 Deepseek 的帮助下,以及其他机房成员的辅助下,我们成功制造出了一个难度主题管理器脚本,用法还是直接放入篡改猴。脚本启动后,我们要刷新页面,接着,右下角会出现几个选项,点击管理,即可选择难度的主题,很好操作。同时,我们不只搞了后室,我们还搞了 SCP,对于 SCP 了解较深的可以使用,否则我怕你看不懂难易程度,当然,你也可以现场记忆下来。同时,大家也可以自定义主题,选择颜色,文字或者可以放上图片。让洛谷变得更美好不过脚本有个缺陷,每到一个新的页面,我们都需要刷新,这是一个小缺点,不过习惯就好。欢迎大家尝试同时提出更改意见,希望这个脚本可以发展的越来越好。```// ==UserScript==// @name 洛谷难度主题管理器 v10.3// @namespace http://tampermonkey.net/// @version 10.3// @description 自定义洛谷题目难度图标,支持多主题创建、切换和保存,新增后室和SCP主题// @author 鸡腿,PCY和祥子// @match https://www.luogu.com.cn/*// @match https://luogu.com.cn/*// @grant GM_getValue// @grant GM_setValue4 行未改动(function() {'use strict';// 后室主题图片URLconst BACKROOMS_IMAGES = {'暂无评定': 'https://cdn.luogu.com.cn/upload/image_hosting/k83scvdj.png','入门': 'https://cdn.luogu.com.cn/upload/image_hosting/3pkufhwg.png','普及-': 'https://cdn.luogu.com.cn/upload/image_hosting/bnpb43dd.png','普及/提高-': 'https://cdn.luogu.com.cn/upload/image_hosting/dkj0la0b.png','普及+/提高': 'https://cdn.luogu.com.cn/upload/image_hosting/w6fakokc.png','提高+/省选-': 'https://cdn.luogu.com.cn/upload/image_hosting/95438ck0.png','省选/NOI-': 'https://cdn.luogu.com.cn/upload/image_hosting/0pzb08o8.png','NOI/NOI+/CTSC': 'https://cdn.luogu.com.cn/upload/image_hosting/i21hupri.png'};// 默认主题配置const DEFAULT_THEMES = {'经典图标主题': {name: '经典图标主题',created: new Date().toISOString(),updated: new Date().toISOString(),config: {'入门': { type: 'text', value: '🔰入门', color: '#3498db' },'普及-': { type: 'text', value: '📘普及-', color: '#2ecc71' },'普及/提高-': { type: 'text', value: '📗普及/提高-', color: '#f1c40f' },'普及+/提高': { type: 'text', value: '📒普及+/提高', color: '#f39c12' },'提高+/省选-': { type: 'text', value: '📙提高+/省选-', color: '#e67e22' },'省选/NOI-': { type: 'text', value: '📕省选/NOI-', color: '#e74c3c' },'NOI/NOI+/CTSC': { type: 'text', value: '💎NOI/NOI+/CTSC', color: '#9b59b6' },'暂无评定': { type: 'text', value: '❓暂无评定', color: '#95a5a6' }}},'简约文字主题': {name: '简约文字主题',created: new Date().toISOString(),updated: new Date().toISOString(),config: {'入门': { type: 'text', value: '入门', color: '#3498db' },'普及-': { type: 'text', value: '普及-', color: '#2ecc71' },'普及/提高-': { type: 'text', value: '普及/提高-', color: '#f1c40f' },'普及+/提高': { type: 'text', value: '普及+/提高', color: '#f39c12' },'提高+/省选-': { type: 'text', value: '提高+/省选-', color: '#e67e22' },'省选/NOI-': { type: 'text', value: '省选/NOI-', color: '#e74c3c' },'NOI/NOI+/CTSC': { type: 'text', value: 'NOI/NOI+/CTSC', color: '#9b59b6' },'暂无评定': { type: 'text', value: '暂无评定', color: '#95a5a6' }}},'Emoji主题': {name: 'Emoji主题',created: new Date().toISOString(),updated: new Date().toISOString(),config: {'入门': { type: 'text', value: '🐣入门', color: '#3498db' },'普及-': { type: 'text', value: '📚普及-', color: '#2ecc71' },'普及/提高-': { type: 'text', value: '📖普及/提高-', color: '#f1c40f' },'普及+/提高': { type: 'text', value: '📝普及+/提高', color: '#f39c12' },'提高+/省选-': { type: 'text', value: '🏆提高+/省选-', color: '#e67e22' },'省选/NOI-': { type: 'text', value: '🎯省选/NOI-', color: '#e74c3c' },'NOI/NOI+/CTSC': { type: 'text', value: '👑NOI/NOI+/CTSC', color: '#9b59b6' },'暂无评定': { type: 'text', value: '❓暂无评定', color: '#95a5a6' }}},'后室主题': {name: '后室主题',created: new Date().toISOString(),updated: new Date().toISOString(),config: {'入门': { type: 'image', value: BACKROOMS_IMAGES['入门'], color: '#3498db' },'普及-': { type: 'image', value: BACKROOMS_IMAGES['普及-'], color: '#2ecc71' },'普及/提高-': { type: 'image', value: BACKROOMS_IMAGES['普及/提高-'], color: '#f1c40f' },'普及+/提高': { type: 'image', value: BACKROOMS_IMAGES['普及+/提高'], color: '#f39c12' },'提高+/省选-': { type: 'image', value: BACKROOMS_IMAGES['提高+/省选-'], color: '#e67e22' },'省选/NOI-': { type: 'image', value: BACKROOMS_IMAGES['省选/NOI-'], color: '#e74c3c' },'NOI/NOI+/CTSC': { type: 'image', value: BACKROOMS_IMAGES['NOI/NOI+/CTSC'], color: '#9b59b6' },'暂无评定': { type: 'image', value: BACKROOMS_IMAGES['暂无评定'], color: '#95a5a6' }}},'SCP主题': {name: 'SCP主题',created: new Date().toISOString(),updated: new Date().toISOString(),config: {'入门': { type: 'text', value: 'Explained', color: '#ffffff' },'普及-': { type: 'text', value: 'Safe', color: '#2ecc71' },'普及/提高-': { type: 'text', value: 'Euclid', color: '#f1c40f' },'普及+/提高': { type: 'text', value: 'Keter', color: '#e74c3c' },'提高+/省选-': { type: 'text', value: 'Thaumiel', color: '#9b59b6' },'省选/NOI-': { type: 'text', value: 'Archon', color: '#3498db' },'NOI/NOI+/CTSC': { type: 'text', value: 'Apollyon', color: '#000000' },'暂无评定': { type: 'text', value: 'Pending', color: '#95a5a6' }}}};// 难度等级列表const DIFFICULTIES = ['入门', '普及-', '普及/提高-', '普及+/提高','提高+/省选-', '省选/NOI-', 'NOI/NOI+/CTSC', '暂无评定'];// 存储结构let storage = {themes: {},currentTheme: '',settings: {autoRefresh: true,showRefreshButton: true}};// 加载存储数据function loadStorage() {try {const saved = GM_getValue('luogu_difficulty_storage');if (saved && saved.themes && Object.keys(saved.themes).length > 0) {storage = saved;console.log('已加载主题存储数据');return true;}} catch (e) {console.error('加载存储数据失败:', e);}// 初始化为默认主题storage.themes = JSON.parse(JSON.stringify(DEFAULT_THEMES));storage.currentTheme = '经典图标主题';saveStorage();console.log('使用默认主题数据');return false;}// 保存存储数据function saveStorage() {try {GM_setValue('luogu_difficulty_storage', storage);console.log('存储数据已保存');return true;} catch (e) {console.error('保存存储数据失败:', e);return false;}}// 获取当前主题配置function getCurrentConfig() {const theme = storage.themes[storage.currentTheme];return theme ? theme.config : DEFAULT_THEMES['经典图标主题'].config;}// 更新当前主题配置function updateCurrentConfig(config) {if (storage.themes[storage.currentTheme]) {storage.themes[storage.currentTheme].config = config;storage.themes[storage.currentTheme].updated = new Date().toISOString();saveStorage();return true;}return false;}// 添加样式GM_addStyle(`/* 自定义难度标签样式 */.luogu-custom-difficulty {21 行未改动margin: 0 !important;display: inline-block !important;}/* 后室主题图片放大样式 - 用于题目背景之上 */.luogu-backrooms-enlarged {max-width: 200px !important;max-height: 200px !important;width: auto !important;height: auto !important;display: block !important;margin: 10px auto !important;border: 2px solid #666 !important;border-radius: 8px !important;box-shadow: 0 4px 8px rgba(0,0,0,0.3) !important;}/* 后室主题标题样式 */.luogu-backrooms-title {font-size: 20px !important;font-weight: bold !important;text-align: center !important;color: #333 !important;margin: 15px 0 10px 0 !important;padding-bottom: 8px !important;border-bottom: 2px solid #3498db !important;}/* SCP主题特殊文字样式 */.luogu-scp-text {font-family: 'Courier New', monospace !important;font-weight: bold !important;letter-spacing: 1px !important;text-transform: uppercase !important;}/* 设置面板样式 */#luogu-main-panel {position: fixed !important;top: 50% !important;left: 50% !important;transform: translate(-50%, -50%) !important;background: white !important;padding: 20px !important;border-radius: 8px !important;box-shadow: 0 0 20px rgba(0,0,0,0.3) !important;z-index: 10000 !important;width: 800px !important;max-width: 95vw !important;max-height: 90vh !important;overflow: hidden !important;}.luogu-panel-overlay {position: fixed !important;top: 0 !important;left: 0 !important;right: 0 !important;bottom: 0 !important;background: rgba(0,0,0,0.5) !important;z-index: 9999 !important;}/* 选项卡样式 */.luogu-tabs {display: flex !important;border-bottom: 2px solid #eee !important;margin-bottom: 20px !important;}.luogu-tab {padding: 10px 20px !important;cursor: pointer !important;border: none !important;background: none !important;font-size: 14px !important;color: #666 !important;border-bottom: 2px solid transparent !important;transition: all 0.3s !important;margin-right: 5px !important;}.luogu-tab:hover {color: #2196F3 !important;}.luogu-tab.active {color: #2196F3 !important;border-bottom: 2px solid #2196F3 !important;font-weight: bold !important;}/* 主题管理样式 */.luogu-themes-list {max-height: 300px !important;overflow-y: auto !important;margin-bottom: 20px !important;border: 1px solid #eee !important;border-radius: 5px !important;}.luogu-theme-item {padding: 12px 15px !important;border-bottom: 1px solid #f0f0f0 !important;display: flex !important;justify-content: space-between !important;align-items: center !important;transition: background 0.3s !important;}.luogu-theme-item:hover {background: #f9f9f9 !important;}.luogu-theme-item.current {background: #e3f2fd !important;border-left: 4px solid #2196F3 !important;}.luogu-theme-info {flex: 1 !important;}.luogu-theme-name {font-weight: bold !important;color: #333 !important;margin-bottom: 3px !important;}.luogu-theme-meta {font-size: 12px !important;color: #888 !important;}.luogu-theme-actions {display: flex !important;gap: 5px !important;}.luogu-action-btn {padding: 5px 10px !important;border: none !important;border-radius: 3px !important;cursor: pointer !important;font-size: 12px !important;}.luogu-action-btn.apply {background: #4CAF50 !important;color: white !important;}.luogu-action-btn.delete {background: #f44336 !important;color: white !important;}.luogu-action-btn.rename {background: #ff9800 !important;color: white !important;}/* 主题编辑样式 */.luogu-difficulty-editor {display: grid !important;grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)) !important;gap: 15px !important;max-height: 400px !important;overflow-y: auto !important;padding: 10px !important;}.luogu-difficulty-item {padding: 15px !important;border: 1px solid #ddd !important;border-radius: 5px !important;background: #f9f9f9 !important;}.luogu-difficulty-header {font-weight: bold !important;color: #333 !important;margin-bottom: 10px !important;padding-bottom: 5px !important;border-bottom: 1px solid #eee !important;}.luogu-option-group {display: flex !important;align-items: center !important;gap: 10px !important;margin-bottom: 8px !important;flex-wrap: wrap !important;}.luogu-option-label {min-width: 60px !important;font-size: 13px !important;}.luogu-option-input {flex: 1 !important;min-width: 200px !important;padding: 6px !important;border: 1px solid #ddd !important;border-radius: 3px !important;}.luogu-color-input {width: 50px !important;height: 30px !important;cursor: pointer !important;}/* 按钮样式 */.luogu-panel-btn {padding: 8px 15px !important;border: none !important;border-radius: 4px !important;cursor: pointer !important;font-weight: bold !important;margin-left: 5px !important;}.luogu-panel-btn.primary {background: #2196F3 !important;color: white !important;}.luogu-panel-btn.success {background: #4CAF50 !important;color: white !important;}.luogu-panel-btn.danger {background: #f44336 !important;color: white !important;}.luogu-panel-btn.secondary {background: #9e9e9e !important;color: white !important;}.luogu-panel-footer {margin-top: 20px !important;padding-top: 15px !important;border-top: 1px solid #eee !important;text-align: right !important;}/* 快速切换菜单 */.luogu-quick-menu {position: fixed !important;bottom: 15px !important;right: 15px !important;display: flex !important;gap: 5px !important;z-index: 1000 !important;}.luogu-quick-btn {padding: 6px 12px !important;background: #2196F3 !important;color: white !important;border: none !important;border-radius: 4px !important;cursor: pointer !important;font-size: 12px !important;font-weight: bold !important;}.luogu-quick-btn.theme-switch {background: #9c27b0 !important;}.luogu-quick-btn.reprocess {background: #ff9800 !important;}.luogu-quick-btn:hover {opacity: 0.9 !important;}/* 模态框样式 */.luogu-modal {position: fixed !important;top: 50% !important;left: 50% !important;transform: translate(-50%, -50%) !important;background: white !important;padding: 20px !important;border-radius: 8px !important;box-shadow: 0 0 20px rgba(0,0,0,0.3) !important;z-index: 10001 !important;min-width: 300px !important;}.luogu-modal-title {font-size: 18px !important;font-weight: bold !important;margin-bottom: 15px !important;color: #333 !important;}.luogu-modal-input {width: 100% !important;padding: 8px !important;margin-bottom: 15px !important;border: 1px solid #ddd !important;border-radius: 4px !important;box-sizing: border-box !important;}.luogu-modal-footer {text-align: right !important;margin-top: 20px !important;}/* 全屏刷新遮罩 */.luogu-refresh-overlay {position: fixed !important;top: 0 !important;left: 0 !important;right: 0 !important;bottom: 0 !important;background: rgba(0, 0, 0, 0.8) !important;z-index: 100000 !important;display: flex !important;justify-content: center !important;align-items: center !important;color: white !important;font-size: 24px !important;flex-direction: column !important;}.luogu-refresh-overlay span {margin-bottom: 20px !important;text-align: center !important;}`);// 注册菜单命令GM_registerMenuCommand('主题管理器', showThemeManager);GM_registerMenuCommand('快速切换主题', showQuickSwitch);GM_registerMenuCommand('编辑当前主题', showThemeEditor);GM_registerMenuCommand('重新处理难度标签', () => {processAllDifficulties();alert('已重新处理当前页面的难度标签');});GM_registerMenuCommand('刷新页面', fullRefreshPage);// 所有可能的颜色类名const COLOR_CLASSES = ['lcolor--grey-3', // 暂无评定'lcolor--pink-3', // 入门'lcolor--orange-3', // 普及-'lcolor--gold-3', // 普及/提高-'lcolor--green-3', // 普及+/提高'lcolor--blue-3', // 提高+/省选-'lcolor--purple-3', // 省选/NOI-'lcolor--lapis-4', // NOI/NOI+/CTSC'lcolor--red-3','lcolor--yellow-3','lcolor--black-3'];// 获取对比色function getContrastColor(hexColor) {if (!hexColor) return '#ffffff';hexColor = hexColor.replace('#', '');if (hexColor.length === 3) {hexColor = hexColor.split('').map(c => c + c).join('');}try {const r = parseInt(hexColor.substr(0, 2), 16);const g = parseInt(hexColor.substr(2, 2), 16);const b = parseInt(hexColor.substr(4, 2), 16);return (r * 299 + g * 587 + b * 114) / 1000 > 128 ? '#000000' : '#ffffff';} catch (e) {return '#ffffff';}}// 标准化难度文本function normalizeDifficultyText(text) {if (!text) return '';text = text.replace(/\s+/g, '');text = text.replace(/[\u2212\u2013\u2014]/g, '-');text = text.replace(/[\uFF0D\uFE63\u2212]/g, '-');return text;}// 获取难度等级function getDifficultyLevel(text) {const normalized = normalizeDifficultyText(text);for (const diff of DIFFICULTIES) {const normalizedDiff = normalizeDifficultyText(diff);if (normalized === normalizedDiff) {return diff;}}return null;}// 判断是否为题目页面function isProblemPage() {return window.location.pathname.includes('/problem/');}// 判断是否为题目背景之上的难度元素function isProblemHeaderDifficulty(element) {// 检查元素是否在题目标题附近const problemTitle = document.querySelector('.header .title, .problem-title, h1');if (!problemTitle) return false;// 检查元素是否在标题附近const rect1 = element.getBoundingClientRect();const rect2 = problemTitle.getBoundingClientRect();// 判断两个元素是否在垂直方向上相近const verticalDistance = Math.abs(rect1.top - rect2.top);return verticalDistance < 100; // 在100像素范围内视为标题附近的元素}// 查找难度元素function findDifficultyElements() {const elements = new Set();// 方法1: 专门处理.difficulty-tags结构const difficultyTags = document.querySelectorAll('.difficulty-tags .row span:not(.problem-count)');difficultyTags.forEach(el => {if (!el.classList.contains('luogu-processed')) {const text = el.textContent.trim();if (text && getDifficultyLevel(text)) {elements.add(el);}}});// 方法2: 通过颜色类名查找COLOR_CLASSES.forEach(className => {try {document.querySelectorAll(`.${className}`).forEach(el => {if (!el.classList.contains('luogu-processed')) {elements.add(el);}});} catch (e) {}});// 方法3: 通过常见选择器查找const selectors = ['.difficulty','.tag.difficulty','span.difficulty','a[href*="difficulty"]','span[class*="difficulty"]','.problem-tags span','.am-badge'];selectors.forEach(selector => {try {document.querySelectorAll(selector).forEach(el => {const text = el.textContent.trim();if (text && getDifficultyLevel(text) && !el.classList.contains('luogu-processed')) {elements.add(el);}});} catch (e) {}});return Array.from(elements);}// 替换难度元素 - 增强版,支持后室主题的特殊显示function replaceDifficultyElement(element) {// 获取难度文本let difficultyText = element.textContent.trim();// 获取难度等级const difficulty = getDifficultyLevel(difficultyText);if (!difficulty) {return false;}// 获取当前主题配置const config = getCurrentConfig();const configItem = config[difficulty];if (!configItem) {return false;}try {// 标记为已处理element.classList.add('luogu-processed');// 保存原始内容const originalHTML = element.innerHTML;const originalStyle = element.getAttribute('style');element.setAttribute('data-luogu-original', originalHTML);if (originalStyle) {element.setAttribute('data-luogu-original-style', originalStyle);}// 保存problem-count兄弟元素(如果有)const parent = element.parentElement;let problemCountElement = null;if (parent && parent.classList.contains('row')) {const problemCount = parent.querySelector('.problem-count');if (problemCount) {problemCountElement = problemCount.cloneNode(true);element.setAttribute('data-luogu-problem-count', problemCount.outerHTML);}}// 清空内容element.innerHTML = '';// 清除样式const currentStyle = window.getComputedStyle(element);element.style.cssText = '';// 恢复必要的布局样式element.style.display = currentStyle.display;element.style.verticalAlign = 'middle';element.style.margin = '0';element.style.padding = '0';element.style.border = 'none';element.style.boxShadow = 'none';element.style.backgroundColor = 'transparent';// 检查是否为后室主题且在题目背景之上const isBackroomsTheme = storage.currentTheme === '后室主题';const isProblemHeader = isProblemPage() && isProblemHeaderDifficulty(element);if (isBackroomsTheme && isProblemHeader) {// 后室主题在题目背景之上的特殊显示const container = document.createElement('div');container.style.textAlign = 'center';container.style.margin = '10px 0';// 添加标题const title = document.createElement('div');title.className = 'luogu-backrooms-title';title.textContent = difficulty;container.appendChild(title);// 添加放大图片const img = document.createElement('img');img.src = configItem.value || BACKROOMS_IMAGES[difficulty] || '';img.alt = difficulty;img.title = difficulty;img.className = 'luogu-backrooms-enlarged';container.appendChild(img);element.appendChild(container);element.style.display = 'block';element.style.textAlign = 'center';} else if (configItem.type === 'image' && configItem.value) {// 图片模式const img = document.createElement('img');img.src = configItem.value;img.alt = difficulty;img.title = difficulty;img.className = 'luogu-custom-img';img.style.display = 'inline-block';img.style.verticalAlign = 'middle';// 如果是SCP主题,不应用图片if (storage.currentTheme === 'SCP主题') {console.log('SCP主题使用文字模式,忽略图片配置');// 回退到文字模式createTextElement(element, difficulty, configItem);} else {element.appendChild(img);}} else {// 文字模式createTextElement(element, difficulty, configItem);}// 恢复problem-count元素if (problemCountElement && parent && parent.classList.contains('row')) {const existingProblemCount = parent.querySelector('.problem-count');if (existingProblemCount) {existingProblemCount.style.display = 'inline';} else {parent.appendChild(problemCountElement);}}return true;} catch (error) {console.error('替换难度元素出错:', error);try {const original = element.getAttribute('data-luogu-original');if (original) {element.innerHTML = original;}element.classList.remove('luogu-processed');} catch (e) {}return false;}}// 创建文字元素function createTextElement(element, difficulty, configItem) {const span = document.createElement('span');span.textContent = configItem.value || difficulty;span.className = 'luogu-custom-difficulty';// SCP主题特殊样式if (storage.currentTheme === 'SCP主题') {span.classList.add('luogu-scp-text');}span.style.backgroundColor = configItem.color;span.style.color = getContrastColor(configItem.color);// 保持原有的内联样式if (element.hasAttribute('data-luogu-original-style')) {const originalStyleText = element.getAttribute('data-luogu-original-style');if (originalStyleText && originalStyleText.includes('border-color')) {span.style.border = '1px solid ' + configItem.color;}}element.appendChild(span);}// 恢复所有已处理的元素function restoreAllProcessedElements() {const processedElements = document.querySelectorAll('.luogu-processed');processedElements.forEach(element => {const original = element.getAttribute('data-luogu-original');const originalStyle = element.getAttribute('data-luogu-original-style');if (original) {element.innerHTML = original;}if (originalStyle) {element.setAttribute('style', originalStyle);}element.classList.remove('luogu-processed');element.removeAttribute('data-luogu-original');element.removeAttribute('data-luogu-original-style');// 恢复problem-count显示const parent = element.parentElement;if (parent && parent.classList.contains('row')) {const problemCount = parent.querySelector('.problem-count');if (problemCount) {problemCount.style.display = 'inline';}}});}// 处理所有难度元素function processAllDifficulties() {console.log('开始处理难度标签...当前主题:', storage.currentTheme);// 恢复所有已处理的元素restoreAllProcessedElements();// 查找所有难度元素const elements = findDifficultyElements();if (elements.length === 0) {console.log('没有找到难度元素,稍后重试');setTimeout(processAllDifficulties, 2000);return;}// 处理每个元素6 行未改动console.log(`成功处理 ${processedCount} 个难度标签`);}// 全屏刷新页面function fullRefreshPage() {// 创建全屏遮罩const overlay = document.createElement('div');overlay.className = 'luogu-refresh-overlay';const message = document.createElement('span');message.textContent = '正在应用主题更改,刷新页面...';overlay.appendChild(message);document.body.appendChild(overlay);// 保存当前主题到本地存储saveStorage();// 等待一下让用户看到消息setTimeout(() => {location.reload();}, 1500);}// 添加快速切换菜单function addQuickMenu() {// 移除已存在的菜单const existingMenu = document.querySelector('.luogu-quick-menu');if (existingMenu) existingMenu.remove();// 创建菜单容器const menu = document.createElement('div');menu.className = 'luogu-quick-menu';// 主题切换按钮const themeBtn = document.createElement('button');themeBtn.className = 'luogu-quick-btn theme-switch';themeBtn.textContent = `主题: ${storage.currentTheme}`;themeBtn.title = '点击切换主题';themeBtn.addEventListener('click', showQuickSwitch);// 重新处理按钮const reprocessBtn = document.createElement('button');reprocessBtn.className = 'luogu-quick-btn reprocess';reprocessBtn.textContent = '🔄 重处理';reprocessBtn.title = '重新处理当前页面的难度标签';reprocessBtn.addEventListener('click', () => {reprocessBtn.textContent = '处理中...';reprocessBtn.disabled = true;setTimeout(() => {processAllDifficulties();reprocessBtn.textContent = '🔄 重处理';reprocessBtn.disabled = false;}, 300);});// 刷新页面按钮const refreshBtn = document.createElement('button');refreshBtn.className = 'luogu-quick-btn';refreshBtn.textContent = '♻️ 刷新';refreshBtn.title = '刷新整个页面';refreshBtn.addEventListener('click', fullRefreshPage);// 管理按钮const manageBtn = document.createElement('button');manageBtn.className = 'luogu-quick-btn';manageBtn.textContent = '⚙️ 管理';manageBtn.title = '打开主题管理器';manageBtn.addEventListener('click', showThemeManager);menu.appendChild(themeBtn);menu.appendChild(reprocessBtn);menu.appendChild(refreshBtn);menu.appendChild(manageBtn);document.body.appendChild(menu);}// 显示主题管理器function showThemeManager() {removeExistingPanels();// 创建遮罩层const overlay = document.createElement('div');overlay.className = 'luogu-panel-overlay';// 创建主面板const panel = document.createElement('div');panel.id = 'luogu-main-panel';// 构建选项卡let html = `<div class="luogu-tabs"><button class="luogu-tab active" data-tab="themes">主题管理</button><button class="luogu-tab" data-tab="editor">主题编辑</button><button class="luogu-tab" data-tab="settings">设置</button></div><div id="luogu-tab-content" style="min-height: 400px;"></div>`;panel.innerHTML = html;// 添加到页面document.body.appendChild(overlay);document.body.appendChild(panel);// 初始化选项卡内容showTabContent('themes');// 选项卡点击事件panel.querySelectorAll('.luogu-tab').forEach(tab => {tab.addEventListener('click', function() {panel.querySelectorAll('.luogu-tab').forEach(t => t.classList.remove('active'));this.classList.add('active');showTabContent(this.getAttribute('data-tab'));});});// 点击遮罩层关闭overlay.addEventListener('click', () => {removeExistingPanels();});}// 显示选项卡内容function showTabContent(tabName) {const content = document.querySelector('#luogu-tab-content');if (!content) return;switch(tabName) {case 'themes':content.innerHTML = getThemesManagementContent();setupThemesManagementEvents();break;case 'editor':content.innerHTML = getThemeEditorContent();setupThemeEditorEvents();break;case 'settings':content.innerHTML = getSettingsContent();setupSettingsEvents();break;}}// 获取主题管理内容function getThemesManagementContent() {const themes = storage.themes;const currentTheme = storage.currentTheme;let html = `<h3 style="margin-top:0">主题管理</h3><div style="margin-bottom:15px"><button id="luogu-new-theme" class="luogu-panel-btn primary">新建主题</button><button id="luogu-duplicate-theme" class="luogu-panel-btn secondary">复制当前主题</button><button id="luogu-reprocess-btn" class="luogu-panel-btn success">重新处理标签</button><button id="luogu-full-refresh" class="luogu-panel-btn danger">刷新页面</button></div><div class="luogu-themes-list">`;Object.values(themes).forEach(theme => {const isCurrent = theme.name === currentTheme;const createdDate = new Date(theme.created).toLocaleDateString();const updatedDate = new Date(theme.updated).toLocaleDateString();html += `<div class="luogu-theme-item ${isCurrent ? 'current' : ''}" data-theme="${theme.name}"><div class="luogu-theme-info"><div class="luogu-theme-name">${theme.name}</div><div class="luogu-theme-meta">创建: ${createdDate} | 更新: ${updatedDate}</div></div><div class="luogu-theme-actions">${!isCurrent ?`<button class="luogu-action-btn apply" data-action="apply">应用</button>` :`<span style="color:#4CAF50;font-weight:bold">✓ 当前</span>`}<button class="luogu-action-btn rename" data-action="rename">重命名</button>${Object.keys(themes).length > 1 ?`<button class="luogu-action-btn delete" data-action="delete">删除</button>` :''}</div></div>`;});html += `</div><div class="luogu-panel-footer"><button id="luogu-close-panel" class="luogu-panel-btn secondary">关闭</button></div>`;return html;}// 设置主题管理事件function setupThemesManagementEvents() {const panel = document.querySelector('#luogu-main-panel');if (!panel) return;// 新建主题panel.querySelector('#luogu-new-theme')?.addEventListener('click', () => {showCreateThemeModal();});// 复制当前主题panel.querySelector('#luogu-duplicate-theme')?.addEventListener('click', () => {showDuplicateThemeModal();});// 重新处理标签panel.querySelector('#luogu-reprocess-btn')?.addEventListener('click', () => {removeExistingPanels();processAllDifficulties();alert('已重新处理难度标签');});// 刷新页面panel.querySelector('#luogu-full-refresh')?.addEventListener('click', () => {removeExistingPanels();fullRefreshPage();});// 主题操作按钮panel.querySelectorAll('.luogu-action-btn').forEach(btn => {btn.addEventListener('click', function() {const themeItem = this.closest('.luogu-theme-item');const themeName = themeItem.getAttribute('data-theme');const action = this.getAttribute('data-action');switch(action) {case 'apply':applyTheme(themeName);break;case 'rename':showRenameThemeModal(themeName);break;case 'delete':deleteTheme(themeName);break;}});});// 关闭面板panel.querySelector('#luogu-close-panel')?.addEventListener('click', () => {removeExistingPanels();});}// 获取主题编辑内容function getThemeEditorContent() {const config = getCurrentConfig();let html = `<h3 style="margin-top:0">编辑当前主题: ${storage.currentTheme}</h3><p style="color:#666;margin-bottom:15px">修改当前主题的难度显示配置</p><div class="luogu-difficulty-editor">`;DIFFICULTIES.forEach(diff => {const configItem = config[diff] || { type: 'text', value: diff, color: '#95a5a6' };html += `<div class="luogu-difficulty-item" data-difficulty="${diff}"><div class="luogu-difficulty-header">${diff}</div><div class="luogu-option-group"><span class="luogu-option-label">类型:</span><select class="luogu-option-input type-select"><option value="text" ${configItem.type === 'text' ? 'selected' : ''}>文字</option><option value="image" ${configItem.type === 'image' ? 'selected' : ''}>图片</option></select></div><div class="luogu-option-group"><span class="luogu-option-label">内容:</span><input type="text" class="luogu-option-input content-input"value="${configItem.value || diff}"placeholder="${configItem.type === 'text' ? '输入文字' : '输入图片URL'}"></div>${configItem.type === 'text' ? `<div class="luogu-option-group"><span class="luogu-option-label">颜色:</span><input type="color" class="luogu-color-input color-input"value="${configItem.color || '#95a5a6'}"></div>` : ''}</div>`;});html += `</div><div class="luogu-panel-footer"><button id="luogu-save-config" class="luogu-panel-btn success">保存更改</button><button id="luogu-reset-config" class="luogu-panel-btn secondary">重置为默认</button><button id="luogu-reprocess-btn2" class="luogu-panel-btn primary">重新处理</button><button id="luogu-full-refresh2" class="luogu-panel-btn danger">刷新页面</button><button id="luogu-close-panel2" class="luogu-panel-btn secondary">关闭</button></div>`;return html;}// 设置主题编辑事件function setupThemeEditorEvents() {const panel = document.querySelector('#luogu-main-panel');if (!panel) return;// 类型选择改变事件panel.querySelectorAll('.type-select').forEach(select => {select.addEventListener('change', function() {const item = this.closest('.luogu-difficulty-item');const colorInput = item.querySelector('.color-input');const contentInput = item.querySelector('.content-input');if (this.value === 'image') {if (colorInput) colorInput.style.display = 'none';contentInput.placeholder = '输入图片URL';} else {if (colorInput) {colorInput.style.display = 'block';colorInput.value = colorInput.value || '#95a5a6';}contentInput.placeholder = '输入文字';}});});// 保存配置panel.querySelector('#luogu-save-config')?.addEventListener('click', () => {saveThemeConfig();});// 重置配置panel.querySelector('#luogu-reset-config')?.addEventListener('click', () => {if (confirm('确定要重置当前主题的配置为默认值吗?')) {const defaultTheme = DEFAULT_THEMES[storage.currentTheme] || DEFAULT_THEMES['经典图标主题'];updateCurrentConfig(JSON.parse(JSON.stringify(defaultTheme.config)));showTabContent('editor'); // 刷新编辑器setTimeout(() => {processAllDifficulties();updateQuickMenu();}, 100);}});// 重新处理panel.querySelector('#luogu-reprocess-btn2')?.addEventListener('click', () => {removeExistingPanels();processAllDifficulties();alert('已重新处理难度标签');});// 刷新页面panel.querySelector('#luogu-full-refresh2')?.addEventListener('click', () => {removeExistingPanels();fullRefreshPage();});// 关闭面板panel.querySelector('#luogu-close-panel2')?.addEventListener('click', () => {removeExistingPanels();});}// 获取设置内容function getSettingsContent() {return `<h3 style="margin-top:0">设置</h3><div style="margin-bottom:15px"><label style="display:flex;align-items:center;margin-bottom:10px"><input type="checkbox" id="auto-refresh" ${storage.settings.autoRefresh ? 'checked' : ''}style="margin-right:8px"><span>自动刷新页面变化</span></label><label style="display:flex;align-items:center;margin-bottom:10px"><input type="checkbox" id="show-refresh-btn" ${storage.settings.showRefreshButton ? 'checked' : ''}style="margin-right:8px"><span>显示快速切换菜单</span></label></div><div class="luogu-panel-footer"><button id="luogu-save-settings" class="luogu-panel-btn success">保存设置</button><button id="luogu-close-panel3" class="luogu-panel-btn secondary">关闭</button></div>`;}// 设置设置事件function setupSettingsEvents() {const panel = document.querySelector('#luogu-main-panel');if (!panel) return;// 保存设置panel.querySelector('#luogu-save-settings')?.addEventListener('click', () => {const autoRefresh = panel.querySelector('#auto-refresh').checked;const showRefreshBtn = panel.querySelector('#show-refresh-btn').checked;storage.settings.autoRefresh = autoRefresh;storage.settings.showRefreshButton = showRefreshBtn;saveStorage();if (showRefreshBtn) {addQuickMenu();} else {const quickMenu = document.querySelector('.luogu-quick-menu');if (quickMenu) quickMenu.remove();}alert('设置已保存');});// 关闭面板panel.querySelector('#luogu-close-panel3')?.addEventListener('click', () => {removeExistingPanels();});}// 显示快速切换主题面板function showQuickSwitch() {removeExistingPanels();const overlay = document.createElement('div');overlay.className = 'luogu-panel-overlay';const modal = document.createElement('div');modal.className = 'luogu-modal';modal.innerHTML = `<div class="luogu-modal-title">快速切换主题</div><div style="max-height:300px;overflow-y:auto;margin-bottom:15px">${Object.values(storage.themes).map(theme => {const isCurrent = theme.name === storage.currentTheme;return `<div style="padding:10px;border-bottom:1px solid #eee;cursor:pointer;background:${isCurrent ? '#e3f2fd' : 'white'}"class="luogu-quick-theme" data-theme="${theme.name}"><div style="font-weight:bold">${theme.name}</div>${isCurrent ? '<div style="color:#4CAF50;font-size:12px">✓ 当前主题</div>' : ''}</div>`;}).join('')}</div><div class="luogu-modal-footer"><button id="luogu-cancel-switch" class="luogu-panel-btn secondary">取消</button></div>`;document.body.appendChild(overlay);document.body.appendChild(modal);// 主题点击事件modal.querySelectorAll('.luogu-quick-theme').forEach(item => {item.addEventListener('click', function() {const themeName = this.getAttribute('data-theme');applyTheme(themeName);removeExistingPanels();});});// 取消按钮modal.querySelector('#luogu-cancel-switch')?.addEventListener('click', () => {removeExistingPanels();});// 遮罩层点击关闭overlay.addEventListener('click', () => {removeExistingPanels();});}// 应用主题function applyTheme(themeName) {if (!storage.themes[themeName]) {alert('主题不存在');return;}storage.currentTheme = themeName;saveStorage();console.log(`已切换到主题: ${themeName}`);processAllDifficulties();updateQuickMenu();// 如果主题管理器开着,刷新它const panel = document.querySelector('#luogu-main-panel');if (panel) {showTabContent('themes');}}// 更新快速菜单function updateQuickMenu() {const themeBtn = document.querySelector('.luogu-quick-btn.theme-switch');if (themeBtn) {themeBtn.textContent = `主题: ${storage.currentTheme}`;}}// 显示创建主题模态框function showCreateThemeModal() {removeExistingPanels();const overlay = document.createElement('div');overlay.className = 'luogu-panel-overlay';const modal = document.createElement('div');modal.className = 'luogu-modal';modal.innerHTML = `<div class="luogu-modal-title">新建主题</div><input type="text" id="luogu-new-theme-name" class="luogu-modal-input"placeholder="输入主题名称" maxlength="20"><div style="margin-bottom:15px"><label style="display:block;margin-bottom:5px">基于现有主题:</label><select id="luogu-base-theme" class="luogu-modal-input"><option value="">空主题</option>${Object.values(storage.themes).map(theme =>`<option value="${theme.name}">${theme.name}</option>`).join('')}</select></div><div class="luogu-modal-footer"><button id="luogu-confirm-create" class="luogu-panel-btn success">创建</button><button id="luogu-cancel-create" class="luogu-panel-btn secondary">取消</button></div>`;document.body.appendChild(overlay);document.body.appendChild(modal);// 创建按钮modal.querySelector('#luogu-confirm-create')?.addEventListener('click', () => {const themeName = modal.querySelector('#luogu-new-theme-name').value.trim();const baseTheme = modal.querySelector('#luogu-base-theme').value;if (!themeName) {alert('请输入主题名称');return;}if (storage.themes[themeName]) {alert('主题名称已存在');return;}// 创建新主题const now = new Date().toISOString();let config;if (baseTheme && storage.themes[baseTheme]) {config = JSON.parse(JSON.stringify(storage.themes[baseTheme].config));} else {config = JSON.parse(JSON.stringify(DEFAULT_THEMES['经典图标主题'].config));}storage.themes[themeName] = {name: themeName,created: now,updated: now,config: config};saveStorage();removeExistingPanels();showThemeManager();});// 取消按钮modal.querySelector('#luogu-cancel-create')?.addEventListener('click', () => {removeExistingPanels();showThemeManager();});// 遮罩层点击关闭overlay.addEventListener('click', () => {removeExistingPanels();showThemeManager();});}// 显示复制主题模态框function showDuplicateThemeModal() {const currentTheme = storage.themes[storage.currentTheme];const newName = `${currentTheme.name} 副本`;showCreateThemeModal();// 设置默认值setTimeout(() => {const nameInput = document.querySelector('#luogu-new-theme-name');const baseSelect = document.querySelector('#luogu-base-theme');if (nameInput && baseSelect) {nameInput.value = newName;baseSelect.value = storage.currentTheme;}}, 50);}// 显示重命名主题模态框function showRenameThemeModal(themeName) {removeExistingPanels();const overlay = document.createElement('div');overlay.className = 'luogu-panel-overlay';const modal = document.createElement('div');modal.className = 'luogu-modal';modal.innerHTML = `<div class="luogu-modal-title">重命名主题</div><input type="text" id="luogu-rename-theme-name" class="luogu-modal-input"value="${themeName}" placeholder="输入新的主题名称" maxlength="20"><div class="luogu-modal-footer"><button id="luogu-confirm-rename" class="luogu-panel-btn success">确定</button><button id="luogu-cancel-rename" class="luogu-panel-btn secondary">取消</button></div>`;document.body.appendChild(overlay);document.body.appendChild(modal);// 重命名按钮modal.querySelector('#luogu-confirm-rename')?.addEventListener('click', () => {const newName = modal.querySelector('#luogu-rename-theme-name').value.trim();if (!newName) {alert('请输入新的主题名称');return;}if (newName === themeName) {removeExistingPanels();showThemeManager();return;}if (storage.themes[newName]) {alert('主题名称已存在');return;}// 重命名主题const theme = storage.themes[themeName];theme.name = newName;theme.updated = new Date().toISOString();// 更新主题列表storage.themes[newName] = theme;delete storage.themes[themeName];// 如果当前主题被重命名,更新当前主题if (storage.currentTheme === themeName) {storage.currentTheme = newName;}saveStorage();removeExistingPanels();showThemeManager();});// 取消按钮modal.querySelector('#luogu-cancel-rename')?.addEventListener('click', () => {removeExistingPanels();showThemeManager();});// 遮罩层点击关闭overlay.addEventListener('click', () => {removeExistingPanels();showThemeManager();});}// 删除主题function deleteTheme(themeName) {if (Object.keys(storage.themes).length <= 1) {alert('不能删除最后一个主题');return;}if (storage.currentTheme === themeName) {alert('不能删除当前正在使用的主题,请先切换到其他主题');return;}if (confirm(`确定要删除主题 "${themeName}" 吗?`)) {delete storage.themes[themeName];saveStorage();// 刷新主题管理器const panel = document.querySelector('#luogu-main-panel');if (panel) {showTabContent('themes');}}}// 保存主题配置function saveThemeConfig() {const config = {};DIFFICULTIES.forEach(diff => {const item = document.querySelector(`[data-difficulty="${diff}"]`);if (item) {const type = item.querySelector('.type-select').value;const value = item.querySelector('.content-input').value.trim();const color = type === 'text' ? item.querySelector('.color-input')?.value : undefined;config[diff] = {type: type,value: value || diff,color: color || '#95a5a6'};}});if (updateCurrentConfig(config)) {alert('配置已保存');processAllDifficulties();} else {alert('保存失败');}}// 显示主题编辑器function showThemeEditor() {removeExistingPanels();const overlay = document.createElement('div');overlay.className = 'luogu-panel-overlay';const panel = document.createElement('div');panel.id = 'luogu-main-panel';panel.innerHTML = getThemeEditorContent();document.body.appendChild(overlay);document.body.appendChild(panel);setupThemeEditorEvents();overlay.addEventListener('click', () => {removeExistingPanels();});}// 移除所有面板function removeExistingPanels() {const panels = ['.luogu-panel-overlay','#luogu-main-panel','.luogu-modal'];panels.forEach(selector => {const element = document.querySelector(selector);if (element) element.remove();});}// 监听页面变化function setupPageChangeListener() {if (!storage.settings.autoRefresh) return;const observer = new MutationObserver(() => {// 检查是否有新的难度标签出现const selectors = ['.difficulty-tags .row span:not(.problem-count):not(.luogu-processed)','.lcolor--grey-3:not(.luogu-processed)','.lcolor--pink-3:not(.luogu-processed)','.lcolor--orange-3:not(.luogu-processed)','.lcolor--gold-3:not(.luogu-processed)','.lcolor--green-3:not(.luogu-processed)','.lcolor--blue-3:not(.luogu-processed)','.lcolor--purple-3:not(.luogu-processed)','.lcolor--lapis-4:not(.luogu-processed)','.difficulty:not(.luogu-processed)'].join(',');const unprocessed = document.querySelectorAll(selectors);if (unprocessed.length > 0) {console.log(`检测到 ${unprocessed.length} 个新的难度元素,重新处理`);setTimeout(processAllDifficulties, 500);}});observer.observe(document.body, {childList: true,subtree: true});}// 初始化function init() {console.log('洛谷难度主题管理器 v10.3 启动 - 作者:鸡腿,PCY和祥子');// 加载存储数据loadStorage();// 初始处理setTimeout(() => {console.log('开始初始处理难度标签');processAllDifficulties();if (storage.settings.showRefreshButton) {addQuickMenu();}}, 2000);// 监听页面变化setupPageChangeListener();}// 启动if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', init);} else {setTimeout(init, 1000);}})();```事实上,脚本是 Deepseek 写的,不过,你会发现,版本号为 10.3,其实我们反复调教你好几次,确认每个页面的难度都可以正常显示,同时保证不会有内容识别出错,所以,即使是 AI 来干,我们也花费了三天时间来完善和扩展,也就变成了你现在看到的这样。希望大家能喜欢这个脚本,谢谢了。我今天入谷时长两年半,感谢各位。