x.com autoBtn

Automatically skips the subscription window after blocking an advertising account

当前为 2024-11-25 提交的版本,查看 最新版本

// ==UserScript==
// @name           x.com autoBtn
// @name:ru        x.com автоКнопка
// @namespace      http://tampermonkey.net/
// @version        0.1
// @description    Automatically skips the subscription window after blocking an advertising account
// @description:ru Автоматически пропускает окно подписки при блокировке рекламного аккаунта
// @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==

let buttonClicked = false;
function clickButtonIfExists() {
    if (buttonClicked) 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()
            buttonClicked = true
        }
    }
}
const observer = new MutationObserver((mutationsList) => {
    for (const mutation of mutationsList) {
        if (mutation.type === 'childList' || mutation.type === 'attributes') {
            clickButtonIfExists()
        }
    }
});
const observerConfig = {
    childList: true,
    subtree: true,
    attributes: false
};
observer.observe(document.body, observerConfig)
clickButtonIfExists()