Reddit Confirm Save/Submit ⚠️

Display a confirmation popup before submitting or editing content

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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