Greasy Fork

去除切换标签页事件

Removes all visibilitychange, pagehide, and beforeunload events from the page

目前为 2023-04-07 提交的版本。查看 最新版本

// ==UserScript==
// @name         去除切换标签页事件
// @namespace    https://github.com/GXhunter/
// @version      1.1
// @description  Removes all visibilitychange, pagehide, and beforeunload events from the page
// @match        *://*/*
// @license MIT
// @grant        unsafeWindow
// @run-at       document-idle
// ==/UserScript==

(function () {
    setTimeout(() => {
        const stopEventPropagation = (event) => {
            event.stopImmediatePropagation()
            event.stopPropagation();
            event.preventDefault();
        };
        console.log(window.getEventListeners(window))
        unsafeWindow.addEventListener('visibilitychange', stopEventPropagation, true);
        unsafeWindow.addEventListener('pagehide', stopEventPropagation, true);
        unsafeWindow.addEventListener('beforeunload', stopEventPropagation, true);
        unsafeWindow.addEventListener('blur', stopEventPropagation, true);
        unsafeWindow.addEventListener('focus', stopEventPropagation, true);
        unsafeWindow.onfocus = null
        unsafeWindow.onblur = null
        unsafeWindow.onpagehide = null
        unsafeWindow.onbeforeunload = null
    }, 1000)



})();