Let Me Leave, Bro

Do you hate "Are you SURE you want to leave this page?" dialogs that pop up when you try to close a tab? So do I. This is a Chrome extension and Tampermonkey script that prevents execution of those Javascript dialogs that prevent you from leaving a page.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Let Me Leave, Bro
// @author       Christopher Conley
// @copyright    Copyright (C) 2024 Christopher Conley
// @license      MIT
// @version      2024.12.30.0851
// @description  Do you hate "Are you SURE you want to leave this page?" dialogs that pop up when you try to close a tab? So do I. This is a Chrome extension and Tampermonkey script that prevents execution of those Javascript dialogs that prevent you from leaving a page.
// @namespace    https://github.com/rosettast0ned/let-me-leave-bro
// @source       https://github.com/rosettast0ned/let-me-leave-bro
// @supportURL   https://github.com/rosettast0ned/let-me-leave-bro/issues
// @match        *://*/*
// @icon         https://raw.githubusercontent.com/rosettast0ned/let-me-leave-bro/refs/heads/main/tampermonkey/let_me_leave_bro.png
// @icon64       https://raw.githubusercontent.com/rosettast0ned/let-me-leave-bro/refs/heads/main/tampermonkey/let_me_leave_bro64.png
// @run-at       document-start
// ==/UserScript==
//
//

(function () {
    console.log('LMLB: Let Me Leave, Bro extension loaded.')

    const StopIt = (event) => {
        console.log('LMLB: Intercepting unload events.')
        event.stopImmediatePropagation();
        event.stopPropagation();
    };

    const AddListeners = () => {
        window.addEventListener("beforeunload", StopIt, { capture: true });
        document.addEventListener("beforeunload", StopIt, { capture: true });
        window.addEventListener("unload", StopIt, { capture: true });
        document.addEventListener("unload", StopIt, { capture: true });
        console.log('LMLB: Added listeners.');
    };

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', () => {
            console.log('LMLB: Document loaded, adding listeners.');
            AddListeners();
        });
    } else {
        console.log('LMLB: Document already loaded, adding listeners.');
        AddListeners();
    }

})();