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.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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();
    }

})();