Created
April 5, 2023 08:19
-
-
Save chunrapeepat/cf4e2f5a3e706d3ac7da434f6237b5cb to your computer and use it in GitHub Desktop.
Make Twitter suck less
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hide Twitter Replies (Home) | |
// @version 1 | |
// @description Hide all reply elements in a Twitter home page. | |
// @author Chun Rapeepat | |
// @match https://twitter.com/home | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// hide replies | |
function hideReplies() { | |
const tweetList = document.querySelectorAll("article[data-testid='tweet']"); | |
Array.from(tweetList).forEach(tweet => { | |
const replyContent = tweet.innerText.includes('Replying to'); | |
if (replyContent) { | |
tweet.style.display = 'none'; | |
} | |
}); | |
} | |
const observer = new MutationObserver(hideReplies); | |
observer.observe(document.body, { childList: true, subtree: true }); | |
hideReplies(); | |
// remove Twitter logo | |
function hideLogo() { | |
document.querySelector("h1[role='heading'").style.display = 'none'; | |
} | |
const observerLogo = new MutationObserver(hideLogo); | |
observerLogo.observe(document.body, { childList: true, subtree: true }); | |
hideLogo(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment