Reddit Confirm Save/Submit ⚠️

Display a confirmation popup when clicking a button with the text 'save'/'submit'.

目前為 2023-07-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Reddit Confirm Save/Submit ⚠️
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Display a confirmation popup when clicking a button with the text 'save'/'submit'.
// @author       Agreasyforkuser
// @icon         https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png
// @match        https://*.reddit.com/*
// @grant        none
// @license      MIT
// ==/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();
        if (['save', 'submit'].includes(buttonText)) {
            const username = getUsername();
            if (!confirm(`⚠️${username}⚠️`)) {
                event.preventDefault();
                event.stopPropagation();
            }
        }
    }

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