chaoxingJump

skip video

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         chaoxingJump
// @namespace    http://tampermonkey.net/
// @version      0.8
// @description  skip video
// @author       You
// @match        http://mooc1-2.chaoxing.com/mycourse/studentstudy*
// @icon         https://www.google.com/s2/favicons?domain=ouchn.cn
// @grant        none
// @license MIT
// ==/UserScript==
(function () {
    'use strict';
    block('mouseout', window);
    check();
    // Your code here...
})();
function block(eventName, window) {
    window.addEventListener(eventName, (event) => {
        event.stopImmediatePropagation();
    }, true);
}
function check() {
    var n = nextService();
    var r = retryService();
    var v = videoService();
    console.log("经过测试,interval 在切换视频时不会改变");
    var lock = setInterval(function () {
        console.info("开始检测是否播放完毕.....");
        if(!n.correct()){
            console.log("出现故障了,无法跳转到下一个作业,无法处理,清除定时作业,lock:", lock);
            clearInterval(lock);
            return;
        }
        v.create();
        v.prop();
        if (!v.exist() && !r.retry()) {
            console.log("判定为当前页面没有视频,直接下一个作业");
            n.nextVideo();
            return;
        }
        v.failover();
        v.next(n);
    }, 3000);
}

function retryService() {
    var retryCount = 0;
    var maxRetry = 3;

    return {
        retry() {
            if (retryCount < maxRetry) {
                console.log('可能是由于加载缓慢导致的未初始化问题,重试次数:' + retryCount + ',最大次数:' + maxRetry)
                retryCount++;
                return true;
            } else {
                retryCount = 0;
                return false;
            }
        }
    }

}

function videoService() {
    let video = null;
    let body = null;
    function getBody() {
        try {
            return document.querySelector('#iframe').contentDocument.querySelector('iframe').contentDocument;
        } catch (error) {
            console.log("获取body出现了错误");
            return null;
        }
    }
    return {
        create() {
            body = getBody();
            if (body == null){
               video = null;
               return;
            };
            video = body.querySelector('#video_html5_api');
        },
        prop() {
            if (this.exist() && video.playbackRate == 1) {
                video.playbackRate = 2;
                video.muted = true;
            }
        },
        exist() {
            return video != null && typeof video != 'undefined'
        },
        failover() {
            if (this.exist() && video.paused && video.duration != video.currentTime) {
                console.log("暂停或者没播放完毕,继续播放");
                body.querySelector('.vjs-play-control').click();
                return true;
            }
            return false;
        },
        next(n) {
            if (this.exist() && video.duration == video.currentTime) {
                console.log("播放完毕,下一个视频");
                n.nextVideo();
            }
        }

    }
}

function nextService() {
    // 是否按了下一个的按钮
    let isNext = false;
    // 当前的url,比较下一个按钮是否生效
    let currentURL = window.location.href;

    function isOk() {
        return currentURL !== window.location.href && isNext
    }

    function syncError() {
        return currentURL == window.location.href && isNext
    }

    return {
        nextVideo() {
            console.log("开始播放下一个视频");
            document.querySelector(".orientationright ").click();
            isNext = true;
        },
        correct() {
            if (isOk()) {
                console.log("翻页成功");
                currentURL = window.location.href;
                isNext = false;
            } else if (syncError()) {
                return false;
            }
            return true;
        }
    }

}