Skip to content

Instantly share code, notes, and snippets.

@kiriappeee
Last active September 11, 2022 19:49
Show Gist options
  • Save kiriappeee/ea25f28fb29e3666c19ac47e9567bffa to your computer and use it in GitHub Desktop.
Save kiriappeee/ea25f28fb29e3666c19ac47e9567bffa to your computer and use it in GitHub Desktop.
Remove all the extra tweets that twitter puts into your timeline including ads and likes
/*To use this function, open up Twitter, open a console in dev mode,
paste the function in below, and then run,
var intervalId = window.setInterval(removeGarbage, 1000);
if you wish to stop this removing all the extra tweets every second,
window.clearInterval(intervalId);
*/
function removeGarbage(){
var tweets=document.querySelectorAll('.js-stream-item.stream-item.stream-item');
var tweetsToRemove=Array();
for (var i=0; i<tweets.length; i++){
dataJson = JSON.parse(tweets[i].getAttribute('data-suggestion-json'));
if (dataJson.suggestion_details.suggestion_type == null){
//this little if condition is to stop threaded tweets being removed
if(dataJson.tweet_ids!='' && dataJson.scribe_component=='tweet'){
tweetsToRemove.push(tweets[i]); //this removes all ads
}
}
else if (dataJson.suggestion_details.suggestion_type == "RecycledTweet"){
tweetsToRemove.push(tweets[i]); // Removes the in case you missed it section
}
else if(dataJson.suggestion_details.suggestion_type == "ActivityTweet"){
tweetsToRemove.push(tweets[i]); // this removes all tweets liked by a person
}
else if(dataJson.suggestion_details.suggestion_type == "RecycledTweetInline"){
tweetsToRemove.push(tweets[i]); //Twitter does this weird thing of bringing back retweets from the past. Nuke em!
}
else if(dataJson.suggestion_details.suggestion_type == "RankedOrganicTweet"){
//All the stuff below is super aggressive. Removes quotes and retweets. Remove either or both the conditions
//if its too aggressive for your liking
if(tweets[i].querySelector('span.Icon.Icon--small.Icon--retweeted')!==null){
tweetsToRemove.push(tweets[i]); // This removes any retweets
}
if(tweets[i].querySelector('div.QuoteTweet')!==null){
tweetsToRemove.push(tweets[i]); // This removes any quoted tweets
}
}
}
for (var i=0; i<tweetsToRemove.length; i++){
tweetsToRemove[i].remove(); //this is probably a bad idea. I don't know. It works :D
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment