中建知学云_自动刷课

自动挂机观看中建知学云课程,自动切换未完成视频

目前为 2023-02-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         中建知学云_自动刷课
// @namespace    https://e-cscec.zhixueyun.campuses.cn/
// @version      1.0
// @description  自动挂机观看中建知学云课程,自动切换未完成视频
// @author       Owen Yan
// @match        https://e-cscec.zhixueyun.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=e-cscec.zhixueyun.com
// @require      https://gf.qytechs.cn/scripts/425166-elegant-alert-%E5%BA%93/code/elegant%20alert()%E5%BA%93.js?version=922763
// @grant        none
// ==/UserScript==

// *使用说明*
// 如果网速慢可以调整 reloadTimeStamp 的数值 1000表示1秒 默认5500 需要大于3000

(function() {
    'use strict';
    let listHerf = ""
    let href = ""
    const reloadTimeStamp = 5500 // 调整左侧数值

    // 列表目录页处理逻辑
    async function pageList() {
        // 获取当前页面父级列表
        console.log("进入pageList")
        let i = 0
        let j = 0
        let fatherList = document.getElementsByClassName("section-title pointer")
        for (i = 0; i < fatherList.length; i++) {
            // 展开父级菜单
            if (i !== 0 || document.getElementsByClassName("train-citem").length === 0) {
                fatherList[i].click()
            }

            console.log("fatherList" + i)
            const logStr = await sleepFun(i)

            // 检查是否有更多
            if (openMore()) {
                // 读取子列表(也就是课程列表)
                if (document.getElementsByClassName("n-content n-list").lenght === 0) {
                    return
                }
                let classUrlList = document.getElementsByClassName("n-content n-list")[0].getElementsByTagName("li")
                console.log("classUrlList", classUrlList)
                for (j = 0; j < classUrlList.length; j++) {
                    let classUrl = ""
                    console.log("classUrlList" + j)
                    // 拼接课程详情页url
                    classUrl = "https://e-cscec.zhixueyun.com/#/study/course/detail/11&" + classUrlList[j].id.substr(17) + "&0/5/1"

                    // 判断课程是否已经完成
                    if (classUrlList[j].getElementsByClassName("ms-train-state un-finish").length !== 0) {
                        // 未完成
                        console.log("课程未完成")
                        // window.location.href = classUrl
                        location.href = classUrl
                        return
                    }
                }
            }

            // 当前父级已完成

        }
        new ElegantAlertBox("所有课程已经学完>__<")

    }

    // 视频播放页处理逻辑
    function pageVideo() {
        let setIntervalId = 0

        setIntervalId = setInterval(function() {
            let state = document.querySelector("dl.focus > div.chapter-right > div.section-item.section-item11 > div:nth-child(3) > span")
            state = state ? state.innerText : null
            if (state == "已完成") {
                new ElegantAlertBox("准备播放下一个视频>__<")
                let courses = document.querySelectorAll("dl")
                for (let i of courses) {
                    if (i.querySelector("div.chapter-right > div.section-item.section-item11 > div:nth-child(3) > span").innerText != "已完成") {
                        i.click()
                        return
                    }
                }

                // 返回目录页面
                clearInterval(setIntervalId)
                // window.location.href = localStorage.getItem('listHerf')
                location.href = localStorage.getItem('listHerf')
                setTimeout(() => {
                    window.location.reload()
                }, reloadTimeStamp - 1000)
                return

            } else {
                // if (document.getElementsByClassName("vjs-playing").length !== 0) {
                //     simulate(document.getElementsByClassName("vjs-big-play-button")[0])
                // }
                // if (document.getElementsByClassName("videojs-referse-btn vjs-hidden") === 0) {
                //     simulate(document.getElementsByClassName("videojs-referse-btn")[0])
                // }
                // new ElegantAlertBox("还没有学习完 >__<")
                // 修改页面提示
                if (document.getElementsByClassName("chapter-categary")) {
                    document.getElementsByClassName("chapter-categary")[0].getElementsByClassName("h3")[0].innerText = "[挂机中]目录[学习中]"
                }
                if (document.querySelector(".register-mask-layer") && 'display: none;' != document.querySelector(".register-mask-layer").getAttribute("style")) {
                    simulate(document.querySelector("#D210registerMask"))
                }
            }

        }, 5000)
    }


    // 展开更多
    function openMore() {
        if (document.getElementById("D219loadMore")) {
            document.getElementById("D219loadMore").click()
        }
        return true
    }

    // 休眠方法
    function sleepFun(abc) {
        return new Promise((res) => {
            return setTimeout(() => {
                res(abc)
            }, 1000)
        })
    }

    function start() {
        if (reloadTimeStamp <= 3000) {
            new ElegantAlertBox("reloadTimeStamp需要大于3000")
        }
        href = window.location.href
        if (document.readyState == 'complete') {
            // 页面加载完毕
            let setIntervalId = 0
            setIntervalId = setInterval(() => {
                console.log("执行setInterval")
                // 加载完成
                if (href.indexOf("train-new") !== -1) {
                    // 在列表页
                    if (document.getElementsByClassName("dialog-overlay topLoading hidden").length !== 0) {
                        localStorage.setItem('listHerf', href)
                        pageList()
                    }
                } else if (href.indexOf("error-page") !== -1) {
                    // 在错误页面
                    location.href = localStorage.getItem('listHerf')
                } else if (href.indexOf("course") !== -1) {
                    // 在播放页
                    console.log("进入videoList")
                    pageVideo()
                }
                clearInterval(setIntervalId)


            }, reloadTimeStamp)

        }
    }

    window.onhashchange = function(e) {

        console.log('URL发生变化了', e);
        setTimeout(() => {
            start()

        }, 3000)

    };

    // 开始代码
    document.onreadystatechange = function() {
        console.log("页面加载完毕")
        new ElegantAlertBox("脚本已经开始运行")
        start()
    }

})()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址