Greasy Fork

Greasy Fork is available in English.

云学堂视频辅助

云学堂视频自动刷课

当前为 2022-04-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         云学堂视频辅助
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description 云学堂视频自动刷课
// @author       兜里有糖
// @match        http://*.yunxuetang.cn/kng/trn/mybuyedcourse.htm
// @match        http://*.yunxuetang.cn/kng/view/package/*
// @match        http://*.yunxuetang.cn/kng/course/package/video/*
// @match        http://*.yunxuetang.cn/kng/course/package/scorm/*
// @icon            https://picobd.yunxuetang.cn/media/userfiles/userphotos/default/78.png
// @grant        none
// ==/UserScript==
const titleMap={};
const beginHour=5;
const endHour=22;
const ignoreTitles=[];
(function() {
    'use strict';
    //点击【继续学习】的方法
    function autoContinue() {
        var continueBtn = document.querySelector("#reStartStudy");
        if (continueBtn && continueBtn.click) {
            var imitateMousedown = document.createEvent("MouseEvents");
            imitateMousedown.initEvent("mousedown", true, true);
            continueBtn.dispatchEvent(imitateMousedown);
            continueBtn.click();
            if (console && console.log) {
                console.log('找到并点击了[继续学习]');
            }
        }
    }

    //判断当前是否在学习时间段内
    function isTimeAvailable(){
        let date=new Date()
        let hour=date.getHours()
        if(Number(hour) >= endHour || Number(hour) < beginHour ){
            console.log('已经超过播放区间:【'+beginHour+'--'+endHour+'】','当前时间为:'+date)
            return false;
        }
        return true;
    }
    //判断一个元素是否在一个数组中
    function isInArray(arr,value){
        if(arr ==null || arr.length ==0 || value==null || value ==''){
            return false
        }
        for(var ini=0;ini< arr.length; ini++){
            if(value == arr[ini]){
                return true
            }
        }
        return false
    }

    setInterval(()=>{
        try{
            //去掉弹窗
            var dialogNode=document.getElementById('dvWarningView');
            if(dialogNode!=null){
                autoContinue()
            }else{
                if(player!=null && player.bdPlayer.getState()=='paused'){
                    player.bdPlayer.setMute(true);//静音
                    player.bdPlayer.play();
                }
            }
            var currentProgress=document.getElementById('ScheduleText').innerText

            if(currentProgress == '100%'){
                localStorage.setItem('nextVideo',true)
                window.close()
            }else if(player!=null && player.bdPlayer.getState()=='complete'){//如果没有到100%且视频播放完了,那么再重新播放一遍
                document.location.reload();
            }
        }catch(e){
            console.log(e)
        }
    },5000);

    //我的课程页面,并跳转到课程详情
    // titleMap={}
    try{
        console.log('isTimeAvailable',isTimeAvailable())
        var courseListNode=document.getElementsByClassName('el-my-course-list clearfix')[0];
        for(var courseIndex=courseListNode.children.length - 1;courseIndex >= 0;courseIndex--){
            var courseNode=courseListNode.children[courseIndex];
            var buttonNode= courseNode.children[0].children[1].children[0];
            var title=courseNode.children[1].children[0].innerText;
            var progressNode=courseNode.children[1].children[1].innerText;
            var progress=progressNode.match(/\d+\%/)[0]
            titleMap[title]=progress;
            if((progress !='100%') && !isInArray(ignoreTitles,title)){
                if(isTimeAvailable()){
                    buttonNode.click()
                }
                break;
            }
        }
        //  console.log(titleMap)
        setInterval(()=>{
            var nextVideo=localStorage.getItem('nextVideo')
            console.log(nextVideo)
            if(!isTimeAvailable()){
                return
            }
            if(nextVideo == 'true'  ){
                localStorage.setItem('nextVideo',false)
                document.location.reload();
            }
        },20000)
    }catch(e){
        console.log(e)
    }

    //进入课程介绍页面
    var titleNodes=document.getElementsByClassName('clearfix pr')
    if(titleNodes!=null && titleNodes.length>0){
        var detailTitle=document.getElementsByClassName('clearfix pr')[1].children[1].children[0].innerText
        console.log(detailTitle)
    }

    var btnStartStudy= document.getElementById('btnStartStudy')
    if(btnStartStudy!=null){
        btnStartStudy.click()
        console.log('开始学习')
    }


    console.log('在运行中...')

})();