保证代码中 AI 贡献不高于人类贡献。
功能
- 把“练习情况”一页中的题号改为徽章样式
如何使用
- 下载篡改猴
- 粘贴下方脚本代码至插件并启用
- 完成!现在你应该可以在洛谷的“练习情况”一页看到徽章了。
脚本代码
// ==UserScript==
// @name luogubadge
// @namespace http://tampermonkey.net/
// @version 1
// @description try to take over the world!
// @author XBA
// @match https://www.luogu.com.cn/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=luogu.com.cn
// @grant none
// ==/UserScript==
(function() {
'use strict';
function randomByteFromSeed(seed) {
// 1. 使用 FNV-1a 计算 32 位哈希
let hash = 2166136261;
const prime = 16777619;
for (let i = 0; i < seed.length; i++) {
const code = seed.charCodeAt(i);
// 处理低字节
hash ^= code & 0xFF;
hash = (hash * prime) >>> 0;
// 处理高字节
hash ^= (code >> 8) & 0xFF;
hash = (hash * prime) >>> 0;
}
// 2. 应用 MurmurHash3 的最终混合器(增强雪崩)
hash ^= hash >>> 16;
hash = (hash * 0x85ebca6b) >>> 0;
hash ^= hash >>> 13;
hash = (hash * 0xc2b2ae35) >>> 0;
hash ^= hash >>> 16;
// 3. 取最低 8 位作为输出
return hash & 0xFF;
}
function waitForList(getList, timeout = 5000, interval = 100) {
return new Promise((resolve, reject) => {
// 立即检查一次
const list = getList();
if (list && list.length > 0) return resolve(list);
const startTime = Date.now();
const timer = setInterval(() => {
const currentList = getList();
// 检查是否满足条件
if (currentList && currentList.length > 0) {
clearInterval(timer);
resolve(currentList);
} else if (Date.now() - startTime > timeout) {
clearInterval(timer);
}
}, interval);
});
}
var emojilist=["🏆","🥇","🥈","🥉","⭐","🌟","✨","💫","👑","🗡️","⚔️","🛡️","🏅","🎖️","🚩","⚡","🔥","❄️","💧","🌪️","☄️","🌈","💎","🔮","🧙","🧝","🧟","🧚","🦸","🦹","👾","🤖","📈","📊","🔺","🔻","🆙","🆕","💯","🎯","🔒","🔓","🗝️","🗺️","📍","🧭","🏔️","🌋","🐉","🦄","🦅","🐺","🐻","🦁","🐯","🐎","🪄","🏹","🪓","⛏️","🧨","💣","🛸","🚀","🪙","💰","💵","🏦","🥊","🥋","⚽","🏀","🏈","⚾","🎾","🏐","♟️","🎲","🃏","🎭","🎪","🎨","🎵","🎶","🌍","🌎","🌏","🌕","🌙","☀️","🌊","🌿","🍃","🍄","🪸","🐚","⌨️","🖥️","📀","💿","📡","📱","⏳","⌛","⏰","🕰️","❤️","🧡","💚","💙","💜","🖤","👊","✊","🤝","🏁","🎊","🎉","🎇","🎆","🧩","🎮","🕹️","📜","🏮","🪔","🎐","🧧"];
var css="";
css += [
".problem-id {",
" border: 3px solid;",
" width: 50px;",
" height: 50px;",
" margin-bottom: 5px;",
" margin-right: 5px !important;",
" border-radius: 28px;",
" display: flex;",
" align-items: center;",
" justify-content: center;",
" cursor: pointer;",
"}",
".problem-id > a {",
" color: black;",
" font-size: 23px;",
"}",
".lgbgtx {",
" position: absolute;",
" width: 200px;",
" text-align: center;",
" transform: translateY(-50%) translateY(-30px);",
" white-space: pre-wrap;",
" background-color: black;",
" border-radius: 5px;",
" color: white;",
" display: none;",
"}",
".lgbgtx:hover {",
" display: none !important;",
"}",
".problem-id:hover > .lgbgtx {",
" display: block;",
"}",
".zwpd > .problems > .problem-id {",
" background-color: rgb(191,191,191);",
"}",
".rm > .problems > .problem-id {",
" background-color: rgb(254,76,97);",
"}",
".pjs > .problems > .problem-id {",
" background-color: rgb(243,156,17);",
"}",
".pj > .problems > .problem-id {",
" background-color: rgb(255,193,22);",
"}",
".pjtg > .problems > .problem-id {",
" background-color: rgb(83,196,26);",
"}",
".tg > .problems > .problem-id {",
" background-color: rgb(19,194,194);",
"}",
".tgsx > .problems > .problem-id {",
" background-color: rgb(52,152,219);",
"}",
".sxn > .problems > .problem-id {",
" background-color: rgb(156,61,207);",
"}",
".nnc > .problems > .problem-id {",
" background-color: rgb(14,29,105);",
"}"
].join("\n");
if (typeof GM_addStyle != "undefined") {
GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
addStyle(css);
} else {
var node = document.createElement("style");
node.type = "text/css";
node.appendChild(document.createTextNode(css));
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
heads[0].appendChild(node);
} else {
// no head yet, stick it whereever
document.documentElement.appendChild(node);
}
}
function refrpro(){
var pds=document.getElementsByClassName("problem-id");
for(let i=0;i<pds.length;++i){
if(pds[i].hasAttribute('isbaged'))continue;
var t=document.createElement("div");
t.className="lgbgtx";
if(pds[i].parentElement.parentElement.children[0].textContent=="尝试过的题目"){
t.textContent="未完成 "+pds[i].children[0].textContent+" "+pds[i].children[0].getAttribute("title")+" 。";
}
else{
if(!pds[i].parentElement.parentElement.hasAttribute('ismkd')){
pds[i].parentElement.parentElement.setAttribute('ismkd', '');
if(pds[i].parentElement.parentElement.children[0].textContent=="暂无评定"){
pds[i].parentElement.parentElement.classList.add("zwpd");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="入门"){
pds[i].parentElement.parentElement.classList.add("rm");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="普及−"){
pds[i].parentElement.parentElement.classList.add("pjs");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="普及"){
pds[i].parentElement.parentElement.classList.add("pj");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="普及+/提高−"){
pds[i].parentElement.parentElement.classList.add("pjtg");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="提高"){
pds[i].parentElement.parentElement.classList.add("tg");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="提高+/省选−"){
pds[i].parentElement.parentElement.classList.add("tgsx");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="省选/NOI−"){
pds[i].parentElement.parentElement.classList.add("sxn");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="NOI/NOI+/CTS"){
pds[i].parentElement.parentElement.classList.add("nnc");
}
}
t.textContent="完成 "+pds[i].children[0].textContent+" "+pds[i].children[0].getAttribute("title")+" !";
}
pds[i].appendChild(t);
pds[i].addEventListener('click', function() {
location.assign(pds[i].children[0].getAttribute("href"));
});
pds[i].children[0].textContent=emojilist[randomByteFromSeed(pds[i].children[0].textContent)&0x7F];
pds[i].setAttribute('isbaged', '');
}
setTimeout(refrpro,2000);
}
var pids=document.getElementsByClassName("problem-id");
(async () => {
try {
const pds = await waitForList(() => pids);
for(let i=0;i<pds.length;++i){
if(pds[i].hasAttribute('isbaged'))continue;
var t=document.createElement("div");
t.className="lgbgtx";
if(pds[i].parentElement.parentElement.children[0].textContent=="尝试过的题目"){
t.textContent="未完成 "+pds[i].children[0].textContent+" "+pds[i].children[0].getAttribute("title")+" 。";
}
else{
if(!pds[i].parentElement.parentElement.hasAttribute('ismkd')){
pds[i].parentElement.parentElement.setAttribute('ismkd', '');
if(pds[i].parentElement.parentElement.children[0].textContent=="暂无评定"){
pds[i].parentElement.parentElement.classList.add("zwpd");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="入门"){
pds[i].parentElement.parentElement.classList.add("rm");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="普及−"){
pds[i].parentElement.parentElement.classList.add("pjs");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="普及"){
pds[i].parentElement.parentElement.classList.add("pj");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="普及+/提高−"){
pds[i].parentElement.parentElement.classList.add("pjtg");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="提高"){
pds[i].parentElement.parentElement.classList.add("tg");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="提高+/省选−"){
pds[i].parentElement.parentElement.classList.add("tgsx");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="省选/NOI−"){
pds[i].parentElement.parentElement.classList.add("sxn");
}
if(pds[i].parentElement.parentElement.children[0].textContent=="NOI/NOI+/CTS"){
pds[i].parentElement.parentElement.classList.add("nnc");
}
}
t.textContent="完成 "+pds[i].children[0].textContent+" "+pds[i].children[0].getAttribute("title")+" !";
}
pds[i].appendChild(t);
pds[i].addEventListener('click', function() {
location.assign(pds[i].children[0].getAttribute("href"));
});
pds[i].children[0].textContent=emojilist[randomByteFromSeed(pds[i].children[0].textContent)&0x7F];
pds[i].setAttribute('isbaged', '');
}
} catch (err) {
console.error(err.message);
}
})();
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if(node.matches && node.matches('.problem-id')){
if(node.hasAttribute('isbaged'))continue;
var t=document.createElement("div");
t.className="lgbgtx";
if(node.parentElement.parentElement.children[0].textContent=="尝试过的题目"){
t.textContent="未完成 "+node.children[0].textContent+" "+node.children[0].getAttribute("title")+" 。";
}
else{
if(!node.parentElement.parentElement.hasAttribute('ismkd')){
node.parentElement.parentElement.setAttribute('ismkd', '');
if(node.parentElement.parentElement.children[0].textContent=="暂无评定"){
node.parentElement.parentElement.classList.add("zwpd");
}
if(node.parentElement.parentElement.children[0].textContent=="入门"){
node.parentElement.parentElement.classList.add("rm");
}
if(node.parentElement.parentElement.children[0].textContent=="普及−"){
node.parentElement.parentElement.classList.add("pjs");
}
if(node.parentElement.parentElement.children[0].textContent=="普及"){
node.parentElement.parentElement.classList.add("pj");
}
if(node.parentElement.parentElement.children[0].textContent=="普及+/提高−"){
node.parentElement.parentElement.classList.add("pjtg");
}
if(node.parentElement.parentElement.children[0].textContent=="提高"){
node.parentElement.parentElement.classList.add("tg");
}
if(node.parentElement.parentElement.children[0].textContent=="提高+/省选−"){
node.parentElement.parentElement.classList.add("tgsx");
}
if(node.parentElement.parentElement.children[0].textContent=="省选/NOI−"){
node.parentElement.parentElement.classList.add("sxn");
}
if(node.parentElement.parentElement.children[0].textContent=="NOI/NOI+/CTS"){
node.parentElement.parentElement.classList.add("nnc");
}
}
t.textContent="完成 "+node.children[0].textContent+" "+node.children[0].getAttribute("title")+" !";
}
node.appendChild(t);
node.addEventListener('click', function() {
location.assign(node.children[0].getAttribute("href"));
});
node.children[0].textContent=emojilist[randomByteFromSeed(node.children[0].textContent)&0x7F];
node.setAttribute('isbaged', '');
}
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
//location.href = "https://www.example.com";
//location.assign("https://www.example.com");
setTimeout(refrpro,2000);
})();
