x.com block confirm

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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