自动做题工具

自动做题工具适用于链接为 https://kc.jxjypt.cn/ 的成教网站

// ==UserScript==
// @name         自动做题工具
// @namespace    http://tampermonkey.net/
// @version      v1.0.1
// @description  自动做题工具适用于链接为 https://kc.jxjypt.cn/ 的成教网站
// @author       提灯者
// @match        https://kc.jxjypt.cn/paper/*
// @match        https://kc.jxjypt.cn/classroom/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=jxjypt.cn
// @grant        none
// @license MIT
// ==/UserScript==
if(location.href.indexOf("classroom")>0){
    document.addEventListener('visibilitychange', function() {
        // 用户息屏、或者切到后台运行 (离开页面)
        if (document.visibilityState === 'hidden') {
        }
        // 用户打开或回到页面
        if (document.visibilityState === 'visible') {
            window.location.reload()
        }
    })
}

$(document).ready(function () {
    $("body").append(`<script >
if (localStorage.getItem("loadState")==null){
  localStorage.setItem("loadState","false");
}
    let loadState=localStorage.getItem("loadState");
function updateState(){
if (loadState=="false"){
  localStorage.setItem("loadState","true");
        alert("自动答题已开启")
        window.location.reload()
}else {
        alert("自动答题已关闭")
        window.location.reload()
  localStorage.setItem("loadState","false");
}
}
window.onload=function(){
    const czctList = $(".czct")
    if(loadState=="true"){
    for(let czctListIndex = 0;czctListIndex<czctList.length;czctListIndex++){
        if($(czctList[czctListIndex]).find("a").length==1){
            setTimeout(function(){
           console.log ($(czctList[czctListIndex]).find("a"))
                $(czctList[czctListIndex]).find("a")[0].click()
            },1000)
            break
        }
    }
    }
}
</script>`)
    $("body").append(`<div onclick='updateState()' style='position:fixed;top:0;background:#000;color:#fff;padding:10px;z-index:999'>点击切换自动答题状态</div>`)
    let loadState=localStorage.getItem("loadState");
    if(loadState=="false"){
        return
    }
    const ll = $("#questionModule>ul li");
    for (let i = 0; i < ll.length; i++) {
        const $ti = $(ll[i]);
        const html = $ti.html();
        if (html.indexOf("单选题") !== -1 || html.indexOf("多选题") !== -1) {
            $ti.find(".zkjx").click();
            setTimeout(function () {
                const tt = $ti.find(".solution").text();
                let answer = tt.substring(tt.indexOf("释疑:") + 3, tt.indexOf("解析")).trim();
                let option = $ti.find(".sub-answer.sub-picon-no.clearfix>dd");
                if (answer.length > 1) {
                    for (let j = 0; j < option.length; j++) {
                        for (let k = 0; k < answer.length; k++) {
                            let answerOption = $(option[j]).attr("data-value")
                            if (answerOption == answer[k]) {
                                $(option[j]).click();
                            }
                        }
                    }
                    return;
                }
                for (let j = 0; j < option.length; j++) {
                    let answerOption = $(option[j]).attr("data-value")
                    if (answerOption == answer) {
                        $(option[j]).click();
                        break;
                    }
                }
            }, 500)
        }else if(html.indexOf("判断题") !== -1 ){
            /*const tt = $ti.find(".sub-content>.solution").text();
                console.log( $ti.find(".sub-content>.solution")[0].firstChild)*/
            setTimeout(function () {
                const tt = $ti.find(".sub-content>.solution").text();
                let answer = tt.substring(tt.indexOf("释疑:")+3, tt.indexOf("解析")).trim();
                console.log( answer=="错")
                answer=answer=="错"?"错误":"正确"
                console.log( answer)
                let option = $ti.find(".sub-answer.sub-picon-no.clearfix>dd");
                for (let j = 0; j < option.length; j++) {
                    let answerOption = $(option[j]).attr("data-value")
                    if (answerOption == answer) {
                        $(option[j]).click();
                        break;
                    }
                }
            }, 600)
            /*let answer = tt.substring(tt.indexOf("释疑:"), tt.indexOf("解析")).trim();
                answer=answer.indexOf("错")>0?"错误":"正确"
                    let option = $ti.find(".sub-answer.sub-picon-no.clearfix>dd");
                    for (let j = 0; j < option.length; j++) {
                        let answerOption = $(option[j]).attr("data-value")
                        if (answerOption == answer) {
                            $(option[j]).click();
                            break;
                        }
                    }*/
            console.log(111)
        } else /*if (html.indexOf("分析题") !== -1 || html.indexOf("简答题") !== -1 || html.indexOf("论述题") !== -1)*/ {
            $ti.find(".zkjx").click();
            setTimeout(function () {
                const tt = $ti.find(".solution").text();
                let answer = tt.substring(tt.indexOf("释疑:") + 3, tt.indexOf("解析")).trim();
                $ti.find(".e__textarea").text(answer)
            }, 500)
        }
    }
    let i = setTimeout(function () {
        $("#btn_submit").click()
        $("#kap_input").focus()
        $("#kap_input").on({
            "keydown":function (e){
                e.stopPropagation()
                console.log(11)
                if(e.keyCode === 13){
                    $(".layui-layer-btn0").click();
                }
            }
        })
        // layui-layer-btn0 #kaptcha_img
        $(document).on({
            "keydown":function (e){
                $(".layui-layer-btn0").click();
            }
        })
        clearTimeout(i)
    }, 2000)
    })