高校邦视频自动播放

Automatically play and continue videos on GaoXiaoBang.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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;
})();