Remove mouse restrictions and automatically close pop-up windows

Auto Close Popups for Learning Site & Block Mouse Leave Popup Improved

目前為 2024-11-07 提交的版本,檢視 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Remove mouse restrictions and automatically close pop-up windows
// @namespace    https://mbt.jd.com/cards/ffksimple/home.html?channelName=wdqb_sy_icon&do_not_click_on_me
// @namespace    https://t.me/mycutcbot
// @version      0.21
// @description  Auto Close Popups for Learning Site & Block Mouse Leave Popup Improved
// @author       ziqs
// @match        *://*.study.moxueyuan.com/*
// @grant        none
// @license      GPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';

    // 定義一個阻止事件的函數
    function preventEvent(e) {
        e.stopImmediatePropagation();
        e.preventDefault();
    }

    // 監聽 `mouseleave`, `mouseout`, 和 `blur` 事件
    ['mouseleave', 'mouseout', 'blur'].forEach(eventType => {
        window.addEventListener(eventType, preventEvent, true);
        document.addEventListener(eventType, preventEvent, true);
    });

    // 定時移除動態新增的事件監聽器
    const observer = new MutationObserver(() => {
        document.querySelectorAll('*').forEach(element => {
            try {
                element.onmouseleave = null;
                element.onmouseout = null;
                element.onblur = null;
            } catch (error) {
                console.error(`Error clearing event listeners on ${element}`, error);
            }
        });
    });

    // 開始監聽 DOM 變化
    observer.observe(document.body, { childList: true, subtree: true });

})();



(function() {
    'use strict';

    // 監聽 <body> 的類別名稱變化
    const observer = new MutationObserver((mutationsList) => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
                const bodyClass = document.body.className;

                // 檢查是否包含 el-popup-parent--hidden 類
                if (bodyClass.includes('el-popup-parent--hidden')) {
                    console.log('Popup detected, attempting to click "I am here" button after delay');

                    // 延遲 5 秒點擊按鈕
                    setTimeout(() => {
                        // 尋找所有符合條件的按鈕
                        const buttons = document.querySelectorAll('.dialog-footer-cancel');
                        for (const button of buttons) {
                            if (button.textContent.includes('我在')) {
                                button.click();
                                console.log('"I am here" button clicked after 5 seconds');
                                break;
                            }
                        }
                    }, 5000); // 5秒延遲(5000毫秒)
                }
            }
        }
    });

    // 開始監聽 <body> 的屬性變化
    observer.observe(document.body, { attributes: true });

})();