Twitter UI Cleanup

Remove unwanted buttons and sections on Twitter

目前為 2025-01-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Twitter UI Cleanup
  3. // @namespace https://github.com/Daminator4113/Twitter-UI-Cleanup
  4. // @version 1.1
  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. removeParent('aside a[href*="/i/premium_sign_up"]', 3, 'DIV'); // "Try Premium for free" section
  34.  
  35. const selectors = [
  36. 'a[href*="/i/grok"]', // Grok
  37. 'a[href*="/i/premium_sign_up"]', // Twitter Blue
  38. 'a[href*="/i/verified-orgs-signup"]', // Verified organizations
  39. 'button[data-testid="grokImgGen"]', // "Generate Image with Grok" button.
  40. ];
  41.  
  42. selectors.forEach(selector => {
  43. document.querySelectorAll(selector).forEach(el => el.remove());
  44. });
  45.  
  46. removeParent('div[data-testid="GrokDrawerHeader"]', 1, 'DIV'); // Grok Drawer → I don't know why, but removing the "GrokDrawer" div deactivate the autoplay for videos???
  47.  
  48. 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"]';
  49. removeParent(grokSVG, 4, 'BUTTON'); // Grok profil resume
  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. })();