智慧树网课平台自动刷课插件源码


自动答题+自动切换下一节视频

依赖谷歌浏览器

起因

学校需要完成在智慧树平台上网课的学习,但是由于某些视频实在不太感兴趣,但还是必须得看啊,播放过程中会弹出题目选择。不点击视频无法继续播放,这就很尴尬了。于是就产生了编写一个脚本辅助我们完成这个枯燥的过程的想法,让我们腾出有限的时间去做自己想做的事情。

功能

  1. 自动答题(百分百正确)
  2. 自动切换视频直到课程结束
    完整源码下载请请前往: GitHub: AutoGo 码云: AutoGo

谷歌插件入口文件

{
  "name": "AutoGo",
  "manifest_version": 2,
  "version": "1.0",  
  "description": "Zhuwj AutoGo",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "icons": {
    "128" : "icon.png"
  },
  "content_scripts": [
    {
      "matches": ["https://study.zhihuishu.com/*"],
      "js": ["jquery.js","probably.js","automatic_problem_solving.js","automatic_switch_video.js"]
    }
  ]
}

计算弹出的【多选题】答案组合

function out_probably(len){
    var result = [];
    var nums = [];
    for(var i = 1;i <= len;i++){
        nums.push(i);
    }
    for(var i = len;i > 0;i--){
        result = result.concat(out_combine(nums,i));
    }
    return result;
}

function out_combine(source,m){
    var n = source.length;
    if(m > n){
        return [];
    }
    if(m == n){
        var ints = [];
        ints.push(source);
        return ints;
    }
    var result = [];
    var bs = [];
    for(var i = 0;i < n;i++){
        bs[i] = 0;
    }
    for(var i = 0;i < m;i++){
        bs[i] = 1;
    }
    var flag = true;
    var tempFlag = false;
    var pos,sum;
    do{
        sum = 0;
        pos = 0;
        tempFlag = true;
        result.push(out_print(bs,source));
        for(var i = 0;i < n - 1;i++){
            if(bs[i] == 1 && bs[i+1] == 0){
                bs[i] = 0;
                bs[i+1] = 1;
                pos = i;
                break;
            }
        }

        for(var i=0;i<pos;i++){
            if(bs[i] == 1){
                sum++;
            }
        }

        for(var i=0;i<pos;i++){
            if(i<sum){
                bs[i]=1;
            }else{
                bs[i]=0;
            }
        }

        for(var i= n-m;i<n;i++){
            if(bs[i]==0){
                tempFlag = false;
                break;
            }
        }

        flag = tempFlag == false;
    }while (flag)
    result.push(out_print(bs,source));
    return result;
}

function out_print(bs,source){
    var result = [];
    var pos = 0;
    for(var i = 0;i < bs.length;i++){
        if(bs[i] == 1){
            result[pos] = source[i];
            pos++;
        }
    }
    return result;
}

自动答题服务

function start_problem_solving(){

if($("#mediaplayer_parent").length == 0){
    console.log("当前页面不启动AutoGo的自动答题服务");
    return;
}
console.log("AutoGo自动答题服务启动...");
var out_timer = setInterval(function(){
    //console.log("检查题目是否弹出")
    if($("#popbox_overlay").css("display") == "block"){
        console.log("题目弹出,开始自动答题,关闭轮询服务")
        clearInterval(out_timer);
        setTimeout(function(){
            var len = $("#tmDialog_iframe").contents().find(".exam_correct").length;
            if(len > 0){
                console.log("题目答案已经找到,关闭弹出框。激活自动答题服务");
                window.top.document.getElementsByClassName('popbtn_cancel')[0].click();
                start_problem_solving();
                return;
            }
            var answerOptions = $("#tmDialog_iframe").contents().find(".answerOption");
            len = answerOptions.find("input[type='checkbox']").length;
            console.log("题目答案个数 = " + len + "个");
            if(len > 0){
                console.log("题目为多选题");
                multiple_choice_questions_handle(answerOptions,out_probably(len),0);
            }else{
                console.log("题目为单选题");
                single_choice_question_handle(answerOptions,0);
            }
        
        },1000);
    }
},3000);

}

function single_choice_question_handle(answerOptions,index){

var par = answerOptions.eq(index);
var nodes = $(par).find("input[type='radio']:not(:checked)");
if(nodes.length > 0){
    nodes.eq(0).click();
}
setTimeout(function(){
    len = $("#tmDialog_iframe").contents().find(".exam_correct").length;
    if(len == 0){
        single_choice_question_handle(answerOptions,++index);
    }else{
        console.log("题目答案已经找到,关闭弹出框。激活自动答题服务");
        window.top.document.getElementsByClassName('popbtn_cancel')[0].click();
        start_problem_solving();
    }
},1000);

}

function multiple_choice_questions_handle(answerOptions,types,index){

var nums = types[index];
for(var k = 0;k < nums.length;k++){
    var nodes = answerOptions.eq((nums[k] - 1)).find("input[type='checkbox']:not(:checked)");
    if(nodes.length > 0){
        nodes.eq(0).click();
    }
}
setTimeout(function(){
    len = $("#tmDialog_iframe").contents().find(".exam_correct").length;
    if(len == 0){
        answerOptions.each(function(){
            var nodes = $(this).find("input[type='checkbox']:checked");
            var nodes_len = nodes.length;
            if(nodes_len > 0){
                nodes.eq(0).click();
            }
        });
        multiple_choice_questions_handle(answerOptions,types,++index);
    }else{
        console.log("题目答案已经找到,关闭弹出框。激活自动答题服务");
        window.top.document.getElementsByClassName('popbtn_cancel')[0].click();
        start_problem_solving();
    }
},1000);

}

start_problem_solving();

自动切换视频服务

function next_video_handler(out_next_video_timer){
    var jd = $(".passTime").css("width");
    //console.log("进度 => " + jd);
    if(jd != '100%'){
        return;
    }
    console.log("视频准备结束处理 => " + jd);
    clearInterval(out_next_video_timer);
    var next = $(".current_play").nextAll().filter(".video");
    if(next.length == 0){
        console.log("恭喜您视频学习已经完毕,服务停止");
        return;
    }
    next.click();
    var out_loop_start_timer = setInterval(function(){
        jd = $(".passTime").css("width");
        if(jd != '100%'){
            //开启轮询,关闭检查
            console.log("开启新检查视频线程 => " + jd);
            clearInterval(out_loop_start_timer);
            start_switching_videos();
        }else{
            console.log("还未出现进度,无法开启视频结束检查线程");
        }
    },2000);
}


function start_switching_videos(){
    if($(".current_play .learningPercentage-span").length == 0){
        console.log("当前页面不启动AutoGo的切换视频服务");
        return;
    }
    console.log("AutoGo切换视频服务启动...");
    var out_next_video_timer = setInterval(function(){
        //console.log("检查视频是否结束");
        next_video_handler(out_next_video_timer);
    },3000);
}

start_switching_videos();

文章来自互联网,如有侵权联系删除

声明:混世大魔王|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 智慧树网课平台自动刷课插件源码


❤️好好休息,别太劳累