[蓝墨云] 显示正确的单选选项

显示正确的单选选项方便复习

当前为 2021-12-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         [蓝墨云] 显示正确的单选选项
// @namespace    ckylin-script-mosoteach-showsinglecurrectanswer
// @version      0.1
// @description  显示正确的单选选项方便复习
// @author       CKylinMC
// @match        https://www.mosoteach.cn/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let highlighted = false;
function highlightCurrectAnswers(){
	if(highlighted) return; else highlighted = true;
	const get = (q,p=document.body) => p.querySelector(q);
	const getAll = (q,p=document.body) => p.querySelectorAll(q);
	const list = get(".main-box .topic-list");
	const items = getAll(".topic-item",list);
	const ansMap = ['A','B','C','D','E','F'];
	for(let it of items){
		try{
			const choices = [...getAll(".t-option.t-item>.opt",it)];
			const currect = get(".t-answer.t-item>.answer-l>.light");
			const answer = currect.innerHTML.trim();
			const index = ansMap.indexOf(answer.toUpperCase());
			choices.forEach((el,ind)=>{
				if(ind!=index){
					el.style.opacity = ".1";
					el.style.fontSize = "smaller";
				}else{
					el.style.fontSize = "larger";
				}
			})
		}catch(Exception){}
	}
}

function disableBottom(yes=true){
	const old = document.querySelector("#notbottomcss");
	old&&old.remove();
	if(yes){
		const css = document.createElement("style");
		css.appendChild(document.createTextNode(``));
		css.id = "notbottomcss";
		document.body.appendChild(css);
	}
}

function isContentReady(){
	return document.querySelector(".topic-list")!==null;
}

let timer = null;
function loader(){
	if(!isContentReady()){
		if(timer===null){
			timer = setInterval(loader,200);
		}else{
			console.log("Waiting...");
		}
	}else{
		clearInterval(timer);
		disableBottom();
		highlightCurrectAnswers();
	}
}
if(document.title.indexOf("查看个人解析")>=0)loader();
})();