Hide Verified Posts

Hides posts from verified accounts

As of 2024-10-16. See the latest version.

// ==UserScript==
// @name         Hide Verified Posts
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Hides posts from verified accounts
// @author       bmpq
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function hideVerifiedAccountPosts() {
        const verifiedSvgs = document.querySelectorAll('svg[aria-label="Verified account"]');

        verifiedSvgs.forEach(svg => {
            let article = svg.closest('article');

            if (article) {
                const authorLink = article.querySelector('a[href^="/"][role="link"]');
                let username = 'unknown author';
                let profileUrl = '#';

                if (authorLink && authorLink.getAttribute('href')) {
                    username = authorLink.getAttribute('href').substring(1);
                    profileUrl = authorLink.getAttribute('href');
                }

                const infoDiv = document.createElement('div');
                infoDiv.style.color = 'rgb(113, 118, 123)';
                infoDiv.style.fontFamily = 'TwitterChirp, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif';
                infoDiv.style.padding = '10px 10px';

                const link = document.createElement('a');
                link.href = profileUrl;
                link.textContent = `@${username}`;
                link.style.color = 'inherit';
                link.style.textDecoration = 'none';

                infoDiv.textContent = `Hidden verified post from `;
                infoDiv.appendChild(link);

                article.replaceWith(infoDiv);
            }
        });
    }

    hideVerifiedAccountPosts();

    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            hideVerifiedAccountPosts();
        });
    });

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