21tb自用

自己用的,不要下载……

当前为 2023-10-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         21tb自用
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  自己用的,不要下载……
// @author       YQ
// @match        https://sxqc-gbpy.21tb.com//els/html/courseStudyItem/courseStudyItem.learn.do*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=21tb.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    var interval=30 //间隔时间,秒,必须正整数
    var courseList=[] //所有课程
    var nowIndex=0 //当前播放视频的序号
    var isStart=false
    var watchVideo //视频任务
    console.log("已启动")

    //document.querySelector('#goNextStep').click()
    //document.querySelector('.next-button').click()
    var domain=document.domain
    var url=window.location.pathname
    //时间设置有误,默认为30秒
    if(!(Number.isInteger(interval)&&interval>0))
    {
        interval=30
    }
    if(domain=='sxqc-gbpy.21tb.com' && url=='/els/html/courseStudyItem/courseStudyItem.learn.do')
    {
        setTimeout(function(){
            var newLi = document.createElement("li"); //创建一个input对象(提示框按钮)
            newLi.id = "id001";
            newLi.classList.add('cs-menu-item','cl-go-btn','pull-right')
            var newA=document.createElement("a")
            newA.classList.add('cl-go-link')
            newA.innerHTML='开始挂机'
            newA.style.color='blue'
            newLi.appendChild(newA)
            document.querySelector('.cs-nav-menu').appendChild(newLi)
            newA.onclick=function(){
                if(isStart==false)
                {
                    if(document.querySelector('#courseItemId'))
                    {startWatch()}
                    else
                    {startWatch2()}
                    isStart=true
                    newA.innerHTML='正在挂机'
                    newA.style.color='red'
                }else{
                    clearInterval(watchVideo)
                    isStart=false
                    newA.innerHTML='开始挂机'
                    newA.style.color='blue'
                }
            }
        },10000);
    }


    function startWatch2()
    {
      courseList= document.getElementsByClassName("url-course-content")[0].contentWindow.document.querySelectorAll('.section-item:not(.finish)')
      console.log("还有有"+ courseList.length +"节课")
        checkVideo2()
        watchVideo=setInterval(checkVideo2,interval*1000)
    }

function checkVideo2()
    {
        //Iframe的document
        var frameDocument=document.querySelector('#aliPlayerFrame').contentDocument
        //判断是否有正在学习的节点
        if(frameDocument.querySelector('.first-line.active'))
        {
            //如果有,判断该节点是否是已完成
            if(frameDocument.querySelector('.first-line.active').parentNode.classList.contains('finish'))
            {
                //如果所有节点都已完成
                if(frameDocument.querySelectorAll('.section-item.finish')==frameDocument.querySelectorAll(".section-item"))
                {
                    //关闭定时器
                    clearInterval(watchVideo)
                    return
                }
                //否则点击下一个视频
                frameDocument.querySelectorAll('.section-item')[frameDocument.querySelectorAll('.section-item.finish').length].click()
                return
            }
        } else//如果没有正在学习的节点
        {
            //如果所有节点都已完成
            if(frameDocument.querySelectorAll('.section-item.finish')==frameDocument.querySelectorAll(".section-item"))
            {
                //关闭定时器
                clearInterval(watchVideo)
                return
            }
            //否则点击下一个视频
            frameDocument.querySelectorAll('.section-item')[frameDocument.querySelectorAll('.section-item.finish').length].click()
            return
        }

        if(frameDocument.querySelector('video').paused)
        {
            frameDocument.querySelector('video').play()
        }

    }





    function startWatch()
    {
        console.log("已加载")
        courseList=document.querySelector('#courseItemId').querySelectorAll('.cl-catalog-item-sub')
        console.log("共有"+ courseList.length +"节课")

        checkVideo()

         console.log("开启定时器")
        //开启定时器,循环检测
       watchVideo=setInterval(checkVideo,interval*1000)
    }

        function checkVideo(){
            var j=0;
            for(j=0;j<courseList.length;j++)
            {
                console.log("进入循环")
                if(document.querySelectorAll('.cl-catalog-item-sub')[j].querySelector('a').classList.contains('cl-catalog-link-done'))
                {
                       continue;
                }
                //如果有正在播放的视频

               else if(document.querySelectorAll('.cl-catalog-item-sub')[j].querySelector('a').classList.contains('cl-catalog-playing'))
                {
                    console.log("aaaaaaaaaaa","playing",j)
                    //视频暂停
                    if(j!=nowIndex)
                    {nowIndex=j}
                    if(document.getElementById('iframe_aliplayer').contentWindow.document.querySelector('video').paused)
                    {

                     document.getElementById('iframe_aliplayer').contentWindow.document.querySelector('video').play()
                    }
                    break;
                }

                //找到未播放完成视频
               else
                {
                    console.log("找到"+(j+1)+"节课未播放完成")
                    console.log("当前课程"+nowIndex)
                    if(j!=nowIndex)
                    {
                        nowIndex=j
                        //点击
                        document.querySelectorAll('.cl-catalog-item-sub')[j].querySelector("a").click();
                        break;
                    }
                }
            }
            console.log("正在播放第"+nowIndex+"节课")

            if(j>courseList.length)
            {
                clearInterval(watchVideo)
            }

        }

    // Your code here...
})();