Block Mouse Leave

Block Mouse Leave Popup Improved

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Block Mouse Leave
// @namespace    https://t.me/mycutcbot
// @version      0.1
// @description  Block Mouse Leave Popup Improved
// @author       ziqs
// @match        *://*/*
// @license      GPL-3.0-or-later
// @grant        none
// ==/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 });

})();