传智播客自动搜题

try to take over the world!

目前为 2021-03-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         传智播客自动搜题
// @namespace    http://stu.ityxb.com/writePaper/busywork/*
// @version      1
// @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 total = 0;//题目总数
var index = 0;//搜题索引

window.onload = function(){
questionObj = document.getElementsByClassName("question-title-box");
total = questionObj.length;
find(questionObj[index].innerText);
}
   



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);
                questionObj[index].innerText += "答案:"+ans;
                if(index < total-1)
                {
                 index = index + 1;
                    find(questionObj[index].innerText);

                }

            }
        })
    }