您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
更改洛谷讨论区主题颜色,支持自定义。
当前为
// ==UserScript== // @name Peacock Setaria Luogu 狗尾草洛谷 // @namespace http://tampermonkey.net/ // @version 0.6.91 // @description 更改洛谷讨论区主题颜色,支持自定义。 // @author cff_0102, jia123456 // @match https://www.luogu.com.cn/* // @icon https://www.google.com/s2/favicons?sz=64&domain=luogu.com.cn // @grant none // @license MIT // ==/UserScript== (function() { 'use strict';//说明: 感谢洛谷用户 @cff_0102 的开发资助,此版本经 @cff_0102 同意借鉴了部分内容,完善了自定义功能 function hexToRgb(hex) {hex = hex.replace(/^#/, '');const bigint = parseInt(hex, 16);const r = (bigint >> 16) & 255;const g = (bigint >> 8) & 255;const b = bigint & 255;return { r, g, b };} function lighterColor(hex) {hex = hex.replace(/^#/, '');const bigint = parseInt(hex, 16);let r = (bigint >> 16) & 255;let g = (bigint >> 8) & 255;let b = bigint & 255;r = Math.floor(255 - (255 - r) / 2);g = Math.floor(255 - (255 - g) / 2);b = Math.floor(255 - (255 - b) / 2);const newHex = ((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1);return `#${newHex}`; } // 更改颜色 function changeColors(){//↓ 更改这里的七个十六进制颜色即可更改洛谷相应版块的颜色 const newcolor1 = '#34495e'; // “全部板块”的颜色 const newcolor2 = '#F01010'; // “站务版”的颜色 const newcolor3 = '#F0B810'; // “题目总版”的颜色 const newcolor4 = '#9CF010'; // “学术版”的颜色 const newcolor5 = '#10F0D4'; // “灌水区”的颜色 const newcolor6 = '#109CF0'; // “反馈、申请、工单专版”的颜色 const newcolor7 = '#8010F0'; // “小黑屋”的颜色 const newcolor8 = '#F010D4'; // 团队内帖子的颜色 // 更改上面的颜色(并保存更改后的脚本)即可实现更改洛谷对应讨论区的颜色 const ch = 1;// 是否更改背景色(0 或 1 或 2)(0: 默认背景, 1: 透明背景, 2: 不透明背景) const exco = 1;// 是否更改二楼之后颜色(0 或 1) // 更改上面的设置即可更改显示效果 // 建议在某个地方保存自己的设置,以免更新时回到原来的设置 /* 附: 1. 洛谷原版色系: const newcolor1 = '#272727'; // “全部板块”的颜色 const newcolor2 = '#14558f'; // “站务版”的颜色 const newcolor3 = '#f39c11'; // “题目总版”的颜色 const newcolor4 = '#9d9dcf'; // “学术版”的颜色 const newcolor5 = '#52c41a'; // “灌水区”的颜色 const newcolor6 = '#2949b4'; // “反馈、申请、工单专版”的颜色 const newcolor7 = '#272727'; // “小黑屋”的颜色 const newcolor8 = '#272727'; // 团队内帖子的颜色 */ var newColor = '3498DB'; const elementsWithCustomStyle = document.querySelectorAll('[style*="--forum-color: #f39c11; color: var(--forum-color);"]');// 题目讨论版 elementsWithCustomStyle.forEach(function (element) { element.style.cssText = `--forum-color: ${newcolor3}; color: var(--forum-color);`; }); const forumElement = document.querySelector("section.side"); if(forumElement){ // 获取所属板块的文本内容 const forumTextElement = forumElement.querySelector("a.color-default"); const forumText = forumTextElement.textContent.trim(); const temp = document.querySelector("section.main"); const temp1 = temp.querySelector("div.card.padding-default"); // 根据所属板块的文本内容判断是否需要修改颜色 if (forumText === '站务版') { newColor = newcolor2; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (forumText === '题目总版') { newColor = newcolor3; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (forumText === '学术版') { newColor = newcolor4; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (forumText === '灌水区') { newColor = newcolor5; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (forumText === '反馈、申请、工单专版') { newColor = newcolor6; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (forumText === '小黑屋') { newColor = newcolor7; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (forumText.startsWith('团队')){// 团队帖子内 newColor = newcolor8; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; }else if (window.location.href.startsWith('https://www.luogu.com.cn/discuss/')){// 在题目详情页中 // console.log(forumText); newColor = newcolor3; // 设置新的颜色值 const rgbColor = hexToRgb(newColor); // 将十六进制颜色转换为 RGB 形式 // 修改元素的颜色属性 temp1.style.cssText = `border-bottom: 2px solid rgb(${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b});`; } } const v=document.getElementsByClassName('card padding-default'); if (exco) { var vn = 0; for(let x of v) { if (vn >= 2) { x.style.cssText="border-bottom: 1px solid "+newColor+";";// 强化主题色 } vn = vn + 1; } } const a=document.querySelectorAll("[title=全部板块]"); for(let x of a) x.style.cssText = `--forum-color: ${newcolor1}; color: var(--forum-color);`; //洛谷蓝 const b=document.querySelectorAll("[title=站务版]"); for(let x of b) x.style.cssText = `--forum-color: ${newcolor2}; color: var(--forum-color);`; //紫名紫 const c=document.querySelectorAll("[title=题目总版]"); for(let x of c) x.style.cssText = `--forum-color: ${newcolor3}; color: var(--forum-color);`; // AC 绿 const d=document.querySelectorAll("[title=学术版]"); for(let x of d) x.style.cssText = `--forum-color: ${newcolor4}; color: var(--forum-color);`; //红名红 const e=document.querySelectorAll("[title=灌水区]"); for(let x of e) x.style.cssText = `--forum-color: ${newcolor5}; color: var(--forum-color);`; //cff 青 const f=document.querySelectorAll("[title=反馈、申请、工单专版]"); for(let x of f) x.style.cssText = `--forum-color: ${newcolor6}; color: var(--forum-color);`; //排行橙 const g=document.querySelectorAll("[title=小黑屋]"); for(let x of g){x.style.cssText = `--forum-color: ${newcolor7}; color: var(--forum-color);`; //棕名棕 const svgElement = x.querySelector("svg"); const pathElement = svgElement.querySelector("path"); pathElement.setAttribute("d", "M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48"); //更改小黑屋图标(从四个方块改成一个方块) } const h=document.querySelectorAll("[title^=团队]"); for(let x of h){x.style.cssText = `--forum-color: ${newcolor8}; color: var(--forum-color);`; //比赛蓝 const svgElement = x.querySelector("svg"); const pathElement = svgElement.querySelector("path"); pathElement.setAttribute("d", "M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48"); //更改小黑屋图标(从四个方块改成一个方块) } if(ch == 1){ const c=document.getElementsByClassName("card post-item padding-default"); for (let el of c) { if (el.querySelector("[title=站务版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor2)}40; color: var(--forum-color);`; } else if (el.querySelector("[title=题目总版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor3)}40; color: var(--forum-color);`; } else if (el.querySelector("[title=学术版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor4)}40; color: var(--forum-color);`; } else if (el.querySelector("[title=灌水区]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor5)}40; color: var(--forum-color);`; } else if (el.querySelector("[title=反馈、申请、工单专版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor6)}40; color: var(--forum-color);`; } else if (el.querySelector("[title=小黑屋]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor7)}40; color: var(--forum-color);`; } else if (el.querySelector("[title^=团队]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor8)}40; color: var(--forum-color);`; } else {// 题目讨论区 el.style.cssText=`background-color: ${lighterColor(newcolor3)}40; color: var(--forum-color);`; } }// 改背景色 } else if(ch == 2){ const c=document.getElementsByClassName("card post-item padding-default"); for (let el of c) { if (el.querySelector("[title=站务版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor2)}; color: var(--forum-color);`; } else if (el.querySelector("[title=题目总版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor3)}; color: var(--forum-color);`; } else if (el.querySelector("[title=学术版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor4)}; color: var(--forum-color);`; } else if (el.querySelector("[title=灌水区]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor5)}; color: var(--forum-color);`; } else if (el.querySelector("[title=反馈、申请、工单专版]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor6)}; color: var(--forum-color);`; } else if (el.querySelector("[title=小黑屋]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor7)}; color: var(--forum-color);`; } else if (el.querySelector("[title^=团队]")!=null) { el.style.cssText=`background-color: ${lighterColor(newcolor8)}; color: var(--forum-color);`; } else {// 题目讨论区 el.style.cssText=`background-color: ${lighterColor(newcolor3)}; color: var(--forum-color);`; } }// 改背景色 } } //每隔 300 毫秒执行一次颜色更改函数 setInterval(changeColors, 300); })();