Greasy Fork

Greasy Fork is available in English.

新版云学堂自动刷视频

新版云学堂自动刷视频。进入视频目录页点开始学习,一直刷。

当前为 2023-11-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         新版云学堂自动刷视频
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  新版云学堂自动刷视频。进入视频目录页点开始学习,一直刷。
// @author       piaopiao
// @match        https://*.yunxuetang.cn/kng/*
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @run-at       document-end
// @require      https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js
// @license      MIT
// ==/UserScript==



var url = window.location.href //网页url
var host = window.location.origin //域名www.xxx.com
var Videoid //视频id
var Hanguptimer //接收检查挂机计时器
var i = 999; //定义i作为第几个视频计数,初始赋值999,防止其他操作导致url变化,导致脚本开始
(function() {
    'use strict';
//添加按钮两个按钮
let startButton = document.createElement("button")
startButton.setAttribute("id", "startButton")
startButton.className = "startbutton"
startButton.style.cssText = "cursor:pointer;border-radius:8px;background-color:#F5F5F5;border-style:none;width:90px;height:45px;position:fixed;font-Size:20px;color:red;left:90px;top:100px;z-index:9999"
startButton.innerText = "开始学习"

let pageChangeButton = document.createElement("button")
pageChangeButton.setAttribute("id", "pageChangeButton")
pageChangeButton.className = "pageChangeButton"
pageChangeButton.style.cssText = "cursor:pointer;border-radius:8px;background-color:#F5F5F5;border-style:none;width:110px;height:45px;position:fixed;font-Size:20px;color:red;left:190px;top:100px;z-index:9999"
pageChangeButton.innerText = "翻至指定页"

document.body.append(startButton)
document.body.append(pageChangeButton)
//开始学习点击事件
startButton.addEventListener("click", function(){
    if(startButton.innerText == "开始学习"){
        alert("开始从当前页开始,一直学习,点击停止按钮可结束学习。\n自动设置2倍速,\n自动点击挂机窗口,\n自动跳过积分兑换视频。\n3秒后将开始学习,期间不要刷新网页。")
        i = 0
        getVideoid()
        openVideo()
    }else{
        i=999
        window.open(host+"/main/#/index","_self")
    }
})
startButton.addEventListener("mouseover", function(event){
   startButton.style.backgroundColor="#436BFF"
})
startButton.addEventListener("mouseout", function(event){
   startButton.style.backgroundColor="#F5F5F5"
})
//翻页点击事件
pageChangeButton.addEventListener("click", function() {
	var k //页数
    var page = prompt("请输入页数:", "1") //弹出输入框
	if (page != null && page != "") {
		k = parseInt(page)
		if (k > 0) {
			k = k
		} else {
			k = 1
		}
	} else {
		k = 1
	}
    document.querySelector(".yxtf-pager").__vue__.$emit("change", k) //翻页

})
pageChangeButton.addEventListener("mouseover", function(event){
   pageChangeButton.style.backgroundColor="#436BFF"
})
pageChangeButton.addEventListener("mouseout", function(event){
   pageChangeButton.style.backgroundColor="#F5F5F5"
})

//获取视频id
function getVideoid(){
    if(url.match("&type=2")){
         //设置定时器检查VUE是否加载
        var getVideoidTimer=window.setInterval(function () {
            if(document.getElementsByClassName("kng-list").length != 0){
                Videoid = document.querySelector(".kng-list").__vue__.kngListData
                clearInterval(getVideoidTimer)
            }
        },2000)
    }
}


//监测网页url变化循环播放
window.addEventListener("hashchange", function(){
    url = window.location.href //取当前网页地址
    if(url.match("/video/play")){
        //判断进入视频播放页
        startButton.innerText = "结束学习" //视频播放页按钮名称结束学习
        setTimeout(function(){
        if(document.getElementsByClassName("standard-size-20 color-white").length != 0){
            //检查是否需要积分兑换,需要返回上一页
            console.log("需要积分兑换")
            window.history.go(-1)
        }else{
            if(document.getElementsByClassName("opacity8 ml8").length!=0)
            {
                if (document.querySelector(".opacity8.ml8").innerHTML== "已完成学习") {
                    //检查是否已完成,完成返回上一页
                     window.history.go(-1)
                }else{
                    playVideo()
                   //设置定时器检查进度和挂机窗口,进入视频索引页后删除定时器
                    Hanguptimer = window.setInterval(function() {
            		    checkSchedule() //检查进度
            		    checkHangup() //检查挂机窗口
            	   }, 20000)
                }
            }

        }
        },3000)
    }
    if(url.match("&type=2")){
        //判断进入视频索引页
        startButton.innerText = "开始学习"
        clearInterval(Hanguptimer) //到索引页清除进度和挂机窗口检查定时器
        if(i<16){
            openVideo() //打开视频页
        }else if(i == 999){
            console.log("其他操作导致url变化,无操作") //未点击开始按钮,url变化不开始
        }else{
            //下一页
            console.log("下一页")
            i = 0
            setTimeout(function(){
                document.querySelector(".mt16.pull-right.knglist.yxtf-pagination.yxtf-pagination--normal").__vue__.next()
            }, 1000)
            getVideoid() //页数变化后重新获取视频id
            openVideo()
        }
    }
})

//进入视频索引页打开视频播放页
function openVideo(){
    var j = i
    i++
    setTimeout(function(){
        var Kngid_url=host + "/kng/#/video/play?kngId="+Videoid[j].id+"&projectId=&btid=&gwnlUrl=&rate=2"
        window.open(Kngid_url, "_self")
    }, 3000)


}
//检查课程完成度
function checkSchedule(){
    if(document.getElementsByClassName("yxtulcdsdk-fullsize").length != 0){
        if(document.querySelector(".yxtulcdsdk-fullsize").__vue__.kngDetail.schedule == 100){
            window.history.go(-1)
        }
    }
}


//播放视频
function playVideo(){
        var playTimer=window.setInterval(function () {
            //设置定时器检查VUE是否加载
            if(document.getElementsByClassName("yxtulcdsdk-flex-center yxtulcdsdk-flex-vertical max-w-560 ulcdsdk-break-word").length != 0){
                //播放视频并清除定时器
                clearInterval(playTimer)
                enableWebpackHook()
                console.log("已hook,后台不暂停")
                document.querySelector(".yxtulcdsdk-flex-center.yxtulcdsdk-flex-vertical.max-w-560.ulcdsdk-break-word").__vue__.play()
            }
        },1000)
}
//设置2倍速(没用到)
function setRate(){
        var setPlaybackRateTimer=window.setInterval(function () {
        //设置定时器检查VUE是否加载
        if(document.getElementsByClassName("jw-controlbar jw-background-color jw-reset").length != 0){
            //播放视频后设置2倍速
            console.log("播放视频后设置2倍速")
            document.querySelector(".yxtulcdsdk-fullsize").__vue__.$refs.player.getPlayer().setPlaybackRate(2)
            clearInterval(setPlaybackRateTimer)
        }
    },3000)
}

//检查挂机窗口
function checkHangup(){
    if(document.getElementsByClassName("yxtf-button--large").length != 0)
    {
        console.log("点击一次挂机提示窗口")
        document.getElementsByClassName("yxtf-button--large")[0].click()
    }
}
//hook webpack删除后台暂停函数
function enableWebpackHook() {
    let originCall = Function.prototype.call
    Function.prototype.call = function (...args) {
        const result = originCall.apply(this, args)
        //console.log(args[0])
        if(args[1]?.id==39 || args[1]?.id==38){
            //console.log(args[1]?.id)
            let fucText = args[3].m[126].toString()
            //console.log(fucText)
            //replace去头+slice去尾
            fucText = fucText.replace("function(a,b,c){", "").slice(0, -1)
            //删除暂停函数
            fucText = fucText.replace("&&oa.setState(f.PAUSED)", "")
            args[3].m[126] = new Function("a, b, c", fucText)
            //console.log(args[3].m[126])
            Function.prototype.call = originCall
        }
        return result
    }
}

//获取cookies
function getCookie(cname)
{
  var name = cname + "="
  var ca = document.cookie.split(";")
  for(var i=0; i<ca.length; i++)
  {
    var c = ca[i].trim()
    if (c.indexOf(name)==0) return c.substring(name.length,c.length)
  }
  return ""
}

 //设置cookies
function setCookie(cname,cvalue)
{
	document.cookie = cname+"="+cvalue+";path=/;"
}


    // Your code here...


})();