Greasy Fork

Greasy Fork is available in English.

形势政策刷题 API2

2020/3/27 下午12:01:48

当前为 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.2
// @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 2020/3/27 下午12:01:48
// ==/UserScript==

let allNum = 0

$(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); }, 3000);
    }
}

function getAnswer(question, containerElement) {
    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])
                        answerInputElements[i].click()
                    }
                }
            }
        },
        ontimeout: function () {
            console.log('超时')
            containerElement.append(
                `>>> 获取失败 <<< `
            )
        }
    })
}