Twitter UI Cleanup

Remove unwanted buttons and sections on Twitter

当前为 2025-01-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter UI Cleanup
  3. // @namespace https://github.com/Daminator4113/Twitter-UI-Cleanup
  4. // @version 1.0
  5. // @author Daminator4113
  6. // @description Remove unwanted buttons and sections on Twitter
  7. // @license MIT
  8. // @icon https://abs.twimg.com/favicons/twitter.2.ico
  9. // @match https://twitter.com/*
  10. // @match https://x.com/*
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const removeElements = () => {
  17. const selectors = [
  18. 'a[href*="/i/grok"]', // Grok
  19. 'a[href*="/i/premium_sign_up"]', // Twitter Blue
  20. 'a[href*="/i/verified-orgs-signup"]', // Verified organizations
  21. 'button[data-testid="grokImgGen"]' // "Generate Image with Grok" button
  22. ];
  23.  
  24. const premiumLinkContainer = document.querySelector('aside a[href*="/i/premium_sign_up"]')?.closest('div')?.parentElement; // "Try Premium for free" section
  25. if (premiumLinkContainer?.tagName === 'DIV') {
  26. premiumLinkContainer.remove();
  27. }
  28.  
  29. selectors.forEach(selector => {
  30. document.querySelectorAll(selector).forEach(el => el.remove());
  31. });
  32. };
  33.  
  34. const observer = new MutationObserver(() => {
  35. removeElements();
  36. });
  37.  
  38. observer.observe(document.body, {
  39. childList: true,
  40. subtree: true
  41. });
  42.  
  43. removeElements();
  44. })();