四川省继续教育网站尝试修复自动播放

网课会自动下一节但是播放列表里面不会变化,导致不能自动切到下一堂课,尝试10分钟刷新一次来规避这个bug

// ==UserScript==
// @name         四川省继续教育网站尝试修复自动播放
// @namespace    http://tampermonkey.net/
// @version      2.3
// @description  网课会自动下一节但是播放列表里面不会变化,导致不能自动切到下一堂课,尝试10分钟刷新一次来规避这个bug
// @match        https://edu.chinahrt.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', () => {

        const delay = 5000; // 延迟 3 秒
        const refreshInterval = 10 * 60 * 1000; // 10分钟刷新
        const specialElementSelector = 'div.n-element.__element-q8o5bu.h-3.w-3.bg-gray-500.rounded-1\\/2.mr-1';

        setTimeout(() => {

            let clickedType = null; // 标记点击的是哪种元素

            // 1️⃣ 优先找 canvas
            const fanCanvases = document.querySelectorAll('canvas.fan-canvas.mr-1[data-v-dd237e02]');
            if (fanCanvases.length > 0) {
                const lastCanvas = fanCanvases[fanCanvases.length - 1];
                console.log('找到最后一个 fan-canvas,模拟点击');
                lastCanvas.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
                clickedType = "canvas";
            } else {
                // 2️⃣ 没有 canvas,尝试找 specialElement
                const specialElement = document.querySelector(specialElementSelector);
                if (specialElement) {
                    console.log('找到 specialElement,模拟点击');
                    specialElement.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
                    clickedType = "specialElement";
                } else {
                    // 3️⃣ 再去找 √
                    console.log('没有找到 canvas 或 specialElement,尝试找 √ 图标');
                    const checkmarkSvgs = document.querySelectorAll('svg.icon-CheckmarkCircleSharp');
                    if (checkmarkSvgs.length > 0) {
                        const lastSvg = checkmarkSvgs[checkmarkSvgs.length - 1];
                        console.log('找到最后一个 √ 图标,模拟点击');
                        lastSvg.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
                        clickedType = "checkmark";
                    } else {
                        console.log('没有找到 √ 图标');
                    }
                }
            }

            // 4️⃣ 定义启动刷新计时器
            const startRefreshTimer = () => {
                let remainingTime = refreshInterval;
                const progressDiv = document.createElement('div');
                progressDiv.style.position = 'fixed';
                progressDiv.style.bottom = '10px';
                progressDiv.style.right = '10px';
                progressDiv.style.padding = '5px 10px';
                progressDiv.style.background = 'rgba(0,0,0,0.7)';
                progressDiv.style.color = 'white';
                progressDiv.style.borderRadius = '5px';
                progressDiv.style.zIndex = 9999;
                progressDiv.textContent = `刷新倒计时: ${Math.ceil(remainingTime/1000)}秒`;
                document.body.appendChild(progressDiv);

                const timer = setInterval(() => {
                    remainingTime -= 1000;
                    if (remainingTime <= 0) {
                        clearInterval(timer);
                        location.reload();
                    } else {
                        progressDiv.textContent = `刷新倒计时: ${Math.ceil(remainingTime/1000)}秒`;
                    }
                }, 1000);
            };

            // 5️⃣ 刷新逻辑
            if (clickedType === "canvas") {
                // canvas → 等待 specialElement 出现再刷新
                const specialElement = document.querySelector(specialElementSelector);
                if (specialElement) {
                    startRefreshTimer();
                } else {
                    console.log('元素不存在,等待出现后再启动倒计时刷新');
                    const observer = new MutationObserver((mutations, obs) => {
                        const el = document.querySelector(specialElementSelector);
                        if (el) {
                            console.log('元素出现,开始倒计时刷新');
                            obs.disconnect();
                            startRefreshTimer();
                        }
                    });
                    observer.observe(document.body, { childList: true, subtree: true });
                }
            } else if (clickedType === "specialElement") {
                // specialElement → 直接刷新
                startRefreshTimer();
            } else if (clickedType === "checkmark") {
                // √ → 不刷新
                console.log('点击 √ 图标,不刷新');
            } else {
                console.log('没有点击到任何目标,不刷新');
            }

        }, delay);

    });
})();