// ==UserScript== // @name 三分屏课件自动播放 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match http://*/* // @include http://*/* // @require http://cdn.staticfile.org/jquery/3.4.1/jquery.min.js // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; function startPlay(chapter_n) { var $chapter = $(".chapter").eq(chapter_n); var id = $chapter.attr('data-id'); var href = $chapter.attr('data-href'); var assertType = $chapter.attr('data-assert-type'); // 高亮当前章节 $('#course .chapter').removeClass('active'); $chapter.addClass('active'); // 暂停播放 window.global.player.pause(); if ('link' === assertType) { // [3.1] 点击内容为静态 html 页面的章节,加载章节页面到 #content 中 $("#course").css("top", "2px"); $('#chapter-iframe').attr('src', href); } else if ('video-sync' === assertType) { // [3.2] 点击使用 xml 配置的有视频和页面的章节 // [3.2.1] 加载章节的配置文件,生成章节对象 Chapter.load(id, href, function (chapter) { // [3.2.2] 加载章节的网页内容 $("#course").css("top", "198px"); // [3.2.3] 播放章节的视频 (等待播放器加载完成) var timerId = setInterval(function () { if (window.global.player) { clearInterval(timerId); if (chapter.mp4) { window.global.study.startStudy(chapter); // 开始学习章节,初始化数据 window.global.player.loadByUrl(chapter.mp4, chapter.startTime / 1000); window.global.player.play(); } } }, 100); }); } }; window.addEventListener('load', (event) => { console.log('page is fully loaded'); setInterval(function () { if (window.global.player) { var stat = window.global.player.getStatus(); console.log(stat); if (stat == "ended") { var active_chapter = 0; var chapters = $(".chapter"); for (var i = 0; i < chapters.length; i++) { if (chapters.eq(i).get(0).attributes["class"].value == "chapter active") { active_chapter = i + 1; break; } } console.log(active_chapter); startPlay(active_chapter); }} },5000)}); })();