Greasy Fork

Greasy Fork is available in English.

奥鹏入学测试自动答题

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         奥鹏入学测试自动答题
// @namespace    http://greasyfork.icu/zh-CN/users/707063-genexy
// @version      202109161202
// @description  奥鹏入学测试 https://exam.open.com.cn 自动答题脚本;先用任意帐号登陆 https://learn.open.com.cn 平台才能自动答题。
// @author       流浪的蛊惑
// @match        *://*.open.com.cn/*
// @grant        GM_xmlhttpRequest
// @run-at       document-idle
// ==/UserScript==
function addXMLRequestCallback(callback){//监听请求
    var oldSend, i;
    if( XMLHttpRequest.callbacks ) {
        XMLHttpRequest.callbacks.push( callback );
    } else {
        XMLHttpRequest.callbacks = [callback];
        oldSend = XMLHttpRequest.prototype.send;
        XMLHttpRequest.prototype.send = function(){//监听发送
            for( i = 0; i < XMLHttpRequest.callbacks.length; i++ ) {
                XMLHttpRequest.callbacks[i]( this );
            }
            oldSend.apply(this, arguments);
        }
        XMLHttpRequest.prototype.wrappedSetRequestHeader=XMLHttpRequest.prototype.setRequestHeader;
        XMLHttpRequest.prototype.setRequestHeader = function(header, value) {//监听自定义主机头
            this.wrappedSetRequestHeader(header, value);
            if(!this.headers) {
                this.headers = {};
            }
            if(!this.headers[header]) {
                this.headers[header] = [];
            }
            this.headers[header].push(value);
        }
    }
}
function gGetData(url,item){
    GM_xmlhttpRequest({
        method: "get",
        url: url,
        onload: function(res){
            let data=JSON.parse(res.responseText);
            let choiceslist = data.data.Choices;
            let questionlist = new Array();
            let choicesIndex = [];
            choiceslist.forEach((iteam, index, array) =>{
                if (iteam.IsCorrect){
                    for(let i=0;i<item.i6.length;i++){
                        if(item.i6[i]==iteam.I2){
                            choicesIndex.push(i);
                            questionlist.push(iteam.I2);
                        }
                    }
                }
            });
            //直接定位当前试题
            let dom = document.querySelector("div[id='item_" + item.i1 + "']");
            //点击答案
            choicesIndex.forEach((iteam, index, array) =>{
                console.log(dom.getElementsByClassName("question-options")[0]);
                dom.getElementsByClassName("question-options")[0].getElementsByTagName("li")[iteam].click();
            });
        }
    });
}
//根据问题找出具体的id
function initquestion(question){
    //遍历试题
    for(let i=0;i<question.sectionList.length;i++){
        let list = question.sectionList[i].questionList;
        list.forEach((item, index, array)=>{
            //调用答案接口
            let basturl = "https://learn.open.com.cn/StudentCenter/OnlineJob/GetQuestionDetail?itemBankId=${itemBankId}&questionId=${questionId}";
            let itemBankId = item.i4;
            let questionId = item.i1;
            let rquurl = basturl.replace("${itemBankId}", itemBankId).replace("${questionId}", questionId);
            gGetData(rquurl,item);
        });
    }
}
(function(){
    'use strict';
    addXMLRequestCallback(function(xhr){
        xhr.addEventListener("load",function(){
            if (xhr.readyState == 4 && xhr.status == 200){
                console.log(xhr.responseURL);
                if (xhr.responseURL.includes("open.com.cn/v2/exam/paper")){//https://exam.open.com.cn/v2/exam/paper
                    initquestion(JSON.parse(xhr.responseText));
                }
            }
        });
    });
})();