Greasy Fork

Greasy Fork is available in English.

形势政策刷题 API2

起飞

当前为 2020-04-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        形势政策刷题  API2
// @namespace   Violentmonkey Scripts
// @match       https://hfut.xuetangx.com/*
// @version     0.3
// @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) {
    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')
            index = $(containerElement).find('span.num').text()
            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(
                `>>> 获取失败 <<< `
            )
        }
    })
}