x.com block confirm

Clicks on "Block" and "Maybe later" buttons on Twitter

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           x.com block confirm
// @namespace      http://tampermonkey.net/
// @version        0.2.2
// @description    Clicks on "Block" and "Maybe later" buttons on Twitter
// @author         CiNoP
// @license        GPL-3.0-only
// @match          https://x.com/*
// @icon           https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant          none
// ==/UserScript==
/* jshint esversion: 11 */
/* jshint asi: true */
 
(() => {
    let blockProcessButtonClicked = false
    let blockProcessConfirmButtonClicked = false
 
    function clickBlockButtonIfExists() {
        if (blockProcessButtonClicked) return
        const blockButton = document.querySelector('div[data-testid="block"]')
        const ruBlockButton = document.querySelector('div[data-testid="В черный список"]')
        if (blockButton || ruBlockButton) {
            console.log('Кнопка блокировки найдена, ожидаем подтверждения...')
            ;(blockButton || ruBlockButton).addEventListener('click', () => {
                blockProcessButtonClicked = true
                observeConfirmButton()
            })
        }
    }
 
    function clickConfirmButtonIfExists() {
        const confirmButton = Array.from(document.querySelectorAll('button[data-testid="confirmationSheetConfirm"]')).find(button =>
            button.textContent.includes('В черный список') || button.textContent.includes('Block')
        )
        if (confirmButton) {
            console.log('Кнопка подтверждения найдена, кликаю...')
            confirmButton.click()
            blockProcessConfirmButtonClicked = true
            setTimeout(() => {
                blockProcessButtonClicked = false
                blockProcessConfirmButtonClicked = false
            }, 300)
        }
    }
 
    function observeConfirmButton() {
        const confirmObserver = new MutationObserver(() => {
            clickConfirmButtonIfExists()
        })
        confirmObserver.observe(document.body, {
            childList: true,
            subtree: true
        })
    }
 
    const blockObserver = new MutationObserver(() => {
        clickBlockButtonIfExists()
    })
    const blockObserverConfig = {
        childList: true,
        subtree: true,
        attributes: false
    }
    blockObserver.observe(document.body, blockObserverConfig)
    clickBlockButtonIfExists()
})();
 
(() => {
    let forYouButtonClicked = false
 
    function clickForYouButtonIfExists() {
        if (forYouButtonClicked) return
        const forYouButton = Array.from(document.querySelectorAll('a[role="tab"]')).find(el =>
            el.textContent.trim() === "Для вас" || el.textContent.trim() === "For you"
        )
        if (forYouButton) {
            const buttonText = forYouButton.textContent.trim() === "Для вас" ? "Не сейчас" : "Maybe later"
            const targetButton = Array.from(document.querySelectorAll('button')).find(
                btn => btn.textContent.trim() === buttonText
            )
            if (targetButton) {
                console.log(`Кнопка "${buttonText}" найдена, кликаю...`)
                targetButton.click()
                forYouButtonClicked = true
                setTimeout(() => {
                    forYouButtonClicked = false
                }, 300)
            }
        }
    }
 
    function observeForYouChanges() {
        const observer = new MutationObserver(() => {
            clickForYouButtonIfExists()
        })
        observer.observe(document.body, {
            childList: true,
            subtree: true
        })
    }
 
    function observePostAddedChanges() {
        const observer = new MutationObserver(() => {
            clickForYouButtonIfExists()
        })
        observer.observe(document.body, {
            childList: true,
            subtree: true
        })
    }
 
    observeForYouChanges()
    observePostAddedChanges()
    clickForYouButtonIfExists()
})()