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.

当前为 2024-11-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name X.com Quick Mute Button
  3. // @namespace https://gf.qytechs.cn/users/710133
  4. // @version 1.0
  5. // @description Adds a "Mute" button next to usernames on X.com and uses the dropdown menu to trigger the mute functionality.
  6. // @author tomcatadam
  7. // @match https://*.x.com/*
  8. // @match https://x.com/*
  9. // @match https://twitter.com/*
  10. // @match https://*.twitter.com/*
  11. // @icon https://x.com/favicon.ico
  12. // @grant none
  13. // @license MIT
  14. // @run-at document-end
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. 'use strict';
  19.  
  20. const observer = new MutationObserver(() => {
  21. // Find user elements that don't already have a mute button
  22. document.querySelectorAll('div[data-testid="User-Name"]:not(.mute-enhanced)').forEach(user => {
  23. user.classList.add('mute-enhanced');
  24.  
  25. // Create the "Mute" button
  26. const muteButton = document.createElement('button');
  27. muteButton.innerText = 'Mute';
  28. muteButton.style.marginLeft = '10px';
  29. muteButton.style.backgroundColor = '#e6f4ff'; // Pale blue background
  30. muteButton.style.color = '#1d9bf0'; // X.com's brand blue for text
  31. muteButton.style.border = '1px solid #1d9bf0'; // Border matches text color
  32. muteButton.style.borderRadius = '3px';
  33. muteButton.style.padding = '2px 6px';
  34. muteButton.style.fontSize = '12px';
  35. muteButton.style.cursor = 'pointer';
  36.  
  37. // Handle mute functionality
  38. muteButton.addEventListener('click', () => {
  39. const menuButton = user.closest('article').querySelector('button[data-testid="caret"]');
  40. if (menuButton) {
  41. // Open the dropdown menu
  42. menuButton.click();
  43.  
  44. // Wait for the dropdown to appear and select the mute option
  45. const interval = setInterval(() => {
  46. const muteOption = Array.from(document.querySelectorAll('div[role="menuitem"]'))
  47. .find(el => el.textContent.includes('Mute'));
  48.  
  49. if (muteOption) {
  50. muteOption.click();
  51. clearInterval(interval); // Stop checking once the option is clicked
  52. }
  53. }, 100); // Check every 100ms
  54.  
  55. // Stop trying after 2 seconds if the mute option is not found
  56. setTimeout(() => clearInterval(interval), 2000);
  57. } else {
  58. alert('Menu button not found!');
  59. }
  60. });
  61.  
  62. // Add the button next to the username
  63. user.appendChild(muteButton);
  64. });
  65. });
  66.  
  67. // Start observing the page
  68. observer.observe(document.body, { childList: true, subtree: true });
  69. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址