Greasy Fork

Greasy Fork is available in English.

高校邦视频自动播放

Automatically play and continue videos on GaoXiaoBang.

当前为 2025-04-11 提交的版本,查看 最新版本

// ==UserScript==
// @name         高校邦视频自动播放
// @namespace    https://tampermonkey.net/
// @version      2025-04-10
// @description  Automatically play and continue videos on GaoXiaoBang.
// @author       Nyaser
// @match        *://*.class.gaoxiaobang.com/class/*/unit/*/chapter/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gaoxiaobang.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var video;

    function goNext() {
        var next = document.querySelector("#chapterLayout > div.chapter-info > span.chapter-next.gxb-cur-point > i");
        console.log("Moving to next chapter");
        next.click();
    }

    function heartbeat() {
        if (video.paused) {
            console.log("Resuming playback");
            video.play();
        }

        var progress = document.querySelector("div.cont > div.clear-fix.videoTit > div.progress > span");
        if (progress !== null) {
            console.log("Current progress:", progress.innerText + "%");
            if (progress.innerText == "100") {
                console.log("Progress reached 100%");
                goNext();
            }
        } else {
            console.log("Progress element not found");
            goNext();
        }
    }

    function checkVideoWithRetry(attempts) {
        return new Promise((resolve) => {
            function checkVideo() {
                video = document.querySelector("#video_player_html5_api");

                if (video) {
                    video.muted = true;
                    video.play();
                    console.log("Video found and muted");
                    resolve(true);
                } else if (attempts > 0) {
                    console.log("Video not found, retrying in 1 second");
                    console.log("Attempts left:", attempts);
                    setTimeout(checkVideo, 1e3);
                    attempts--;
                } else {
                    console.log("Video not found after all attempts");
                    resolve(false);
                }
            }

            checkVideo();
        });
    }

    function activate() {
        checkVideoWithRetry(3)
            .then(res => {
            if (res) setInterval(heartbeat, 1e3);
            else goNext();
        })
    }

    window.onload = activate;
})();