Reddit Confirm Save/Submit ⚠️

Display a confirmation popup before submitting or editing content

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Reddit Confirm Save/Submit ⚠️
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Display a confirmation popup before submitting or editing content
// @author       Agreasyforkuser
// @icon         https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    function getUsername() {
        const userSpan = document.querySelector('span.user a');
        if (userSpan) {
            const username = userSpan.textContent;
            const maskedUsername = username
                .split('')
                .map((char, index) => (index % 3 === 2 ? '*' : char))
                .join('');
            return maskedUsername;
        }
        return 'Unknown User';
    }

    function confirmButtonClick(event) {
        const target = event.target;
        const buttonText = target.textContent.trim().toLowerCase();

        // exclude save-post and save-comment buttons
        if (target.closest('.link-save-button, .link-unsave-button, .entry')) {
            return;
        }


        if (['save', 'submit'].includes(buttonText)) {
            const username = getUsername();
            if (!confirm(`⚠️${username}⚠️`)) {
                event.preventDefault();
                event.stopPropagation();
            }
        }
    }

    document.body.addEventListener('click', confirmButtonClick);
})();