学堂云3.0 学堂在线 作业解析|自动作答|后台刷课

收录 54

仅支持各高校独立的学堂云3.0慕课平台,公共课程平台可能不适用 脚本有风险,请谨慎使用!
功能
查询答案
自动答题
自动切换标清和2倍速
后台刷课
页面标题显示播放进度

声明:脚本为油猴脚本,需要自行安装油猴插件,不提供咨询。
脚本为网上搜集而来,仅供学习研究,如果不能使用请自行百度寻找其他适合您的脚本,谢谢

使用方法:
答题界面按S查询答案,查询完成后按N自动作答,没反应请开启大写锁定或刷新重试。 理论上可查询所有题目。
如出现答案顺序错误,请打开匹配功能(修改questions_match的值为1) 有需要可自行设置各功能的开启状态 默认为顺序播放,如只需播放未完成视频,请开启智能播放

    // ==UserScript==
    // @name        学堂云3.0 学堂在线 作业解析|自动作答|后台刷课 
    // @namespace   http://tampermonkey.net/
    // @match       https://*.xuetangx.com/lms
    // @version     3.0
    // @author      Fluke limoure
    // @description
    // @description 作业提前解析|自动作答|后台倍速播放
    // ==/UserScript==

//全局参数,1为开启,0为关闭
var settings = {
    requestInterval: 500,      // 延时ms
    clickLoopInterval: 300,    //点击间隔ms
    questions_match : 0,       // 匹配功能 默认关闭
    X2speed : 1 ,              //二倍速 默认开启
    qualityChange : 1 ,        //切换标清,默认开启
    setmuted: 1,               //切换静音 默认开启
    Backgroungplay: 1,         //后台播放 默认开启
    Autoplay : 1    ,          //连播,默认开启
    Smartplay : 0              //智能播放,自动跳转未完成的视频。默认为顺序播放
};

//视频功能
var firstset = 1;
setInterval(function video() {
       var player = $(".xt_video_player_common_list");
       var current_video = document.getElementsByTagName('video')[0]
       var urld = window.location.href;
       if(urld.match("video")&&firstset) {
       lpanel.html("切换到标清,开启2倍速静音");
       let speedChild = player.children()[0]; //二倍速
           if(settings.X2speed) speedChild.click();
       let quality = player.children()[5]; //标清
           if(settings.qualityChange) quality.click();
           if(settings.setmuted) current_video.muted=true; //静音
        firstset=0;
        }
        if(urld.match("video")) {
            if(settings.Backgroungplay){
                current_video.play();
                console.log("后台播放中");
            }
            let p=$(".xt_video_player_progress_currentTime")[0];//获取播放进度
            let progress = p.style.width;
            document.title = progress;
            if((parseInt(progress) > 95)&&settings.Autoplay){ //进度大于95 播放下一个视频
               console.log("播放完成,即将跳转");
               if(settings.Smartplay) Smartnextone();
               else ordernext();
               return;
            }
      }



  },2000)

