Exit Popup Blocker

Blocks annoying exit popups and prevents websites from holding the browser hostage

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Exit Popup Blocker
// @namespace    RXhpdCBQb3B1cCBCbG9ja2Vy
// @version      1.1
// @description  Blocks annoying exit popups and prevents websites from holding the browser hostage
// @author       smed79
// @license      GPLv3
// @icon         https://i25.servimg.com/u/f25/11/94/21/24/exit10.png
// @match        *://*/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // We must inject this directly into the page's execution environment (Main World)
    const payload = `(function() {
        try {
            // 1. Neutralize the standard 'onbeforeunload' property
            Object.defineProperty(window, 'onbeforeunload', {
                get: () => null,
                set: () => {}, // Silently ignore any attempts to set an exit popup
                configurable: false
            });

            // 2. Neutralize modern 'addEventListener' exit popups
            const originalAddEventListener = EventTarget.prototype.addEventListener;
            EventTarget.prototype.addEventListener = function(type, listener, options) {
                // If the website tries to add a 'beforeunload' event, we just drop it into the void
                if (type === 'beforeunload') {
                    return; 
                }
                // Otherwise, let the event function normally
                return originalAddEventListener.apply(this, arguments);
            };
        } catch (e) {}
    })();`;

    // Create the script tag
    const script = document.createElement('script');
    script.textContent = payload;

    // Inject the script instantly at document-start before the website can load its own scripts
    if (document.documentElement) {
        document.documentElement.appendChild(script);
        script.remove(); // Clean up the tag so the website doesn't know we are there
    }
})();