Greasy Fork

来自缓存

Greasy Fork is available in English.

国家智慧教育平台职教专用|去弹窗

精准处理学习完成弹窗

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         国家智慧教育平台职教专用|去弹窗
// @namespace    http://tampermonkey.net/
// @version      2025.2.25.1.000-hotfix
// @description  精准处理学习完成弹窗
// @author       deepseek
// @match        https://core.teacher.vocational.smartedu.cn/p/course/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // 弹窗处理专用配置
    const popupConfig = {
        checkInterval: 1000,      // 弹窗检测间隔
        maxAttempts: 5,           // 最大尝试次数
        zIndexThreshold: 19891014 // 弹窗最小z-index
    };

    let popupAttempts = 0;

    // 弹窗检测专用观察器
    const observer = new MutationObserver((mutations) => {
        if (popupAttempts >= popupConfig.maxAttempts) return;

        const popup = [...document.querySelectorAll('.layui-layer')]
            .filter(layer => {
                const zIndex = parseInt(layer.style.zIndex || 0);
                return zIndex >= popupConfig.zIndexThreshold;
            })
            .sort((a, b) =>
                parseInt(b.style.zIndex) - parseInt(a.style.zIndex)
            )[0];

        if (popup) {
            const confirmBtn = popup.querySelector('.layui-layer-btn0');
            if (confirmBtn) {
                // 模拟真实点击事件链
                const clickEvents = ['mousedown', 'mouseup', 'click'];
                clickEvents.forEach(eventType => {
                    confirmBtn.dispatchEvent(new MouseEvent(eventType, {
                        bubbles: true,
                        cancelable: true,
                        view: window
                    }));
                });

                console.log('成功关闭弹窗');
                popupAttempts = 0;

                // 强制移除弹窗残留
                setTimeout(() => {
                    popup.style.display = 'none';
                    popup.remove();
                }, 500);
            } else {
                popupAttempts++;
            }
        }
    });

    // 启动观察
    observer.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['style', 'class']
    });

    // 备用定时器检测
    setInterval(() => {
        const popup = document.querySelector('.layui-layer-btn0');
        if (popup) {
            popup.click();
            console.log('定时器检测关闭弹窗');
        }
    }, 2000);

    // 样式清理(可选)
    GM_addStyle(`
        .layui-layer.layui-layer-page {
            display: none !important;
        }
    `);
})();