Greasy Fork

Greasy Fork is available in English.

基金业协会视频自动播放

基金业协会视频自动下一个,但题目目前需要自己答。

当前为 2023-10-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         基金业协会视频自动播放
// @namespace    https://www.nekotofu.top/
// @homepage    https://www.nekotofu.top/
// @version      0.4
// @description 基金业协会视频自动下一个,但题目目前需要自己答。
// @author       misaka10032w
// @match        *://peixun.amac.org.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=microsoft.com
// @license MIT
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    window.onload = function () {
        console.log("DOM已加载!");
        window.addEventListener('blur', function () {
            window.onblur = {}
        }, false);
        function closePopup() {
            const pop = document.querySelector(".class_float");
            if (pop.style.display != "none") {
                var close = pop.getElementsByClassName("btn-close")[0]
                close.click();
            }
        }
        let nowPlaying;
        function getCourse() {
            const courseList = document.querySelectorAll(".catalog-content a");
            for (var i = 0; i < courseList.length; i++) {
                if (!courseList[i].classList.contains("studied") && !courseList[i].classList.contains("test")) {
                    nowPlaying = courseList[i];
                    console.log(nowPlaying.textContent)
                    if(!nowPlaying.classList.contains("cur")){
                        console.log("当前视频已播放完毕");
                        nowPlaying.click();
                    }
                    return nowPlaying;
                }
            }
        }
        nowPlaying = getCourse();
        const player = document.querySelector("video");
        setTimeout(() => {
            player.muted = true;
            player.play();    
        }, 2000)
        player.addEventListener("play", function () {
            console.log("视频开始播放");
        })
        player.addEventListener("pause", function () {
            console.log("视频暂停");
            setTimeout(() => { player.play(); }, 2000)
        })
        player.addEventListener("ended", function () {
            console.log("视频播放结束");
        });
        player.addEventListener("timeupdate", function () {
            const currentTime = player.currentTime.toFixed(0);
            const duration = player.duration.toFixed(0);
            console.log(`当前时间: ${currentTime} / 总时长: ${duration}`);
            if (currentTime == duration && nowPlaying) {
                setTimeout(() => {
                    closePopup();
                    nowPlaying = getCourse();
                    nowPlaying.click();
                }, 5000);
            } else if (currentTime != currentTime && player.paused) {
                player.play();
            }     
        })
    };
})();