Greasy Fork

Greasy Fork is available in English.

Close Twitter Media Warning

Automatic closure of Twitter webpage's media warning.

当前为 2024-04-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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