Greasy Fork is available in English.

Hide Twitter Crap

Hide noise on Twitter ("Who to follow", etc)

  1. // ==UserScript==
  2. // @name Hide Twitter Crap
  3. // @namespace Violentmonkey Scripts
  4. // @match https://x.com/*
  5. // @grant none
  6. // @version 1.0
  7. // @author turtlebasket
  8. // @run-at document-idle
  9. // @license MIT
  10. // @description Hide noise on Twitter ("Who to follow", etc)
  11. // ==/UserScript==
  12.  
  13.  
  14. // https://stackoverflow.com/a/61511955
  15. function waitForEl(selector) {
  16. return new Promise(resolve => {
  17. if (document.querySelector(selector)) {
  18. return resolve(document.querySelector(selector));
  19. }
  20.  
  21. const observer = new MutationObserver(mutations => {
  22. if (document.querySelector(selector)) {
  23. observer.disconnect();
  24. resolve(document.querySelector(selector));
  25. }
  26. });
  27.  
  28. // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
  29. observer.observe(document.body, {
  30. childList: true,
  31. subtree: true
  32. });
  33. });
  34. }
  35.  
  36.  
  37. for (let label of [
  38. '[aria-label="Premium"]',
  39. '[aria-label="Trending"]',
  40. ]) {
  41. waitForEl(label).then((el) => {
  42. el.style.display = 'none';
  43. })
  44. }
  45.  
  46. // draft:
  47. // hide "what's happening", "who to follow", etc; this attempts to leave the searchbar intact
  48.  
  49. // waitForEl('[aria-label="Trending"]').then((trendingEl) => {
  50. // let trendingContainerEls = trendingEl.childNodes[0].childNodes;
  51. // console.log(trendingContainerEls)
  52. // for (let elIndex of [2, 3]) {
  53. // trendingContainerEls[elIndex].style.display = 'none';
  54. // }
  55. // })
  56.