驾考宝典,模拟考试自动做题

驾考宝典模拟考试自动做题,现已兼容科目一和科目四模拟考试

  1. // ==UserScript==
  2. // @name 驾考宝典,模拟考试自动做题
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description 驾考宝典模拟考试自动做题,现已兼容科目一和科目四模拟考试
  6. // @author ZouYS
  7. // @match https://www.jiakaobaodian.com/mnks/exam/*.html
  8. // @icon https://www.jiakaobaodian.com/favicon.ico
  9. // @grant GM_addStyle
  10. // @run-at document-start
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. var quesList=[];
  18. //劫持函数
  19. function addXMLRequestCallback(callback) {
  20. // oldSend 旧函数 i 循环
  21. var oldSend, i;
  22. //判断是否有callbacks变量
  23. if (XMLHttpRequest.callbacks) {
  24. //判断XMLHttpRequest对象下是否存在回调列表,存在就push一个回调的函数
  25. XMLHttpRequest.callbacks.push(callback);
  26. } else {
  27. //如果不存在则在xmlhttprequest函数下创建一个回调列表/callback数组
  28. XMLHttpRequest.callbacks = [callback];
  29. // 保存 XMLHttpRequest 的send函数
  30. oldSend = XMLHttpRequest.prototype.send;
  31. //获取旧xml的send函数,并对其进行劫持(替换) function()则为替换的函数
  32. //以下function函数是一个替换的例子
  33. XMLHttpRequest.prototype.send = function () {
  34. // 把callback列表上的所有函数取出来
  35. for (i = 0; i < XMLHttpRequest.callbacks.length; i++) {
  36. // 把this传入进去
  37. XMLHttpRequest.callbacks[i](this);
  38. }
  39. //循环回调xml内的回调函数
  40. // 调用旧的send函数 并传入this 和 参数
  41. oldSend.apply(this, arguments);
  42. //由于我们获取了send函数的引用,并且复写了send函数,这样我们在调用原send的函数的时候,需要对其传入引用,而arguments是传入的参数
  43. };
  44. }
  45. }
  46. //传入回调 接收xhr变量
  47. addXMLRequestCallback(function (xhr) {
  48. //调用劫持函数,填入一个function的回调函数
  49. //回调函数监听了对xhr调用了监听load状态,并且在触发的时候再次调用一个function,进行一些数据的劫持以及修改
  50. xhr.addEventListener("load", function () {
  51. // 输入xhr所有相关信息
  52. //console.log(xhr);
  53. if (xhr.readyState == 4 && xhr.status == 200) {
  54. // 如果xhr请求成功 则返回请求路径
  55. //console.log("函数1", xhr.responseURL);
  56. //console.log(xhr.response)
  57. if(xhr.responseURL.includes('https://api2.jiakaobaodian.com/api/open/question/question-list.htm')){
  58. //console.log(JSON.parse(xhr.response))
  59. let list=JSON.parse(xhr.response);
  60. quesList=[...quesList,...(list.data)]
  61. console.log(quesList)
  62. }
  63. }
  64. });
  65.  
  66. });
  67.  
  68. async function domain(){
  69. let index=0;
  70. for(index;index<quesList.length;index++)
  71. {
  72. await sleep(200);
  73. //点击并查询正确答案
  74. let questionId=document.querySelector('[data-questionid]').getAttribute('data-questionid')
  75. let result=quesList.filter(item => item.questionId==questionId)
  76. result=result[0]
  77. let answer=result.answer.toString()
  78. //optionType 0 判断
  79. //optionType 1 单选
  80. //optionType 2 多选
  81. console.log(`第${index+1}题:`)
  82.  
  83. let answers=new Map();
  84. answer=parseInt(answer);
  85. let bitPos=4;
  86. for(let i=0;i<4;i++){
  87. let mask=1 << (bitPos+i);
  88. if(answer & mask){
  89. // answers+=result['option' +String.fromCharCode('A'.charCodeAt(0) + i)]
  90. answers.set(result['option' +String.fromCharCode('A'.charCodeAt(0) + i)],true)
  91. }
  92. }
  93. /*else{
  94. switch(answer)
  95. {
  96. case '16':
  97. answer=result.optionA
  98. break;
  99. case '32':
  100. answer=result.optionB
  101. break;
  102. case '64':
  103. answer=result.optionC
  104. break;
  105. case '128':
  106. answer=result.optionD
  107. break;
  108. default:
  109. answer='error get answer'
  110. }
  111. }*/
  112. console.log(answers)
  113. let letter='A'
  114. var container = await document.querySelector('.answer-w');
  115. if (container) {
  116. var paragraphs =await container.querySelectorAll('p'); // 获取父元素内部的所有 <p> 元素
  117. await paragraphs.forEach( function(paragraph) {
  118. if(answers.has(paragraph.textContent.slice(paragraph.textContent.indexOf('、')+1))){
  119. letter=paragraph.textContent.split('、')[0]
  120. let selector = '.select-w.right .select-lable[data-key="' + letter + '"]';
  121. // 使用构建好的选择器字符串来获取相应的按钮元素
  122. let button = document.querySelector(selector);
  123. button.click();
  124. if(result.optionType.toString()!=='2'){
  125. return true;
  126. }
  127. }
  128. });
  129. //多选确定
  130. let btnOk=document.querySelector('.btn-answer-ok')
  131. if(btnOk){
  132. btnOk.click();
  133. }
  134. }
  135.  
  136. }
  137.  
  138. }
  139. function fuc_show() {
  140. // let is_show=document.querySelector('#myWindow')
  141. if (quesList.length===100 || quesList.length===50) {
  142. domain().then(r =>{} );
  143.  
  144. }
  145. else {
  146. alert('wrong init!Please refresh again!')
  147. }
  148. }
  149. async function sleep(time) {
  150. console.log('睡眠' + time / 1000 + 's')
  151. //if(time < 1000)time=1000
  152. return await new Promise((resolve) => setTimeout(resolve, time));
  153. }
  154. window.onload=()=>{
  155. let css = `
  156.  
  157. .mybtn2 {
  158. z-index: 9999999999;
  159. position: absolute;
  160. top: 300px;
  161. font-size: inherit;
  162. font-family: inherit;
  163. color: white;
  164. width: 100px;
  165. height: 50px;
  166. padding: 0.5em 1em;
  167. outline: none;
  168. border: none;
  169. background-color: hsl(236, 32%, 26%);
  170. overflow: hidden;
  171. transition: color 0.4s ease-in-out;
  172. }
  173.  
  174. .mybtn2::before,.mybtn1::before {
  175. content: '';
  176. z-index: -1;
  177. position: absolute;
  178. top: 100%;
  179. right: 100%;
  180. width: 1em;
  181. height: 1em;
  182. border-radius: 50%;
  183. background-color: #3cefff;
  184. transform-origin: center;
  185. transform: translate3d(50%, -50%, 0) scale3d(0, 0, 0);
  186. transition: transform 0.45s ease-in-out;
  187. }
  188.  
  189. .mybtn2:hover,.mybtn1:hover {
  190. cursor: pointer;
  191. color: #161616;
  192. }
  193.  
  194. .mybtn2:hover::before,.mybtn1:hover::before {
  195. transform: translate3d(50%, -50%, 0) scale3d(15, 15, 15);
  196. }`;
  197. GM_addStyle(css);
  198. let showWindow = document.createElement('button')
  199. showWindow.classList.add('mybtn2')
  200. showWindow.innerText='点击自动开始答题';
  201. document.body.appendChild(showWindow)
  202. showWindow.addEventListener('click', fuc_show)
  203.  
  204.  
  205. }
  206. })();

QingJ © 2025

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