[蓝墨云] 重做单选和多选

显示正确的选项方便复习

  1. // ==UserScript==
  2. // @name [蓝墨云] 重做单选和多选
  3. // @namespace ckylin-script-mosoteach-redochoices
  4. // @version 0.4
  5. // @description 显示正确的选项方便复习
  6. // @author CKylinMC
  7. // @match https://www.mosoteach.cn/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let highlighted = false;
  16. const get = (q,p=document.body) => p.querySelector(q);
  17. const getAll = (q,p=document.body) => p.querySelectorAll(q);
  18. function highlightCurrectAnswers(){
  19. if(highlighted) return; else highlighted = true;
  20. const list = get(".main-box .topic-list");
  21. const items = getAll(".topic-item",list);
  22. const ansMap = ['A','B','C','D','E','F','G','H','I','J','K'];
  23. for(let it of items){
  24. try{
  25. const flag = get(".t-flag",it);
  26. if(flag){
  27. flag.className = "t-flag";
  28. }
  29. const choicesContainer = get(".t-option.t-item",it);
  30. const choices = [...getAll(".t-option.t-item>.opt",it)];
  31. const currect = get(".t-answer.t-item>.answer-l>.light",it);
  32. const answers = currect.innerHTML.trim().split('');
  33. const indexes = [];
  34. for(let ans of answers){
  35. let ind = ansMap.indexOf(ans.toUpperCase());
  36. if(ind>=0 && !indexes.includes(ind)) indexes.push(ind);
  37. }
  38. choicesContainer.setAttribute("data-answer-info",JSON.stringify({
  39. "answers": indexes,
  40. "answered": [],
  41. "wronged": false,
  42. "lock": false
  43. }))
  44. choices.forEach((el,ind)=>{
  45. el.setAttribute("data-answer-index",ind);
  46. el.style.fontSize = "larger";
  47. el.style.cursor = "pointer"
  48. el.classList.add("hl-hover");
  49. if(!indexes.includes(ind)){
  50. //el.style.opacity = ".1";
  51. //el.style.fontSize = "smaller";
  52. el.setAttribute("data-answer-currect","no")
  53. }else{
  54. //el.style.fontSize = "larger";
  55. el.setAttribute("data-answer-currect","yes")
  56. }
  57. el.onclick = optionClickCallback;
  58. })
  59. }catch(Exception){}
  60. }
  61. }
  62.  
  63. function optionClickCallback(e){
  64. let current = e.target;
  65. if(current.classList.contains("opt-content")) current = current.parentNode;
  66. const parent = current.parentNode;
  67. const container = parent.parentNode.parentNode.parentNode;
  68. const answerEl = get(".t-answer.t-item",container);
  69. const flag = get(".t-flag",container);
  70. const ind = parseInt(current.getAttribute("data-answer-index"));
  71. const info = JSON.parse(parent.getAttribute("data-answer-info"));
  72. if(info.lock) return;
  73. if(current.getAttribute("data-answer-currect")=="yes"){
  74. current.classList.add("hl-true");
  75. if(!info.answered.includes(ind)){
  76. info.answered.push(ind);
  77. }
  78. }else{
  79. current.classList.add("hl-false");
  80. info.wronged = true;
  81. answerEl.style.display = "block";
  82. }
  83. if(info.wronged) {
  84. parent.previousElementSibling.style.color = "red";
  85. flag.classList.add("t-flag-wrong");
  86. let ico = get(".flag-icon",flag);
  87. ico.className = "flag-icon el-icon-close";
  88. }
  89. if(info.answered.length==info.answers.length) {
  90. if(!info.wronged){
  91. parent.previousElementSibling.style.color = "darkgreen";
  92. flag.classList.add("t-flag-right");
  93. let ico = get(".flag-icon",flag);
  94. ico.className = "flag-icon el-icon-check";
  95. }
  96. info.lock = true;
  97. }
  98. parent.setAttribute("data-answer-info",JSON.stringify(info));
  99. }
  100.  
  101. function customcss(yes=true){
  102. const old = document.querySelector("#rdcustomcss");
  103. old&&old.remove();
  104. if(yes){
  105. const css = document.createElement("style");
  106. css.appendChild(document.createTextNode(`
  107. .hl-hover:hover{
  108. background: antiquewhite;
  109. }
  110. .t-con>.t-info.t-item{
  111. display:none !important;
  112. }
  113. .t-con>.t-subject{
  114. font-weight:bold !important;
  115. font-size:large !important;
  116. }
  117. .t-bottom{
  118. display:none !important;
  119. }
  120. .t-top{
  121. padding-bottom: 20px !important;
  122. }
  123. .t-answer.t-item,.answer-r{
  124. display:none;
  125. }
  126. .hl-true{
  127. color: blue!important;
  128. }
  129. .hl-false{
  130. color: red!important;
  131. }
  132. `));
  133. css.id = "rdcustomcss";
  134. document.body.appendChild(css);
  135. }
  136. }
  137.  
  138. function isContentReady(){
  139. return document.querySelector(".topic-list")!==null;
  140. }
  141.  
  142. let timer = null;
  143. function loader(){
  144. if(!isContentReady()){
  145. if(timer===null){
  146. timer = setInterval(loader,200);
  147. }else{
  148. console.log("Waiting...");
  149. }
  150. }else{
  151. clearInterval(timer);
  152. customcss();
  153. highlightCurrectAnswers();
  154. }
  155. }
  156. if(document.title.indexOf("查看个人解析")>=0)loader();
  157. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址