// ==UserScript== // @name 视频学习 // @namespace http://tampermonkey.net/ // @version 0.2 // @description 适用于:灯塔-干部网络学院 // @author 郭 // @match https://gbwlxy.dtdjzx.gov.cn/content* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; var video = null; var istail = false; var nextCourse = null; function watch() { video = document.querySelector('video'); if (!video) { showMsg('未发现视频'); return } if (video.ended) {//播放完毕也是paused,拦截了 showMsg('当前视频播放完毕'); //playNext(); return; } if (video.paused) {//开始播放 showMsg('开始播放'); video.muted = true;//chrome自动播放需静音 video.play(); video.addEventListener('ended', playNext); setTimeout(findNext,5000); return } //正常播放 showMsg('播放中...') return } function playNext() { if (nextCourse) { nextCourse.click(); } else { showMsg('全部学习完毕'); } } function findNext() { showMsg('寻找下一视频'); const currentCourse = document.querySelector('div.suspended') && document.querySelector('div.suspended').parentNode.parentNode; const courseList = Array.from(document.querySelectorAll('div.course-list-item')); if (courseList.includes(currentCourse)) {//在列表中 if (courseList.at(-1) == currentCourse) {//最后一课 istail = true; nextPage(); } else { nextCourse = courseList[courseList.indexOf(currentCourse) + 1]; showMsg('找到待播放视频'); } } else if (istail) {//在上一页列表中 istail = false; nextCourse = courseList[0]; showMsg('找到待播放视频'); } else {//不在列表中 nextPage();//翻页 } } function nextPage() { const nextBtn = document.querySelector('.ztCourceList-wrap .right button');//下一页按钮 if (nextBtn.disabled) { nextCourse = null; showMsg('最后一个视频'); } else { console.log('翻下一页') nextBtn.click(); setTimeout(findNext, 1000);//加载需要延迟 } } function showMsg(msg = '') { console.info(msg); //设置显示面板 const msgpan=document.querySelector('div.right-fixed-wrap>span'); msgpan.setAttribute('style','color:red;background:yellow;'); msgpan.textContent=msg; } const timerId = setInterval(watch, 3000); })();