跳到正文

剪贴板

剪贴板 i5puzqt7

原文
剪贴板信息

剪贴板信息

收录
更新
JavaScript
// ==UserScript==
// @name         洛谷 - 用户 - 高亮通过题目难度
// @author       hotwords123
// @version      1.0
// @match        https://www.luogu.com.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

	const difficultyColors = [
		'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)'
	];

	const state = window._feInjection;
	const instance = window._feInstance;

	function tryHighlightProblems() {
		if (state.currentTemplate === 'UserShow') {
			const user = state.currentData;
			const problemList = [...user.passedProblems, ...user.submittedProblems];
			if (Array.isArray(problemList) && problemList.length) {
				const problems = new Map(problemList.map(problem => [problem.pid, problem]));
				const component = instance.$children[0].$children[4];
				if (component.menuSelected === 'practice') {
					const nodes = [].slice.call(document.querySelectorAll('.full-container .problems span.problem-id a'));
					for (const node of nodes) {
						const pid = node.textContent.trim();
						const problem = problems.get(pid);
						if (problem) {
							node.title = `${problem.pid} ${problem.title}`;
							node.style.color = difficultyColors[problem.difficulty];
							node.style.fontWeight = 'bold';
						}
					}
				}
			}
		}
	}

	function updateHandler() {
		setTimeout(tryHighlightProblems, 1200);
	}

	window.addEventListener('load', updateHandler, false);
	window.addEventListener('popstate', updateHandler, false);

	const pushState = history.pushState.bind(history);
	history.pushState = function (...arg) {
		updateHandler();
		return pushState(...arg);
	};
})();