Auto Delete Tweet Confirmation

Automatically confirm tweet deletion on X.com

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Auto Delete Tweet Confirmation
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Automatically confirm tweet deletion on X.com
// @author       wez + chatgpt
// @match        https://x.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to click the confirmation button
    function clickConfirmButton() {
        const confirmButton = document.querySelector('[data-testid="confirmationSheetConfirm"]');
        if (confirmButton) {
            console.log('Confirmation button found, clicking...');
            confirmButton.click(); // Click to confirm deletion
        } else {
            console.log('Confirmation button not found.');
        }
    }

    // Create a MutationObserver to detect when the confirmation dialog appears
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            // Check if the confirmation dialog is in the DOM
            if (mutation.addedNodes.length) {
                mutation.addedNodes.forEach((node) => {
                    if (node.nodeType === Node.ELEMENT_NODE && node.querySelector('[data-testid="confirmationSheetDialog"]')) {
                        console.log('Confirmation dialog detected, attempting to click confirm button...');
                        clickConfirmButton(); // Attempt to click the confirm button
                    }
                });
            }
        });
    });

    // Start observing the body for changes
    observer.observe(document.body, { childList: true, subtree: true });

    console.log('Auto Delete Tweet Confirmation script loaded');
})();