Greasy Fork

Greasy Fork is available in English.

Show Twitter Censored Media Section

Modifies the CSS classes to automatically show censored media on Twitter in desktop mode

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Show Twitter Censored Media Section
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Modifies the CSS classes to automatically show censored media on Twitter in desktop mode
// @author       hacim17h
// @match        https://twitter.com/*
// @match        https://x.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to modify classes of children for specific parent divs
    function modifyChildClasses() {
        const parentDivs = document.querySelectorAll('.css-175oi2r.r-18u37iz.r-9aw3ui.r-4amgru.r-14gqq1x');
        parentDivs.forEach(parentDiv => {
            const children = parentDiv.querySelectorAll('.css-175oi2r.r-1udh08x, .css-175oi2r.r-yfv4eo');
            children.forEach(child => {
                // You could adjust here if you want to keep some of the old classes
                child.className = 'css-175oi2r r-1adg3ll r-1ny4l3l';
            });
        });
    }

    // Function to remove specific divs by a complex class string
    function removeSpecificDivs() {
        const elements = document.querySelectorAll('.css-175oi2r.r-1awozwy.r-1p0dtai.r-zchlnj.r-1cmwbt1.r-1777fci.r-edyy15.r-u8s1d.r-1d2f490.r-ipm5af');
        elements.forEach(element => element.remove());
    }

    // MutationObserver for dynamic content handling
    const observer = new MutationObserver(mutations => {
        mutations.forEach(() => {
            modifyChildClasses();
            removeSpecificDivs();
        });
    });

    const config = { childList: true, subtree: true };
    observer.observe(document.body, config);

    // Initial call to functions
    modifyChildClasses();
    removeSpecificDivs();
})();