Greasy Fork

Greasy Fork is available in English.

视频学习

适用于:灯塔-干部网络学院

当前为 2022-12-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        视频学习
// @namespace    http://tampermonkey.net/
// @homepageURL https://pooorfoool.gitee.io/study
// @version      0.5
// @description   适用于:灯塔-干部网络学院
// @author       郭
// @match        https://gbwlxy.dtdjzx.gov.cn/content*
// @grant        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('全部学习完毕');
        clearInterval(timerId);
        alert('学习完毕');
    }
}
function findNext() {
    showMsg('寻找下一视频');
    var currentCourse = document.querySelector('div.suspended') &&
        document.querySelector('div.suspended').parentNode.parentNode;
    var 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() {
    var 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);
    //设置显示面板
    var msgpan=document.querySelector('div.right-fixed-wrap>span');
    msgpan.setAttribute('style','color:red;background:yellow;');
    msgpan.textContent=msg;
}

var timerId = setInterval(watch, 3000);

})();