普法网(宪法小卫士)课后练习、考试自动答题

第六届全国学生“学宪法 讲宪法”活动

目前为 2022-08-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 普法网(宪法小卫士)课后练习、考试自动答题
  3. // @namespace Ne-21
  4. // @version 1.3.2
  5. // @description 第六届全国学生“学宪法 讲宪法”活动
  6. // @author Ne-21
  7. // @match *://static.qspfw.moe.gov.cn/*
  8. // @icon https://blog.gocos.cn/wp-content/uploads/2021/07/2021-07-2782.ico
  9. // @connect api.gocos.cn
  10. // @run-at document-end
  11. // @grant unsafeWindow
  12. // @license MIT
  13. // @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
  14. // @require https://cdn.staticfile.org/limonte-sweetalert2/11.0.1/sweetalert2.all.min.js
  15. // ==/UserScript==
  16.  
  17. var _self = unsafeWindow,
  18. $ = _self.jQuery || top.jQuery,
  19. Swal = Swal || window.Swal,
  20. columnId = getQueryVariable("columnId"),
  21. answer_list = [],
  22. exam_list = [],
  23. time = 3000, // 答题间隔时间,最好为3000mss
  24. num = {"A": 1,"B": 2, "C": 3, "D": 4};
  25.  
  26. (function() {
  27. if (window.location.pathname == '/xf2022/learn_exam.html') {
  28. Swal.fire('宪法小助手提示','点击确定开始考试(因无测试账号,所以脚本可用性未知,欢迎提供测试账号,邮箱nawlgzs#gmail.com)','info')
  29. getExam();
  30. let t = setInterval( function() {
  31. doExam(t)
  32. },time);
  33. } else if (window.location.pathname == '/xf2022/learn-practice.html') {
  34. Swal.fire('宪法小助手提示','点击确定开始练习(因无测试账号,所以脚本可用性未知,欢迎提供测试账号,邮箱nawlgzs#gmail.com)','info')
  35. getAnswer(columnId);
  36. let t = setInterval( function() {
  37. doQuestion(t)
  38. },time);
  39. }
  40. })();
  41.  
  42. // 解析url参数
  43. function getQueryVariable(variable) {
  44. var query = window.location.search.substring(1);
  45. var vars = query.split("&");
  46. for (var i=0;i<vars.length;i++) {
  47. var pair = vars[i].split("=");
  48. if(pair[0] == variable){return pair[1];}
  49. }
  50. return(false);
  51. };
  52.  
  53. // 正则匹配
  54. function getStr(str, start, end) {
  55. let res = str.match(new RegExp(`${start}(.*?)${end}`))
  56. return res ? res[1] : null
  57. }
  58.  
  59. // 获取答案
  60. function getAnswer(columnId) {
  61. var html = $("html").html(),
  62. taskId = getStr(html,'&taskId=','`,')
  63.  
  64. $.ajax({
  65. url: _self.config.practice.host + _self.config.practice.practice + "?columnId="+ columnId + "&taskId=" + taskId,
  66. headers: _self.config.apiConfig.header,
  67. async: false,
  68. success: function (res) {
  69. const { data, status } = res;
  70. if (status === "0") {
  71. var question_data = res.data
  72. var questionBankList = data.questionBankList
  73. answer_list = questionBankList;
  74. upload(question_data)
  75. } else if (status === "1") {
  76. //无效的columnId(下个接口是chapterId)
  77. alert("请先学习当前模块");
  78. window.history.go(-1);
  79. } else if (status === "-2") {
  80. alert("请重新登陆");
  81. } else {
  82.  
  83. }
  84. },
  85. error: function (err) {
  86. }
  87. });
  88. }
  89.  
  90. // 答题操作
  91. function doQuestion(t) {
  92. var cur_topic = $('#currentTopic').text(),
  93. tol_topic = $('#totalTopic').text(),
  94. answer = answer_list[cur_topic - 1].answer;
  95. $('#exam_answer > div:nth-child(' + num[answer] + ')').click();
  96. if (cur_topic == tol_topic) {
  97. // 清除Interval的定时器
  98. clearInterval(t);
  99. setTimeout(function(){alert('答题完成')},time / 2)
  100. } else{
  101. setTimeout(function(){$('#next_question').click()},time / 2);
  102. };
  103. }
  104.  
  105. // 获取考试题目
  106. function getExam(){
  107. var html = $("html").html(),
  108. taskId = getStr(html,'taskId=','`,');
  109. $.ajax({
  110. url: _self.config.wexam.host + _self.config.wexam.getPaper + "?taskId=" + taskId,
  111. headers: _self.config.apiConfig.header,
  112. async: false,
  113. success: function (res) {
  114. const { data, status, message } = res;
  115. if (status === "0") {
  116. var question_data = res.data;
  117. var paper = question_data.paper;
  118. var paperInfo = paper.paperInfo;
  119. exam_list = paperInfo;
  120. } else {
  121. alert('获取考试题目失败!')
  122. }
  123. },
  124. error: function (err) {
  125. }
  126. });
  127. }
  128. // 考试答题操作
  129. function doExam(t){
  130. var cur_topic = $('#currentTopic').text(),
  131. tol_topic = $('#totalTopic').text(),
  132. questionInfo = exam_list[cur_topic - 1];
  133. $.ajax({
  134. url: 'https://api.gocos.cn/index.php/cxapi/xf/getAnswer?v=2',
  135. type: 'POST',
  136. data: {
  137. 'question': questionInfo.content,
  138. 'answerops':questionInfo.answerOptions,
  139. 'topicId': questionInfo.id
  140. },
  141. async: false,
  142. success: function (res) {
  143. if (res.code == 1) {
  144. var data = res.data;
  145. var answer = data[0].answer
  146. $('#exam_answer > div:nth-child(' + num[answer] + ')').click();
  147. } else {
  148. var msg = res.msg;
  149. alert(msg)
  150. }
  151. },
  152. error: function (err) {
  153. }
  154. });
  155. if (cur_topic == tol_topic) {
  156. // 清除Interval的定时器
  157. clearInterval(t);
  158. setTimeout(function(){alert('答题完成')},time / 2);
  159. } else{
  160. setTimeout(function(){$('#next_question').click()},time / 2);
  161. };
  162.  
  163. }
  164.  
  165. function upload(question_data) {
  166. $.ajax({
  167. url: 'https://api.gocos.cn/index.php/cxapi/xf/upload',
  168. type: 'POST',
  169. data: {'data': question_data},
  170. async: true,
  171. success: function (res) {
  172. },
  173. error: function (err) {
  174. }
  175. });
  176. }

QingJ © 2025

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