diff --git a/hide-twitter-crap/README.md b/hide-twitter-crap/README.md new file mode 100644 index 0000000..25744e4 --- /dev/null +++ b/hide-twitter-crap/README.md @@ -0,0 +1,4 @@ +# Hide Twitter Crap + +Hides Twitter sidebar (i.e. "Trending", "Who to follow", etc) & premium button; search should still be usable from the "Explore" tab. + diff --git a/hide-twitter-crap/script.js b/hide-twitter-crap/script.js new file mode 100644 index 0000000..cc710a9 --- /dev/null +++ b/hide-twitter-crap/script.js @@ -0,0 +1,54 @@ +// ==UserScript== +// @name Hide Twitter Crap +// @namespace Violentmonkey Scripts +// @match https://x.com/* +// @grant none +// @version 1.0 +// @author turtlebasket +// @run-at document-idle +// ==/UserScript== + + +// https://stackoverflow.com/a/61511955 +function waitForEl(selector) { + return new Promise(resolve => { + if (document.querySelector(selector)) { + return resolve(document.querySelector(selector)); + } + + const observer = new MutationObserver(mutations => { + if (document.querySelector(selector)) { + observer.disconnect(); + resolve(document.querySelector(selector)); + } + }); + + // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336 + observer.observe(document.body, { + childList: true, + subtree: true + }); + }); +} + + +for (let label of [ + '[aria-label="Premium"]', + '[aria-label="Trending"]', +]) { + waitForEl(label).then((el) => { + el.style.display = 'none'; + }) +} + +// draft: +// hide "what's happening", "who to follow", etc; this attempts to leave the searchbar intact + +// waitForEl('[aria-label="Trending"]').then((trendingEl) => { +// let trendingContainerEls = trendingEl.childNodes[0].childNodes; +// console.log(trendingContainerEls) +// for (let elIndex of [2, 3]) { +// trendingContainerEls[elIndex].style.display = 'none'; +// } +// }) +