Greasy Fork

来自缓存

Greasy Fork is available in English.

X.com Quick Mute Button

Adds a "Mute" button next to usernames on X.com and uses the dropdown menu to trigger the mute functionality.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         X.com Quick Mute Button
// @namespace    http://greasyfork.icu/users/710133
// @version      1.0
// @description  Adds a "Mute" button next to usernames on X.com and uses the dropdown menu to trigger the mute functionality.
// @author       tomcatadam
// @match        https://*.x.com/*
// @match        https://x.com/*
// @match        https://twitter.com/*
// @match        https://*.twitter.com/*
// @icon         https://x.com/favicon.ico
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    const observer = new MutationObserver(() => {
        // Find user elements that don't already have a mute button
        document.querySelectorAll('div[data-testid="User-Name"]:not(.mute-enhanced)').forEach(user => {
            user.classList.add('mute-enhanced');

            // Create the "Mute" button
            const muteButton = document.createElement('button');
            muteButton.innerText = 'Mute';
            muteButton.style.marginLeft = '10px';
            muteButton.style.backgroundColor = '#e6f4ff'; // Pale blue background
            muteButton.style.color = '#1d9bf0'; // X.com's brand blue for text
            muteButton.style.border = '1px solid #1d9bf0'; // Border matches text color
            muteButton.style.borderRadius = '3px';
            muteButton.style.padding = '2px 6px';
            muteButton.style.fontSize = '12px';
            muteButton.style.cursor = 'pointer';

            // Handle mute functionality
            muteButton.addEventListener('click', () => {
                const menuButton = user.closest('article').querySelector('button[data-testid="caret"]');
                if (menuButton) {
                    // Open the dropdown menu
                    menuButton.click();

                    // Wait for the dropdown to appear and select the mute option
                    const interval = setInterval(() => {
                        const muteOption = Array.from(document.querySelectorAll('div[role="menuitem"]'))
                            .find(el => el.textContent.includes('Mute'));

                        if (muteOption) {
                            muteOption.click();
                            clearInterval(interval); // Stop checking once the option is clicked
                        }
                    }, 100); // Check every 100ms

                    // Stop trying after 2 seconds if the mute option is not found
                    setTimeout(() => clearInterval(interval), 2000);
                } else {
                    alert('Menu button not found!');
                }
            });

            // Add the button next to the username
            user.appendChild(muteButton);
        });
    });

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