职业培训自动播放

厦门市职业技能培训总站自动播放下一个视频

当前为 2020-04-07 提交的版本,查看 最新版本

// ==UserScript==
// @name         职业培训自动播放
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  厦门市职业技能培训总站自动播放下一个视频
// @author       mouc
// @include      /http?:\/\/xmaqsc\.zyk\.yxlearning\.com\/learning/.*
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @run-at       document-idle
// @license      MIT License
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const delay = 10000;//重试间隔
    let play = ()=>{
       $('.polyvFlashObject')[0].j2s_resumeVideo();
    };

    var interval = null;//计时器

    function start(){
        if (interval != null){
            clearInterval(interval);
            interval = null;
        }

        //每隔delay毫秒恢复播放
        interval = setInterval(() => {

        if( $('.polyvFlashObject').length === 1 ){
            //console.warn("检测到播放器, 正在重试恢复播放...")
            if ($($($(".beginstyle")[1])[0]).children()[1].innerText < 100){
                play();
            }
            else
            {
                console.warn("检测到总进度为100, 停止播放于"+ (new Date).toString());
                stop();
            }
        }else{
            console.error("没有检测到播放器, " + delay + "毫秒后重试...");
        }
        }, delay);
    }

    start();

    function stop(){
        $('.polyvFlashObject')[0].j2s_stopVideo();
        clearInterval(interval);
		interval = null;
    }

    // Your code here...
})();