ceshi

自动从接口获取答案并自动填写

目前為 2022-03-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name ceshi
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.22
  5. // @description 自动从接口获取答案并自动填写
  6. // @author 曦月
  7. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js
  8. // @match https://learn.open.com.cn/StudentCenter/OnLineJob/TestPaper*
  9. // @match http://learn.open.com.cn/StudentCenter/MyWork/UndoneWork*
  10. // @license MIT
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. //全局问题
  15. let question;
  16. //请求的问题封装(方便根据id查找对应的对象)
  17. var map = {};
  18. //根据问题的id来获取答案封装
  19. var answer = {};
  20. var get_point = false;
  21.  
  22. // 封装ajax
  23. function addXMLRequestCallback(callback) {
  24. var oldSend, i;
  25. if (XMLHttpRequest.callbacks) {
  26. // we've already overridden send() so just add the callback
  27. XMLHttpRequest.callbacks.push(callback);
  28. } else {
  29. // create a callback queue
  30. XMLHttpRequest.callbacks = [callback];
  31. // store the native send()
  32. oldSend = XMLHttpRequest.prototype.send;
  33. // override the native send()
  34. XMLHttpRequest.prototype.send = function () {
  35. // process the callback queue
  36. // the xhr instance is passed into each callback but seems pretty useless
  37. // you can't tell what its destination is or call abort() without an error
  38. // so only really good for logging that a request has happened
  39. // I could be wrong, I hope so...
  40. // EDIT: I suppose you could override the onreadystatechange handler though
  41. for (i = 0; i < XMLHttpRequest.callbacks.length; i++) {
  42. XMLHttpRequest.callbacks[i](this);
  43. }
  44. // call the native send()
  45. oldSend.apply(this, arguments);
  46. }
  47. }
  48. }
  49.  
  50. let wrong = [];
  51.  
  52. //根据问题找出具体的id
  53. function initquestion(question) {
  54. //找出的问题数组
  55. $(".Test-Info-Right h2").text("自动答题中")
  56. let list = question.data.paperInfo.Items;
  57. let nums = 0
  58. wrong.forEach(item => {
  59. let bust = (new Date()).getTime();
  60. let t = (new Date()).getTime() + 20;
  61. let basturl = `https://learn.open.com.cn/StudentCenter/OnlineJob/GetQuestionDetail?bust=${bust}&itemBankId=${item.ItemBankId}&questionId=${item.QuestionId}&_=${t}`
  62. $.ajax({
  63. url: basturl,
  64. type: 'GET',
  65. dataType: 'json',
  66. success(data) {
  67. if (data.status === 1) {
  68. select.eq(0).click()
  69. return
  70. }
  71. var choices_list = data.data.Choices
  72. list.forEach(row => {
  73. if (data.data.I2 === row.I2) {
  74. var select = $(`div [itemid="${row.I1}"] li`)
  75. for (var i = 0; i < choices_list.length; i++) {
  76. if (choices_list[i].IsCorrect) {
  77. select.eq(i).click()
  78. }
  79. }
  80. }
  81. })
  82. }
  83. });
  84. })
  85. }
  86.  
  87. // 获取url参数信息
  88. function getQueryVariable(variable) {
  89. var query = window.location.search.substring(1);
  90. var vars = query.split("&");
  91. for (var i = 0; i < vars.length; i++) {
  92. var pair = vars[i].split("=");
  93. if (pair[0] === variable) {
  94. return pair[1];
  95. }
  96. }
  97. return false;
  98. }
  99.  
  100. (function () {
  101. 'use strict';
  102. let url = window.location.href;
  103. if (url.includes("StudentCenter/OnLineJob/TestPaper")) {
  104. console.log("开始答题");
  105. addXMLRequestCallback(function (xhr) {
  106. xhr.addEventListener("load", function () {
  107. if (xhr.readyState === 4 && xhr.status === 200 && !get_point) {
  108. if (xhr.responseURL.includes("homeworkapi.open.com.cn/getHomework")) {
  109. // console.log(xhr.responseURL);
  110. // 查询到接口后阻止继续监听
  111. get_point = true
  112. question = JSON.parse(xhr.responseText);
  113. console.log(question);
  114.  
  115. let bust = (new Date()).getTime();
  116. let rangeKey = JSON.parse(question.data.stuHomeWorkInfo.rangeKey);
  117. let courseExerciseId = getQueryVariable('courseExerciseId');
  118. let t = (new Date()).getTime();
  119. // 获取错题记录
  120. let allWrongList = `https://learn.open.com.cn/StudentCenter/OnlineJob/GetWrongQuestions?bust=${bust}&courseid=${rangeKey.CourseId}&courseExerciseId=${courseExerciseId}&studentHomeworkId=${question.data.stuHomeWorkInfo.studentHomeworkId}&homeCourseId=${question.data.stuHomeWorkInfo.courseId}&_=${t}`
  121.  
  122. $.ajax({
  123. url: allWrongList,
  124. type: 'GET',
  125. dataType: 'json',
  126. success(dataasd) {
  127. if (dataasd.status === 0) {
  128. wrong = dataasd.data.Rows
  129. initquestion(question);
  130. } else {
  131. alert(dataasd.message)
  132. }
  133. }
  134. });
  135. }
  136. }
  137. });
  138. });
  139. } else {
  140. // 未完成作业列表
  141. console.log("作业列表");
  142. $("td a").each(function (index, el) {
  143. if ($(el).text() === "做作业") {
  144. let url = $(el).attr('href')
  145. open_new_window(url)
  146. }
  147. })
  148.  
  149. function open_new_window(url) {
  150. setTimeout(function () {
  151. window.open(url, '_blank')
  152. }, 3000)
  153. }
  154. }
  155. })();

QingJ © 2025

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