Hide Twitter Verified Checkmarks

Hide the "Get verified" nag and/or all checkmarks

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hide Twitter Verified Checkmarks
// @version      1.1
// @description  Hide the "Get verified" nag and/or all checkmarks
// @author       Zira Ott
// @namespace    dev.foxs.userscripts.twitter-checkmarks
// @license      MIT
// @match        https://x.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=x.com
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    // Settings

    // Load the toggle states (default to true for both)
    let hideVerifiedNag = GM_getValue('hideVerifiedNag', true);
    let hideCheckmarks = GM_getValue('hideCheckmarks', true);

    let hideVerifiedNagCommand;
    let hideCheckmarksCommand;

    // Clear existing commands and add new ones with the current states
    function updateMenuCommands() {
        if (hideVerifiedNagCommand) GM_unregisterMenuCommand(hideVerifiedNagCommand);
        if (hideCheckmarksCommand) GM_unregisterMenuCommand(hideCheckmarksCommand);

        hideVerifiedNagCommand = GM_registerMenuCommand(`${hideVerifiedNag ? '✅' : '🔳'} Hide "Get Verified" Nag`, toggleVerifiedNag);
        hideCheckmarksCommand = GM_registerMenuCommand(`${hideCheckmarks ? '✅' : '🔳'} Hide All Checkmarks`, toggleCheckmarks);
    }

    function toggleVerifiedNag() {
        hideVerifiedNag = !hideVerifiedNag;
        GM_setValue('hideVerifiedNag', hideVerifiedNag);
        updateNagVisibility();
        updateMenuCommands();
    }

    function toggleCheckmarks() {
        hideCheckmarks = !hideCheckmarks;
        GM_setValue('hideCheckmarks', hideCheckmarks);
        updateCheckmarkVisibility();
        updateMenuCommands();
    }

    // Actual magic

    function updateNagVisibility() {
        const nagElement = document.querySelector('div[data-testid="UserName"] a[href="/i/premium_sign_up"]');

        if (nagElement && nagElement.parentElement && nagElement.parentElement.parentElement) {
            nagElement.parentElement.parentElement.style.display = hideVerifiedNag ? 'none' : 'block';
        }
    }

    function updateCheckmarkVisibility() {
        const checkmarks = document.querySelectorAll('svg[data-testid="icon-verified"]');
        checkmarks.forEach(checkmark => {
            checkmark.style.display = hideCheckmarks ? 'none' : 'block';
        });
    }

    // Events

    // Set up a MutationObserver to watch for changes in the DOM
    const observer = new MutationObserver(() => {
        updateNagVisibility();
        updateCheckmarkVisibility();
    });

    // Start observing the document body for changes
    observer.observe(document.body, { childList: true, subtree: true });

    // Run the functions initially in case elements are already present
    updateNagVisibility();
    updateCheckmarkVisibility();

    // Initialize the menu commands
    updateMenuCommands();
})();