优学院答题

优学院自动答题,配合优学院看视频脚本使用

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/394494/774223/%E4%BC%98%E5%AD%A6%E9%99%A2%E7%AD%94%E9%A2%98.js

  1. // ==UserScript==
  2. // @name 优学院答题
  3. // @namespace Brush-JIM
  4. // @version 2020.01.01
  5. // @description 优学院自动答题,配合优学院看视频脚本使用
  6. // @author Brush-JIM
  7. // @require https://code.jquery.com/jquery-3.3.1.min.js
  8. // @grant unsafeWindow
  9. // ==/UserScript==
  10.  
  11. function Short_Answer_Question(questionid, data) {
  12. $.ajax({
  13. url: 'https://api.ulearning.cn/questionAnswer/' + /question(\d*)/gi.exec(questionid)[1],
  14. async: false,
  15. success: function (result) {
  16. let Inputs = data.querySelectorAll('textarea');
  17. let evt = document.createEvent("Events");
  18. evt.initEvent("change", true, true);
  19. if (Inputs.length == 1) {
  20. if (result['correctreply'] != '' && result['correctreply'] != null) {
  21. Inputs[0].value = result['correctreply']
  22. } else if (result['correctAnswerList'].length != 0) {
  23. if (result['correctAnswerList'][0] != '' && result['correctAnswerList'][0] != null) {
  24. Inputs[0].value = result['correctAnswerList'][0]
  25. } else {
  26. Inputs[0].value = '答案言之有理即可'
  27. }
  28. } else {
  29. Inputs[0].value = '答案言之有理即可'
  30. }
  31. Inputs[0].dispatchEvent(evt);
  32. } else if (Inputs.length > 1) {
  33. if (result['correctAnswerList'].length === Inputs.length) {
  34. for (let g = 0; Inputs.length > g; g++) {
  35. Inputs[g].value = result['correctAnswerList'][g].replace(/<([\s\S]*?)>/gi, '');
  36. Inputs[g].dispatchEvent(evt);
  37. }
  38. } else if (result['correctAnswerList'].length > Inputs.length) {
  39. for (let g = 0; Inputs.length > g; g++) {
  40. Inputs[g].value = result['correctAnswerList'][g].replace(/<([\s\S]*?)>/gi, '');
  41. Inputs[g].dispatchEvent(evt);
  42. }
  43. } else if (result['correctAnswerList'].length < Inputs.length) {
  44. for (let g = 0; result['correctAnswerList'].length > g; g++) {
  45. Inputs[g].value = result['correctAnswerList'][g].replace(/<([\s\S]*?)>/gi, '');
  46. Inputs[g].dispatchEvent(evt);
  47. }
  48. } else { ;
  49. }
  50. } else { ;
  51. }
  52. },
  53. error: function () {
  54. console.log('Ajax Failure.');
  55. }
  56. })
  57. }
  58.  
  59. function Fill_In_The_Blanks(questionid, data) {
  60. $.ajax({
  61. url: 'https://api.ulearning.cn/questionAnswer/' + /question(\d*)/gi.exec(questionid)[1],
  62. async: false,
  63. success: function (result) {
  64. if (result['correctAnswerList'].length != 0) {
  65. let Inputs = data.querySelectorAll('input[type="text"]');
  66. if (result['correctAnswerList'].length === Inputs.length) {
  67. for (let f = 0; Inputs.length > f; f++) {
  68. if (result['correctAnswerList'][f].search(/\/\//) === -1) {
  69. Inputs[f].value = result['correctAnswerList'][f];
  70. } else {
  71. Inputs[f].value = /([\s\S]*)\/\//gi.exec(result['correctAnswerList'][f])[1]
  72. }
  73. }
  74. } else if (result['correctAnswerList'].length > Inputs.length) {
  75. for (let f = 0; Inputs.length > f; f++) {
  76. if (result['correctAnswerList'][f].search(/\/\//) === -1) {
  77. Inputs[f].value = result['correctAnswerList'][f];
  78. } else {
  79. Inputs[f].value = /([\s\S]*)\/\//gi.exec(result['correctAnswerList'][f])[1]
  80. }
  81. }
  82. } else if (result['correctAnswerList'].length < Inputs.length) {
  83. for (let f = 0; result['correctAnswerList'].length > f; f++) {
  84. if (result['correctAnswerList'][f].search(/\/\//) === -1) {
  85. Inputs[f].value = result['correctAnswerList'][f];
  86. } else {
  87. Inputs[f].value = /([\s\S]*)\/\//gi.exec(result['correctAnswerList'][f])[1]
  88. }
  89. }
  90. } else { ;
  91. }
  92. }
  93. },
  94. error: function () {
  95. console.log('Ajax Failure.');
  96. }
  97. })
  98. }
  99.  
  100. function True_Or_False(questionid, data) {
  101. $.ajax({
  102. url: 'https://api.ulearning.cn/questionAnswer/' + /question(\d*)/gi.exec(questionid)[1],
  103. async: false,
  104. success: function (result) {
  105. if (result['correctAnswerList'].length != 0) {
  106. let Choose = undefined;
  107. if (result['correctAnswerList'][0] === 'false') {
  108. Choose = false;
  109. } else if (result['correctAnswerList'][0] === 'true') {
  110. Choose = true;
  111. } else {
  112. console.log('Unknown Choice.');
  113. return undefined;
  114. }
  115. if (Choose === true && data.querySelector('[class="choice-btn right-btn"]') != null) {
  116. data.querySelector('[class="choice-btn right-btn"]').click();
  117. } else if (Choose === false && data.querySelector('[class="choice-btn wrong-btn"]') != null) {
  118. data.querySelector('[class="choice-btn wrong-btn"]').click();
  119. } else if (Choose === true && data.querySelector('[class="choice-btn right-btn selected"]') != null) { ;
  120. } else if (Choose === false && data.querySelector('[class="choice-btn wrong-btn selected"]') != null) { ;
  121. } else {
  122. console.log('Unknown Error.');
  123. }
  124. }
  125. },
  126. error: function () {
  127. console.log('Ajax Failure.');
  128. }
  129. })
  130. }
  131.  
  132. function Multiple_Choices(questionid, data) {
  133. $.ajax({
  134. url: 'https://api.ulearning.cn/questionAnswer/' + /question(\d*)/gi.exec(questionid)[1],
  135. async: false,
  136. success: function (result) {
  137. if (result['correctAnswerList'].length != 0) {
  138. let Reset_Choices = data.querySelectorAll('div[id^="choice"] div[class="checkbox selected"]');
  139. for (let e = 0; Reset_Choices.length > e; e++) {
  140. Reset_Choices[e].click();
  141. }
  142. let Choices = data.querySelectorAll('div[id^="choice"]');
  143. for (let c = 0; Choices.length > c; c++) {
  144. let Option = Choices[c].querySelector('div[class="option"]').innerText.replace(/\./, '');
  145. for (let d = 0; result['correctAnswerList'].length > d; d++) {
  146. if (Option === result['correctAnswerList'][d]) {
  147. Choices[c].click();
  148. }
  149. }
  150. }
  151. }
  152. },
  153. error: function () {
  154. console.log('Ajax Failure.');
  155. }
  156. })
  157. }
  158.  
  159. function Single_Choice_Question(questionid, data) {
  160. $.ajax({
  161. url: 'https://api.ulearning.cn/questionAnswer/' + /question(\d*)/gi.exec(questionid)[1],
  162. async: false,
  163. success: function (result) {
  164. if (result['correctAnswerList'].length != 0) {
  165. let Choices = data.querySelectorAll('div[id^="choice"]');
  166. for (let c = 0; Choices.length > c; c++) {
  167. let Option = Choices[c].querySelector('div[class="option"]').innerText.replace(/\./, '');
  168. if (Option === result['correctAnswerList'][0]) {
  169. Choices[c].querySelector('div[class="option"]').click();
  170. break;
  171. }
  172. }
  173. }
  174. },
  175. error: function () {
  176. console.error('Ajax Failure.');
  177. }
  178. })
  179. }
  180.  
  181. function answer() {
  182. $('button[type="button"][class="btn-hollow btn-redo"]').click()
  183. var data = {};
  184. for (let a = 0; $('div[id^="question"]').length > a; a++) {
  185. if ($('div[id^="question"]:eq(' + a + ') div[id^="question"]').length == 0) {
  186. let questionid = $('div[id^="question"]:eq(' + a + ')')[0].id;
  187. if (/question(\d+)/gi.test(questionid) == true) {
  188. data[questionid] = $('div[id^="question"]:eq(' + a + ')')[0];
  189. } else { ;
  190. }
  191. } else { ;
  192. }
  193. }
  194. var data_1 = {};
  195. for (let key in data) {
  196. let Type = data[key].querySelector('span[class="question-type-tag"]');
  197. if (Type === undefined) {
  198. console.log('Unknown Type.');
  199. } else {
  200. data_1[key] = {};
  201. data_1[key]['Type'] = Type.innerText;
  202. data_1[key]['Location'] = data[key];
  203. }
  204. }
  205. for (let key_1 in data_1) {
  206. let Type_1 = data_1[key_1]['Type'];
  207. let Location_1 = data_1[key_1]['Location'];
  208. if (Type_1 === '单选题') {
  209. Single_Choice_Question(key_1, Location_1);
  210. } else if (Type_1 === '多选题') {
  211. Multiple_Choices(key_1, Location_1);
  212. } else if (Type_1 === '判断题') {
  213. True_Or_False(key_1, Location_1);
  214. } else if (Type_1 === '填空题') {
  215. Fill_In_The_Blanks(key_1, Location_1);
  216. } else if (Type_1 === '简答题') {
  217. Short_Answer_Question(key_1, Location_1);
  218. } else {
  219. console.log('Unknown Type.');
  220. }
  221. }
  222. $('[data-bind="text: $root.i18nMessageText().submit, click: submitQuiz"]').click()
  223. }

QingJ © 2025

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