关闭 Twitter 媒体警告

关闭 Twitter 网页上的媒体警告

目前为 2024-04-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         Close Twitter Media Warning
// @name:ja      Close Twitter Media Warning
// @name:zh-cn   关闭 Twitter 媒体警告
// @name:zh-tw   關閉 Twitter 媒體警告
// @description         Automatic closure of Twitter webpage's media warning.
// @description:ja      Twitter ウェブページのメディア警告を自動的に閉じる
// @description:zh-cn   关闭 Twitter 网页上的媒体警告
// @description:zh-tw   關閉 Twitter 網頁上的媒體警告
// @namespace    none
// @version      0.1.1
// @author       ShanksSU
// @match        https://twitter.com/*
// @match        https://twitter.com/*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant        none
// @compatible   Chrome
// @license      MIT
// ==/UserScript==

const ButtonAutoClicker = (function () {
    var targetSelectors = [
        '.css-175oi2r[role="button"][tabindex="0"]',
        '.css-1rynq56[role="button"][tabindex="0"]'
    ];

    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            checkButtons(mutation.target);
        });
    });

    function checkButtons(targetNode) {
        targetSelectors.forEach(function(selector) {
            var buttons = targetNode.querySelectorAll(selector);
            if (buttons) {
                buttons.forEach(function(button) {
                    if (button.textContent.trim() === "Show" && isVisible(button) && !isClicked(button)) {
                        button.click();
                        console.log("Button clicked.");
                    }
                });
            }
        });
    }

    function isVisible(element) {
        return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
    }

    var clickedButtons = new Set();
    function isClicked(button) {
        if (clickedButtons.has(button)) {
            return true;
        }
        clickedButtons.add(button);
        return false;
    }

    function init() {
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    return {
        init: init
    };
})();

ButtonAutoClicker.init();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址