Greasy Fork

Greasy Fork is available in English.

四川智慧教育全自动学习(纯净稳定版 + 2x)

自动播放 / 自动下一节 / 后台不暂停 / 2倍速 / 异常自动恢复

当前为 2025-12-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         四川智慧教育全自动学习(纯净稳定版 + 2x)
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  自动播放 / 自动下一节 / 后台不暂停 / 2倍速 / 异常自动恢复
// @match        *://*.sc.smartedu.cn/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    console.log("📘 智慧教育自动学习脚本已启动(稳定版)");

    const CHECK_INTERVAL = 3000;
    const MAX_RETRY = 5;
    let retryCount = 0;

    // ================= 工具函数 =================
    function sleep(ms) {
        return new Promise(r => setTimeout(r, ms));
    }

    function getVideo() {
        return document.querySelector("video");
    }

    function getCurrentLesson() {
        return document.querySelector(".subsectionNameContent_fir.studying");
    }

    function getNextLesson() {
        const cur = getCurrentLesson();
        if (!cur) return null;

        const item = cur.closest(".subsectionNameContent");
        if (!item) return null;

        const next = item.nextElementSibling;
        if (next) return next;

        const chapter = item.closest(".chaptercell");
        return chapter?.nextElementSibling?.querySelector(".subsectionNameContent");
    }

    // ================= 核心播放 =================
    function forcePlay(reason = "") {
        const v = getVideo();
        if (!v) return;

        try {
            v.muted = true;
            v.playbackRate = 2.0;
            const p = v.play();
            if (p) p.catch(() => {});
            console.log("▶ 播放中", reason);
        } catch (e) {}
    }

    function bindVideoEvents() {
        const v = getVideo();
        if (!v) return;

        v.onended = async () => {
            console.log("✅ 当前视频播放完成");
            await sleep(1500);
            goNext();
        };

        v.onerror = () => {
            console.warn("⚠ 视频异常,尝试修复");
            retryPlay();
        };

        v.onpause = () => {
            setTimeout(() => {
                if (v.paused) forcePlay("pause-fix");
            }, 800);
        };
    }

    function retryPlay() {
        const v = getVideo();
        if (!v) return;

        if (retryCount >= MAX_RETRY) {
            console.warn("❌ 多次失败,刷新页面");
            location.reload();
            return;
        }

        retryCount++;
        v.load();
        setTimeout(() => forcePlay("retry"), 1000);
    }

    // ================= 自动下一节 =================
    function goNext() {
        const next = getNextLesson();
        if (!next) {
            console.log("🎉 所有课程播放完成");
            return;
        }

        const btn = next.querySelector(".subsectionStudy span");
        if (btn) {
            console.log("➡️ 进入下一节");
            btn.click();
            retryCount = 0;
        }
    }

    // ================= 防后台暂停 =================
    function antiBackgroundPause() {
        document.addEventListener("visibilitychange", () => {
            if (document.hidden) forcePlay("background");
        });

        setInterval(() => {
            const v = getVideo();
            if (v && v.paused) {
                forcePlay("interval");
            }
        }, CHECK_INTERVAL);
    }

    // ================= 启动 =================
    function start() {
        forcePlay("init");
        bindVideoEvents();
        antiBackgroundPause();
    }

    setTimeout(start, 3000);

})();