Twitter UI Cleanup

Remove unwanted buttons and sections on Twitter

  1. // ==UserScript==
  2. // @name Twitter UI Cleanup
  3. // @namespace https://github.com/Daminator4113/Twitter-UI-Cleanup
  4. // @version 1.2
  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 removeParent = (selector, levels, tagName) => {
  17. const element = document.querySelector(selector);
  18. if (element) {
  19. let parent = element;
  20. for (let i = 0; i < levels; i++) {
  21. parent = parent.parentElement;
  22. if (!parent) break;
  23. }
  24. if (parent?.tagName === tagName) {
  25. //console.log('REMOVE',parent);
  26. parent.remove();
  27. }
  28. }
  29. };
  30.  
  31. // The order of removal is important!
  32. const removeElements = () => {
  33. const selectors = [
  34. 'a[href*="/i/grok"]', // Grok
  35. 'a[data-testid="premium-signup-tab"]', // Twitter Blue
  36. 'a[data-testid="vo-signup-tab"]', // Verified organizations
  37. 'button[data-testid="grokImgGen"]', // "Generate Image with Grok" button.
  38. ];
  39.  
  40. selectors.forEach(selector => {
  41. document.querySelectorAll(selector).forEach(el => el.remove());
  42. });
  43.  
  44. removeParent('a[href*="/i/premium_sign_up"]', 4, 'DIV'); // "Try Premium for free" section
  45. removeParent('div[data-testid="GrokDrawerHeader"]', 1, 'DIV'); // Grok Drawer → I don't know why, but removing the "GrokDrawer" div deactivate the autoplay for videos?
  46.  
  47. const grokSVG = 'path[d="M2.205 7.423L11.745 21h4.241L6.446 7.423H2.204zm4.237 7.541L2.2 21h4.243l2.12-3.017-2.121-3.02zM16.957 0L9.624 10.435l2.122 3.02L21.2 0h-4.243zm.767 6.456V21H21.2V1.51l-3.476 4.946z"]';
  48. removeParent(grokSVG, 4, 'BUTTON'); // Grok profil resume
  49. removeParent(grokSVG, 5, 'BUTTON'); // Grok explain tweet
  50. };
  51.  
  52. const observer = new MutationObserver(removeElements);
  53.  
  54. observer.observe(document.body, {
  55. childList: true,
  56. subtree: true
  57. });
  58.  
  59. removeElements();
  60. })();