形势政策刷题 API2

起飞

Από την 23/04/2020. Δείτε την τελευταία έκδοση.

// ==UserScript==
// @name        形势政策刷题  API2
// @namespace   Violentmonkey Scripts
// @match       https://hfut.xuetangx.com/*
// @version     0.4
// @author      QuarkWitcher
// @grant       GM_xmlhttpRequest
// @require     https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js
// @require     https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js
// @description 起飞
// ==/UserScript==

let getedAnswer = {}

$(window).keydown(function (event) {
    String.prototype.replaceAll = function (s1, s2) {
        return this.replace(new RegExp(s1, "gm"), s2);
    }
    switch (event.key) {
        case 's':
            let lis = $('.paper-list>li');
            // 主体页面没有加载完
            if (lis.length == 0) {
                lpanel.html("还没加载完,请重试");
                alert("还没加载完,请重试");
                return false;
            }
            allNum = lis.length;
            blockGetAnswer(lis, 0)
    }
});

function blockGetAnswer(lis, index) {
    if (index < lis.length) {
        let question = $(lis[index]).find('span.content').text();
        getAnswer(question, lis[index]);
        setTimeout(function () { blockGetAnswer(lis, index + 1); }, 2000 + Math.floor(Math.random() * 2000));
    }
    else {
        var text = ''
        Object.keys(getedAnswer).forEach(function (key) {
            if (getedAnswer[key] == false) {
                text += key + ','
            }
        })
        if (text == '') {
            alert('全部完成')
        }
        else {
            alert("没有搜索到" + text)
            lis[index - 1].append(
                `   [全部完成${"没有搜索到" + text}]`
            )
        }
    }
}

function blockClick(lis, index) {
    if (index < lis.length) {
        if (!$(lis[index]).is(":checked")) {
            lis[index].click()
        }
        setTimeout(function () { blockClick(lis, index + 1); }, 3000 + Math.floor(Math.random() * 3000));
    }
}



function getAnswer(question, containerElement) {
    index = $(containerElement).find('span.num').text()
    getedAnswer[index] = false
    GM_xmlhttpRequest({
        method: 'GET',
        url: 'http://wk.bcaqfy.xin/cxapi?tm=' + encodeURIComponent(question),
        headers: {
            'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        },
        onload: function (xhr) {
            getStr = xhr.responseText.replaceAll("", "||")
            result = JSON.parse(getStr)
            answer = result.answer.split('||')
            containerElement.append(
                `>>>${result.answer}<<<`
            )
            answerInputElements = $(containerElement).find('input')
            console.log("====================================")
            console.log(result.tm)
            console.log(answer)
            clickList = []
            for (let i = 0; i < answerInputElements.length; i++) {
                for (let j = 0; j < answer.length; j++) {
                    if (answerInputElements[i].value == answer[j]) {
                        console.log("选中", answer[j])
                        clickList.push(answerInputElements[i])
                        getedAnswer[index] = true
                    }
                }
            }
            blockClick(clickList, 0)
        },
        ontimeout: function () {
            console.log('超时')
            containerElement.append(
                `>>> 获取失败 <<< `
            )
        }
    })
}