🏠 Home 

Greasy Fork is available in English.

奥鹏入学测试自动答题

奥鹏入学测试 https://exam.open.com.cn 自动答题脚本;先用任意帐号登陆 https://learn.open.com.cn ##才能自动答题。

  1. // ==UserScript==
  2. // @name 奥鹏入学测试自动答题
  3. // @namespace https://greasyfork.org/zh-CN/users/707063-genexy
  4. // @version 202109161202
  5. // @description 奥鹏入学测试 https://exam.open.com.cn 自动答题脚本;先用任意帐号登陆 https://learn.open.com.cn ##才能自动答题。
  6. // @author 流浪的蛊惑
  7. // @match *://*.open.com.cn/*
  8. // @grant GM_xmlhttpRequest
  9. // @run-at document-idle
  10. // ==/UserScript==
  11. function addXMLRequestCallback(callback){//监听请求
  12. var oldSend, i;
  13. if( XMLHttpRequest.callbacks ) {
  14. XMLHttpRequest.callbacks.push( callback );
  15. } else {
  16. XMLHttpRequest.callbacks = [callback];
  17. oldSend = XMLHttpRequest.prototype.send;
  18. XMLHttpRequest.prototype.send = function(){//监听发送
  19. for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) {
  20. XMLHttpRequest.callbacks[i]( this );
  21. }
  22. oldSend.apply(this, arguments);
  23. }
  24. XMLHttpRequest.prototype.wrappedSetRequestHeader=XMLHttpRequest.prototype.setRequestHeader;
  25. XMLHttpRequest.prototype.setRequestHeader = function(header, value) {//监听自定义主机头
  26. this.wrappedSetRequestHeader(header, value);
  27. if(!this.headers) {
  28. this.headers = {};
  29. }
  30. if(!this.headers[header]) {
  31. this.headers[header] = [];
  32. }
  33. this.headers[header].push(value);
  34. }
  35. }
  36. }
  37. function gGetData(url,item){
  38. GM_xmlhttpRequest({
  39. method: "get",
  40. url: url,
  41. onload: function(res){
  42. let data=JSON.parse(res.responseText);
  43. let choiceslist = data.data.Choices;
  44. let questionlist = new Array();
  45. let choicesIndex = [];
  46. choiceslist.forEach((iteam, index, array) =>{
  47. if (iteam.IsCorrect){
  48. for(let i=0;i<item.i6.length;i++){
  49. if(item.i6[i]==iteam.I2){
  50. choicesIndex.push(i);
  51. questionlist.push(iteam.I2);
  52. }
  53. }
  54. }
  55. });
  56. //直接定位当前试题
  57. let dom = document.querySelector("div[id='item_" + item.i1 + "']");
  58. //点击答案
  59. choicesIndex.forEach((iteam, index, array) =>{
  60. console.log(dom.getElementsByClassName("question-options")[0]);
  61. dom.getElementsByClassName("question-options")[0].getElementsByTagName("li")[iteam].click();
  62. });
  63. }
  64. });
  65. }
  66. //根据问题找出具体的id
  67. function initquestion(question){
  68. //遍历试题
  69. for(let i=0;i<question.sectionList.length;i++){
  70. let list = question.sectionList[i].questionList;
  71. list.forEach((item, index, array)=>{
  72. //调用答案接口
  73. let basturl = "https://learn.open.com.cn/StudentCenter/OnlineJob/GetQuestionDetail?itemBankId=${itemBankId}&questionId=${questionId}";
  74. let itemBankId = item.i4;
  75. let questionId = item.i1;
  76. let rquurl = basturl.replace("${itemBankId}", itemBankId).replace("${questionId}", questionId);
  77. gGetData(rquurl,item);
  78. });
  79. }
  80. }
  81. (function(){
  82. 'use strict';
  83. addXMLRequestCallback(function(xhr){
  84. xhr.addEventListener("load",function(){
  85. if (xhr.readyState == 4 && xhr.status == 200){
  86. console.log(xhr.responseURL);
  87. if (xhr.responseURL.includes("open.com.cn/v2/exam/paper")){//https://exam.open.com.cn/v2/exam/paper
  88. initquestion(JSON.parse(xhr.responseText));
  89. }
  90. }
  91. });
  92. });
  93. })();