ChaoxingAnswerToggler

隐藏或显示学习通作业选择题答案,复习专用。

  1. // ==UserScript==
  2. // @name ChaoxingAnswerToggler
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 隐藏或显示学习通作业选择题答案,复习专用。
  6. // @author Cassius0924
  7. // @match https://mooc1.chaoxing.com/mooc-ans/mooc2/work/*
  8. // @match https://mooc1.chaoxing.com/*
  9. // @match https://mooc1.chaoxing.com/mycourse/studentstudy/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=chaoxing.com
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. function toggleAnswer(answerDiv) {
  19. if (answerDiv.style.visibility === 'hidden' || answerDiv.style.visibility === '') {
  20. answerDiv.style.visibility = 'visible';
  21. } else {
  22. answerDiv.style.visibility = 'hidden';
  23. }
  24. }
  25.  
  26. function hideAllAnswers(answerDivs) {
  27. answerDivs.forEach(function(answerDiv) {
  28. answerDiv.style.visibility = 'hidden';
  29. });
  30. }
  31.  
  32. function showAllAnswers(answerDivs) {
  33. answerDivs.forEach(function(answerDiv) {
  34. answerDiv.style.visibility = 'visible';
  35. });
  36. }
  37.  
  38. function createElement(tag, className, style, content) {
  39. const element = document.createElement(tag);
  40. className && (element.className = className);
  41. style && (element.style = style);
  42. content && (element.innerHTML = content);
  43. return element;
  44. }
  45.  
  46. function applyToggler(QContainerClassName, AContainerClassName, TContainerClassName, Style) {
  47. var questionContainers = document.querySelectorAll(QContainerClassName);
  48.  
  49. questionContainers.forEach(function(questionContainer) {
  50. var answerDiv = questionContainer.querySelector(AContainerClassName);
  51. answerDiv.classList.add('ha_mark_answer');
  52. answerDiv.style.width = 'auto';
  53. answerDiv.style.visibility = 'visible';
  54. var showAnswerButton = createElement('button', 'ha_toggle_answer_button');
  55. showAnswerButton.classList.add('ha_button');
  56. showAnswerButton.textContent = '显示答案';
  57. showAnswerButton.addEventListener('click', (event) => {
  58. toggleAnswer(answerDiv)
  59. });
  60.  
  61. questionContainer.appendChild(showAnswerButton);
  62. });
  63.  
  64. const topicNumberContainer = document.querySelector(TContainerClassName);
  65. if (topicNumberContainer) {
  66. var haControlDiv = createElement('div', 'ha_control_div');
  67. haControlDiv.classList.add('topicNumber_checkbox');
  68. topicNumberContainer.appendChild(haControlDiv);
  69.  
  70. var haShowAllButton = createElement('button', 'ha_show_all_answer');
  71. haShowAllButton.classList.add('ha_button');
  72. haShowAllButton.textContent = '显示所有答案';
  73. haShowAllButton.addEventListener('click', ()=>{
  74. var answerDivs = document.querySelectorAll(AContainerClassName);
  75. showAllAnswers(answerDivs);
  76. });
  77. haControlDiv.appendChild(haShowAllButton);
  78.  
  79. var haHiddenAllButton = createElement('button', 'ha_hidden_all_answer');
  80. haHiddenAllButton.classList.add('ha_button');
  81. haHiddenAllButton.textContent = '隐藏所有答案';
  82. haHiddenAllButton.addEventListener('click', ()=> {
  83. var answerDivs = document.querySelectorAll(AContainerClassName);
  84. hideAllAnswers(answerDivs);
  85. });
  86. haControlDiv.appendChild(haHiddenAllButton);
  87.  
  88. document.querySelector(TContainerClassName).appendChild(createElement('style', 'ha-global-style', '', Style));
  89. }
  90. }
  91.  
  92. const QContainerClassNames = [
  93. {
  94. QC: ".questionLi",
  95. AC: ".mark_answer",
  96. TC: "#topicNumberScroll",
  97. Style: '.ha_hidden_all_answer{margin-top: -20px; width: 90px; height: 32px} .ha_show_all_answer{margin-top: -10px; margin-right: 50px;width: 90px; height: 32px} .ha_toggle_answer_button {margin-top: -43px;margin-left: 24px;width: 70px;height: 32px;line-height: 32px;} .ha_button {box-shadow: -4px -4px 10px -8px rgba(255, 255, 255, 1), 4px 4px 10px -8px rgba(0, 0, 0, .3); background: linear-gradient(135deg, rgba(230, 230, 230, 1) 0%, rgba(246, 246, 246, 1) 100%);cursor: pointer;border: 1px solid #e5e5e5;border-radius: 5px;text-align: center;} .ha_mark_answer{margin-left: 100px;}'
  98. },
  99. {
  100. QC: ".newTiMu",
  101. AC: ".newAnswerBx",
  102. TC: ".ceyan_name",
  103. Style: '.ha_hidden_all_answer{margin-top: -20px; width: 90px; height: 32px} .ha_show_all_answer{margin-top: 13px; margin-right: 50px;width: 90px; height: 32px} .ha_toggle_answer_button {margin-top: -130px;margin-left: 24px;width: 70px;height: 32px;line-height: 32px;} .ha_button {box-shadow: -4px -4px 10px -8px rgba(255, 255, 255, 1), 4px 4px 10px -8px rgba(0, 0, 0, .3); background: linear-gradient(135deg, rgba(230, 230, 230, 1) 0%, rgba(246, 246, 246, 1) 100%);cursor: pointer;border: 1px solid #e5e5e5;border-radius: 5px;text-align: center;} .ha_mark_answer{margin-left: 100px;}'
  104. },
  105. ];
  106.  
  107. QContainerClassNames.forEach((map) => {
  108. console.log("APL");
  109. applyToggler(map["QC"], map["AC"], map["TC"], map["Style"]);
  110. });
  111.  
  112. })();

QingJ © 2025

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