Skip to content

Instantly share code, notes, and snippets.

@willh
Last active October 8, 2015 18:48
Show Gist options
  • Save willh/3373992 to your computer and use it in GitHub Desktop.
Save willh/3373992 to your computer and use it in GitHub Desktop.
Clean up Twitter by hiding tweets by matching on content and removing trends and 'promoted' tweets
// ==UserScript==
// @name Twitter Cleanup
// @description Remove crap from your Twitter feed without unfollowing people
// @author @willhamill
// @include https://twitter.com/*
// @include https://www.twitter.com/*
// @include http://twitter.com/*
// @include http://www.twitter.com/*
// ==/UserScript==
(function(){
function hideTweetMatchingText(matchString) {
var elems = document.getElementsByTagName('p'), i;
for (i in elems) {
if((" " + elems[i].className + " ").indexOf(" " + "js-tweet-text" + " ") > -1) {
var boringTweet = elems[i]
if (boringTweet.innerHTML.indexOf(matchString) != -1) {
// hide great-grandparent div to disappear the entire tweet
boringTweet.parentNode.parentNode.parentNode.style.display = "none"
}
}
}
}
hideTweetMatchingText("http://4sq.com")
hideTweetMatchingText("http://pinterest.com/pin")
hideTweetMatchingText("http://instagr.am")
})();
(setTimeout(function(){
var elems = document.getElementsByTagName('div'), i;
for (i in elems) {
if((elems[i].className).indexOf("trends-inner") > -1) {
var trendsHeader = elems[i]
trendsHeader.style.display = "none"
}
}
var elems = document.getElementsByTagName('a'), i;
for (i in elems) {
if((elems[i].className).indexOf("js-promoted-badge") > -1) {
var promotedLink = elems[i]
promotedLink.parentNode.style.display = "none"
}
}
}, 2000))();
@willh
Copy link
Author

willh commented Jul 4, 2013

First function removes any tweets containing a given content, e.g. links to FourSquare.
Second function removes the Trends left-side div.
Third function removes any 'promoted' tweet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment