一个网站建设爱好者,技术交流,相互学习
当前位置:首页>>我的自考
某自学网站课后习题自动答题提交的油猴脚本
发布时间:2023-07-25 10:46:47 栏目:我的自考 阅读量:1989 作者:南方姑娘

某自学网站课后习题自动答题提交的油猴脚本,需要先在浏览器安装油猴

// ==UserScript==
// @name         [当前使用]-[单选+判断]做题脚本
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://cqlg.360xkw.com/gxplatform/gxlearningcenter/questionBank.html?paperId=*
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    // Your code here...
    // 单选题
    var single_index=1;
    var isSingle = false;
    // 判断题
    var judge_index=1;
    var isJudge = false;
    var time = setInterval(start, 5000);
    function start(){
        if(isSingle && isJudge){
            clearInterval(time);
            if($('#DXsubmitPaper').css('display') != 'none'){
               $('#DXsubmitPaper').click();
               setTimeout(function(){
                   $('a.layui-layer-btn0').click();
               }, 2000);
            }
            if($('#submitPaper').css('display') != 'none'){
               $('#submitPaper').click();
            }
        }
        if(!isSingle){
           singleCode();
        }
        if(isSingle){
           judgeCode();
        }
    }
    // 单选题
    function singleCode(){
        var singleNumber = $('.single_list div.tm').length;
        if(single_index > singleNumber){
            isSingle = true;
            return;
        }
        var singleEle = $('#t'+single_index+'').find('.Parsing').find('.parsingInfo:first');
        var answerText = $.trim(singleEle.text());
        console.log('答案是:', $.trim(answerText));
        var ele = $('#t'+single_index+' .redio li');
        select(answerText, ele);
        single_index++;
    }
    // 判断题
    function judgeCode(){
        var judgeNumber = $('.judge_list div.tm').length;
        if(judge_index > judgeNumber || judgeNumber == 0){
            isJudge = true;
            return;
        }
        var singleEle = $('#p'+judge_index+'').find('.Parsing').find('.parsingInfo:first');
        var answerText = $.trim(singleEle.text());
        console.log('答案是:', $.trim(answerText));
        var ele = $('#p'+judge_index+' .redio li');
        select(answerText, ele);
        judge_index++;
    }
    // 执行做题
    function select(answerText,ele){
        switch(answerText){
            case 'A':
                ele.eq(0).css('color', 'red');
                ele.eq(0).click();
                break;
            case 'B':
                ele.eq(1).css('color', 'red');
                ele.eq(1).click();
                break;
            case 'C':
                ele.eq(2).css('color', 'red');
                ele.eq(2).click();
                break;
            case 'D':
                ele.eq(3).css('color', 'red');
                ele.eq(3).click();
                break;
            default:
                console.log('没有答案');
        }
    }
})();

评论:

IT视频教程
Copyright © web小工匠 保留所有权利. 渝ICP备15008469号 网站地图