ChatGPT Edit Cancel Confirmation

Adds a confirmation dialog when clicking the Cancel button when editing messages

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         ChatGPT Edit Cancel Confirmation
// @namespace    https://github.com/GooglyBlox
// @version      1.0
// @description  Adds a confirmation dialog when clicking the Cancel button when editing messages
// @author       GooglyBlox
// @match        https://chatgpt.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function handleCancelClick(event) {
        const target = event.target.closest('button');
        if (target &&
            target.classList.contains('btn-secondary') &&
            target.textContent.trim() === 'Cancel') {

            event.stopPropagation();
            event.preventDefault();

            if (confirm('Are you sure you want to cancel?')) {
                document.removeEventListener('click', handleCancelClick, true);

                target.click();

                setTimeout(() => {
                    document.addEventListener('click', handleCancelClick, true);
                }, 0);
            }
        }
    }

    document.addEventListener('click', handleCancelClick, true);
})();