x.com block confirm

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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()
})()