Reddit Confirm Save/Submit ⚠️

Display a confirmation popup before submitting or editing content

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         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);
})();