传智播客自动搜题

try to take over the world!

目前为 2021-03-13 提交的版本,查看 最新版本

// ==UserScript==
// @name         传智播客自动搜题
// @namespace    http://stu.ityxb.com/writePaper/busywork/*
// @version      2
// @description  try to take over the world!
// @author       广东东软学院林鑫松同学
// @match        http://stu.ityxb.com/writePaper/busywork/*
// @grant        GM_xmlhttpRequest
// @connect      *
// ==/UserScript==

//http://api.902000.xyz:88/wkapi.php?q=

var questionObj;
var radioDiv;
var total = 0;//题目总数
var index = 0;//搜题索引
var answerArray = new Array();//搜索得出的答案库存
window.onload = function(){
questionObj = document.getElementsByClassName("question-title-box");
radioDiv = document.getElementsByClassName("el-radio__label");
total = questionObj.length;
find(questionObj[index].innerText);




var bgdiv = document.getElementById("writeQuestion");
bgdiv.style.background = "url('https://s1.ax1x.com/2020/10/09/0BX4xI.png')";


}
   



function find(q){
        GM_xmlhttpRequest({
            method: 'POST',
            url: 'http://api.902000.xyz:88/wkapi.php',
            headers: {
                'Content-type': 'application/x-www-form-urlencoded'
            },
            data: 'q='+ encodeURIComponent(q),
            timeout: 1000,
            onload:function(xhr)
            {
                var str = xhr.responseText;
                console.log(str);
                var open = str.indexOf("answer");
                str = str.substring(open);
                open = str.indexOf("answer") + 9;
                var end = str.indexOf(",") - 1;
                var ans = str.substring(open,end);
                answerArray.push(ans);
                questionObj[index].innerText += "答案:"+ans;
                questionObj[index].style.color = "red";
                questionObj[index].style.fontSize = "28px";
                if(index < total-1)
                {
                 index = index + 1;
                    find(questionObj[index].innerText);
                }
                else{

                        for(let i = 0;i<radioDiv.length;i++)
    {
        if(radioDiv[i].children.length > 0)//单选题
        {
            let str = radioDiv[i].children[0].innerText;
            str = str.substring(2);//删除选项前缀
            for(let j = 0;j<answerArray.length;j++)
            {
            if(answerArray[j] == str)
            {
              str +="✔"
            }

            }
            console.log(str);
        }
        else{//判断题
            let choiceStr = radioDiv[i].innerText;
        console.log(choiceStr);
        }

    }



                }

            }
        })
    }