版本比较
洛谷简易插件2.0
正文
增加 17 行删除 36 行
12345678910117 行未改动192021222324252627282930313233343536373839264 行未改动全部展开30430530630730830931031131231331431531631731816 行未改动33533633733833934034134234334434534634734834935035135235310 行未改动36436536636736836937037137237337437537637725 行未改动403404405406407[这个插件](https://www.luogu.com.cn/article/dxg99wmz)由于现在洛谷增加了青题,不支持青题渲染,所以我和 ds 把这个插件修改了一下,如下,支持青题渲染:```cpp// ==UserScript==// @name luogu_bot1// @namespace http://tampermonkey.net/// @version 1.0.0// @description 简易洛谷插件// @author heffo_hard// @match https://www.luogu.com.cn/*// @grant none// @run-at document-end7 行未改动['lgbot1AddMessageLink', '私信界面 Ctrl+Click 打开用户主页'],['lgbot1RemoveCover', '移除主页遮盖'],['lgbot1AddProblemsColor', '显示题目颜色']]);// 修改点:在绿题(索引4)和蓝题(原索引5)之间插入青题,后续颜色依次后移// 新索引对应关系:0-灰,1-红,2-橙,3-黄,4-绿,5-青,6-蓝,7-紫,8-黑const problemDifficultyToColor = [[191,191,191], // 0: 暂无评定[254,76,97], // 1: 入门[243,156,17], // 2: 普及-[255,193,22], // 3: 普及/提高-[82,196,26], // 4: 普及+/提高(绿)[19,194,194], // 5: 提高(青)← 新增,插在绿和蓝之间[52,152,219], // 6: 提高+/省选-(蓝)[157,61,207], // 7: 省选/NOI-(紫)[14,29,105] // 8: NOI/NOI+/CTSC(黑)];function addSettingButton(){//增加插件设置const navElement = document.querySelector('nav.lfe-body');if(!navElement){console.log("未找到侧边导航栏");264 行未改动全部展开let scriptText = '';for(const i of doc.querySelectorAll("script")){scriptText += i.textContent;}const match = scriptText.match(/"difficulty":(\d+)/);if(!match) return;const problemDifficulty = Number(match[1]);if(problemDifficulty >= 0 && problemDifficulty < problemDifficultyToColor.length){problemToColorMap.set(problemid,`rgb(${problemDifficultyToColor[problemDifficulty].join(',')})`);return problemToColorMap.get(problemid);}}function isProblemId(problemid){if(problemid.startsWith('AT_')) return true;if(!/[a-zA-Z]/.test(problemid)) return false;16 行未改动if(item.innerText.startsWith(problemid)){const spanItem = item.children[0];if(spanItem && spanItem.matches('span.pid') && spanItem.innerText === problemid){const color = await getProblemColor(problemid, prior);if(color){spanItem.style.color = color;spanItem.style.fontWeight = 'bold';}}else{const color = await getProblemColor(problemid, prior);if(color){const content = item.innerHTML;item.innerHTML = content.replace(problemid,`<b style="color: ${color};">${problemid}</b>`);}}}}async function addProblemsColor(){10 行未改动}}}else if(mutation.type === 'characterData') {if(mutation.target.parentElement && mutation.target.parentElement.matches('span.pid')){const color = await getProblemColor(mutation.target.textContent);if(color){mutation.target.parentElement.style.color = color;mutation.target.parentElement.style.fontWeight = 'bold';}}}}});25 行未改动if(localStorage.getItem('lgbot1AddProblemsColor') === 'true'){setTimeout(addProblemsColor, 500);}})();```12345678910117 行未改动192021222324252627264 行未改动全部展开29229329429529629729829930030130230330430516 行未改动32232332432532632732832933033133233333433533610 行未改动34734834935035135235335435535635725 行未改动383384385386387388[这个插件](https://www.luogu.com.cn/article/dxg99wmz)由于现在洛谷增加了青题,不支持青题渲染,所以我把这个插件修改了一下,如下,支持青题渲染:```cpp// ==UserScript==// @name luogu_bot1// @namespace http://tampermonkey.net/// @version 1.0.0// @description 自制洛谷插件// @author heffo_hard// @match https://www.luogu.com.cn/*// @grant none// @run-at document-end7 行未改动['lgbot1AddMessageLink', '私信界面 Ctrl+Click 打开用户主页'],['lgbot1RemoveCover', '移除主页遮盖'],['lgbot1AddProblemsColor', '显示题目颜色']]);const problemDifficultyToColor = [[191,191,191],[254,76,97],[243,156,17],[255,193,22],[82,196,26],[19,194,194],[52,152,219],[157,61,207],[14,29,105]];function addSettingButton(){//增加插件设置const navElement = document.querySelector('nav.lfe-body');if(!navElement){console.log("未找到侧边导航栏");264 行未改动全部展开let scriptText = '';for(const i of doc.querySelectorAll("script")){scriptText += i.textContent;}scriptText = scriptText.match(/"difficulty":\d/)[0];debugger;if(!scriptText) return;const problemDifficulty = Number(scriptText[scriptText.length-1]);problemToColorMap.set(problemid,`rgb(${problemDifficultyToColor[problemDifficulty].join(',')})`);return problemToColorMap.get(problemid);}function isProblemId(problemid){if(problemid.startsWith('AT_')) return true;if(!/[a-zA-Z]/.test(problemid)) return false;16 行未改动if(item.innerText.startsWith(problemid)){const spanItem = item.children[0];if(spanItem && spanItem.matches('span.pid') && spanItem.innerText === problemid){const color = await getProblemColor(problemid, prior);spanItem.style.color = color;spanItem.style.fontWeight = 'bold';}else{const color = await getProblemColor(problemid, prior);const content = item.innerHTML;item.innerHTML = content.replace(problemid,`<b style="color: ${color};">${problemid}</b>`);}}}async function addProblemsColor(){10 行未改动}}}else if(mutation.type === 'characterData') {if(mutation.target.parentElement.matches('span.pid')){mutation.target.parentElement.style.color = await getProblemColor(mutation.target.textContent);mutation.target.parentElement.style.fontWeight = 'bold';}}}});25 行未改动if(localStorage.getItem('lgbot1AddProblemsColor') === 'true'){setTimeout(addProblemsColor, 500);}})();```