//顺序播放
function ordernext(){
    let url = window.location.href;
    let domain = url.match(/\/\/(\S*).xuetangx.com/);
    var spV = url.split('/');
    var courseid = spV[5];   //当前主课程ID
    var classid = spV[6];    //当前课程ID
    var nowvid = spV[8];     //当前视频ID
    var nowunitid = spV[7];
    var courseAPIurl = "https://"+domain[1]+".xuetangx.com/lms/api/v1/course/"+courseid+"/courseware/";

    $.ajax({
        type: "post",
        url: courseAPIurl,
        data: {"class_id":classid},//查询
        success: function (redata) {
           let nextid = 0;
           let nextunitid = 0
           let listdata = redata.coursewareOrder;
           let flag = 0;

           //获取下个视频的ID
             for( i in listdata){
                 if(i.match(nowunitid)){
                    if(i.match(':'+ nowvid)) {flag=1;continue;} //寻找当前播放视频所在的位置
                 }
                 if(flag){
                     if(!i.match(":H\+")){
                         nextunitid = i.split(':')[0];
                         nextid = i.split(':')[2];
                         break;
                     }
                 }
             console.log(nextunitid + " " + nextid);
                }
                    let next=(url.match(/(\S*)\/0\//)[1]);
                    let nexturl = next.substr(0,next.length-nowvid.length-nowunitid.length-1) + nextunitid + '/' + nextid + "/0/";  //下一个视频地址
                    console.log("下一个视频地址   " + nexturl);
                    lpanel.html("播放完成,下一个视频   " + nexturl);

                  setTimeout(window.location.href = nexturl,6000);
                  location.reload()  ;
        }
    });


}

//智能播放
function Smartnextone(){
    let url = window.location.href;
    let domain = url.match(/\/\/(\S*).xuetangx.com/);
    var spV = url.split('/');
    var courseid = spV[5];   //当前主课程ID
    var classid = spV[6];    //当前课程ID
    var nowvid = spV[8];     //当前视频ID
    var nowunitid = spV[7];
    var VideoRe = "https://"+domain[1]+".xuetangx.com/score/"+courseid+"/manual_paging/";
    var courseAPIurl = "https://"+domain[1]+".xuetangx.com/lms/api/v1/course/"+courseid+"/courseware/";
    var unitdata ;

    //智能播放
    $.ajax({
        type: "post",
        url: courseAPIurl,
        data: {"class_id":classid},//查询未完成视频
        success: function (responsedata) {
           unitdata = responsedata.data;
           console.log(unitdata);
           //查询进度
           $.ajax({
            type: "post",
            url: VideoRe,
            data: {"class_id":classid,"cla":"v","cp":"","status":0,"page":1},//查询信息
            success: function (redata) {
               let nextid = 0;
               let nextunitid = 0
               var v = redata.data.items[0];
                        if(v.percent >= 75){v = redata.data.items[1]; console.log("数据未更新"+v.percent);} //防止数据未更新重复观看
                        nextid = v.item_id;  //下一个视频ID
                        nextunit = v.chapter; //下一个单元名
                        console.log(nextunit);
                        var next=(url.match(/(\S*)\/0\//)[1]);
                        console.log(nextid + + " " + v.section);
                        for(let i = 0; i < unitdata.length; i++){
                            if(unitdata[i].unit_name.match(nextunit))
                            { console.log("获得id");
                              nextunitid = unitdata[i].unit_id;
                              break;
                            }

                        }

                        var nexturl=next.substr(0,next.length-nowvid.length-nowunitid.length-1) + nextunitid + '/' + nextid + "/0/";  //下一个视频地址
                        console.log("下一个视频地址   " + nexturl);
                        lpanel.html("播放完成,下一个视频   " + nexturl);

                        setTimeout(window.location.href=nexturl,6000);
                        location.reload()  ;
            }


        });
        }

    });



    }

// 左侧提示
    let lpanel = $('<div>', {
        html: "在答题界面按S查询答案,按N自动点击,无效请开启大写锁定或刷新",
        id: "retry",
        style: "position:fixed;z-index:9999;width: 240px;background-color: #FFA500;top:100px;left:10px;opacity: 0.7;color: black;"
    });
    lpanel.appendTo('body');
// 点击事件,每次点击都是一次请求,mmp
let clickList = [];
// 是否全部查询成功
let successNum = 0;
let allNum = 0;
let nChange = 0;
// 控制按键 s 触发的重复请求
let submit = false;
// 开启点击
let autoClick = false;
// title 页面标识
let title = $('.title').text();

// 初始化函数
function init() {
    title = $('.title').text();
    autoClick = false;
    retry = [];
    submit = false;
    successNum = 0;
    allNum = 0;
    nChange = 0;
    clickList = [];
    lpanel.html('在答题界面按S查询答案,按N自动点击,无效请切换输入法状态或刷新重试');
}

$(window).keydown(function (event) {
    switch (event.key) {
        case 'n':
            autoClick = !autoClick;
            nChange++;
            if (autoClick){
                clickLoop();
            }
            return false;
        case 's':
            // 初始化
            let numx=0;
            let answer = new Array();
            let blank=new Array();
            let analy = new Array();
            var questions = new Array();
            var tureanswer = new Array();
            var truequestion = new Array();
            var trueanaly = new Array();
            let nowlist = $('.paper-list>li');
            var nowquestion = new Array();
            //获取当前链接
            let url = window.location.href;
            let domain = url.match(/\/\/(\S*).xuetangx.com/);
            let LIST="https://"+domain[1]+".xuetangx.com/inner_api/homework/score/result/P%2B29698%2B0090/"+url.substring(url.length - 11);

            //调用API查询
            $.getJSON(LIST,function(result){
            let p=result.data.question_data;
            $.each(p, function(idx, objx) {
                let ps=JSON.stringify(objx.options);
                let psx=ps.match(/\"([^\"]*)\",/g);
                psx= psx.toString().replace(/,,/g,"&nbsp&nbsp&nbsp&nbsp&nbsp");
            blank[numx]=psx.replace(/,/g,"");         //查询填空题

            questions[numx]=objx.stem.replace(/<[^>]+>/g,"");
            questions[numx]=questions[numx].replace(/(\n)/g,"");   //去除HTML标记
            console.log(questions[numx]);
            answer[numx]=objx.correct_answer;
            if(answer[numx]=="") answer[numx]=blank[numx];
            analy[numx]=objx.analysis;
            numx++;
         });

         let lis = $('.paper-list>li');
         for (let i = 0; i < lis.length; i++) {
             nowquestion[i] = $(nowlist[i]).find('span.content').text();
             let question = $(lis[i]).find('span.content').text();
             // 建立好每个 li 的提示信息容器
             $(lis[i]).attr("id", "li" + i);
             $(lis[i]).append($('<div>', {
                 id: "div" + i,
             }));
             // 匹配
             if(settings.questions_match){
             for(let j = 0;j <nowlist.length; j++){
                 if(nowquestion[i]==questions[j])
                   {
                       tureanswer[i] = answer[j];
                       truequestion[i] = questions[j];
                       trueanaly[i] = analy[j];
                       console.log(i + ' 匹配成功');
                       break;
                   }
                   else if(j==nowlist.length-1){

                    tureanswer[i] = answer[i];
                    truequestion[i] = questions[i];
                    trueanaly[i] = analy[i];
                    console.log(i + '匹配失败,使用默认配置');
                   }
             }

             show(lis[i],tureanswer[i],trueanaly[i],truequestion[i]);}
             else show(lis[i],answer[i],analy[i],questions[i]);

             }


         })



    }
});

// 显示
function show(li,x,y,que) {
               // 提示信息容器
                let div = $(li).find('#div' + $(li).attr("id").substring(2));
                div.html('查询题目: ' + que + '</span><br></span><br>' +  '正确答案:' + "<span style='color: green'>" + x + '</span><br>' + '答案解析:' + y + '</span>');
                // 点击事件入列
                clickList.push(click(li, x));
}


// 点击事件
function click(li, answer) {
    return function () {
        let choices = $(li).find('.answer-info');
        for (let i = 0; i < choices.length; i++) {
            if ($(li).find('.type').text().replace(" ", '') == '多选') {
                if (answer.indexOf($(choices[i]).text().replace(" ", '')) != -1) {
                    if (!$(choices[i]).find('input').prop("checked")) {
                        $(choices[i]).click();
                        return true;
                    }
                }else{
                    if ($(choices[i]).find('input').prop("checked")) {
                        $(choices[i]).click();
                        return true;
                    }
                }
            } else {
                // 单选和选择
                if (answer == $(choices[i]).text().replace(" ", '')) {
                    if (!$(choices[i]).find('input').prop("checked")) {
                        $(choices[i]).click();
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

// 执行点击事件
async function clickLoop() {

    while (autoClick) {
        let tmp = nChange;
        let flag = false;
        for (let i = 0; i < clickList.length; i++) {
            if (clickList[i]()) {
                flag = true;
                break;
            }
        }
        if (!flag) {
            lpanel.html("自动点击完成。主观题、多选题可能无法作答,请注意检查遗漏");
            $(document).scrollTop(0);
            autoClick=false;
            return false;
        }
        await sleep(settings.clickLoopInterval + (100*Math.random()>>0)*20 );
        if (tmp!=nChange)
            return false;
    }
}

const sleep = (timer) => {
    return new Promise((resolve, reject) => {
        setTimeout(resolve, timer);
    });
};
none
打赏采用二维码方式。

添加新评论