洛谷个人练习中显示题目颜色

在控制台中加上如下代码

var colors = ['rgb(191, 191, 191)', 'rgb(254, 76, 97)', 'rgb(243, 156, 17)', 'rgb(255, 193, 22)', 'rgb(82, 196, 26)', 'rgb(52, 152, 219)', 'rgb(157, 61, 207)', 'rgb(14, 29, 105)'];
(function() {
    'use strict';
    var problems = [];
    for(var passed of window._feInjection.currentData.passedProblems) problems.push({pid: passed.pid, dif: passed.difficulty, rendered: false});
    for(var tryed of window._feInjection.currentData.submittedProblems) problems.push({pid: tryed.pid, dif: tryed.difficulty, rendered: false});
    setInterval(() => {
        if(window.location.href.split("#").length == 2 && window.location.href.split("#")[1] == 'practice'){
            for(var i = 0;i < problems.length;i++) if(!problems[i].rendered) {
                var elements = document.querySelectorAll('a');
                for(var el of elements) if(el.textContent == problems[i].pid) {
                    if (el.classList) el.classList.remove("color-default");
                    else el.className = el.className.replace('color-default',  ' ');
                    problems[i].rendered = true;
                    el.style.color = colors[problems[i].dif];
                    break;
                }
            }
        }else for(var j = 0;j < problems.length;j++) problems[j].rendered = false;
    }, 1000);
})();
posted @ 2021-07-20 19:29  dbg_8  阅读(1163)  评论(0编辑  收藏  举报