// ==UserScript== // @name 21tb自用 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 自己用的,不要下载…… // @author You // @match https://sxqc-gbpy.21tb.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=21tb.com // @grant none // @license MIT // @downloadURL none // ==/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() { //判断是否有下一页出现 if(document.querySelector('.next-button')) { courseList=document.querySelectorAll('.section-item:not(.finish)') if(courseList?.length==0) { clearInterval(watchVideo) }else{ document.querySelectorAll('.next-button')[document.querySelectorAll('.section-item:not(.finish)').length].click() } } if(document.getElementsByClassName("url-course-content")[0].contentWindow.document.querySelector('video').paused) { document.getElementsByClassName("url-course-content")[0].contentWindow.document.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;jcourseList.length) { clearInterval(watchVideo) } } // Your code here... })();