正保会计网校(原中华会计网校)继续教育自动答题2024修复版

正保会计网校(原中华会计网校)继续教育自动答题

  1. // ==UserScript==
  2. // @name 正保会计网校(原中华会计网校)继续教育自动答题2024修复版
  3. // @version 2024.04.23.002
  4. // @description 正保会计网校(原中华会计网校)继续教育自动答题
  5. // @author Herohub
  6. // @match https://jxjy.chinaacc.com/courseware/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace https://github.com/LazyBug1E0CF
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. let answerRegex = /(?<=正确答案:)[\w对错]+(?=。)/;
  16.  
  17. let answerDict = {
  18. "对": "Y",
  19. "错": "N",
  20. "A": "A",
  21. "B": "B",
  22. "C": "C",
  23. "D": "D",
  24. "E": "E",
  25. "F": "F"
  26. };
  27.  
  28. setInterval(() => {
  29. if (isTesting()) {
  30. // 先直接提交答案,以便得到正确答案
  31. doAnswer();
  32.  
  33. let answerTipDiv = document.querySelector("#PointQuestionAnswer0");
  34. while(answerTipDiv.innerHTML === "") {
  35. console.log("等待正确答案中。。。");
  36. }
  37. let correctAnswer = getCorrectAnswer();
  38. fillRightAnswer(correctAnswer);
  39. clearAnswerDiv();
  40. doAnswer();
  41. }
  42. }, 1000);
  43.  
  44. // 答题弹窗
  45. let testDiv = document.querySelector("div#videoPoint");
  46.  
  47. // 检查是否在进行答题
  48. let isTesting = function() {
  49. return "none" != testDiv.style.display;
  50. };
  51.  
  52. // 提交答案
  53. let doAnswer = function() {
  54. // 答题按钮
  55. let answerBtn = document.querySelector("input[name='btn']");
  56. answerBtn.click();
  57. };
  58.  
  59. // 取得正确答案
  60. let getCorrectAnswer = function() {
  61. let answerText = document.querySelector("#PointQuestionAnswer0").innerText;
  62. let match = answerText.match(answerRegex);
  63. if (match) {
  64. return match[0];
  65. }
  66. };
  67.  
  68. // 选择正确答案
  69. let fillRightAnswer = function(answerString) {
  70. let answers = answerString.split("");
  71. for (let answer of answers) {
  72. let answerValue = answerDict[answer.toUpperCase()];
  73. document.querySelector("input[name='useranswer0'][value='" + answerValue + "']").checked = true;
  74. }
  75. };
  76.  
  77. // 延迟5秒关闭答题弹窗
  78. let closeBtn = document.querySelector("a#closePointId");
  79. setTimeout(function() {
  80. closeBtn.click();
  81. }, 5000);
  82.  
  83. // 设置一个变量来存储关闭按钮的引用
  84. let closeBtnX;
  85.  
  86. // 定时检查关闭按钮是否存在
  87. setInterval(function() {
  88. // 尝试获取关闭按钮的DOM元素
  89. closeBtnX = document.querySelector("a#closePointId");
  90. // 如果找到了关闭按钮
  91. if (closeBtnX) {
  92. // 设置10秒后自动点击关闭按钮
  93. setTimeout(function() {
  94. if (closeBtnX && closeBtnX.click) {
  95. closeBtnX.click();
  96. }
  97. }, 10000); // 10秒(10000毫秒)后执行点击操作
  98.  
  99. // 清除定时器,避免重复设置
  100. clearInterval(this);
  101. }
  102. }, 1000); // 每秒检查一次
  103.  
  104. // 清空答案提示
  105. let clearAnswerDiv = function() {
  106. document.querySelector("#PointQuestionAnswer").innerHTML = "";
  107. };
  108. })();