Skip to content

Instantly share code, notes, and snippets.

@kirsn
Created August 4, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirsn/316cfddbf5dc46dd126c423f112cfc8d to your computer and use it in GitHub Desktop.
Save kirsn/316cfddbf5dc46dd126c423f112cfc8d to your computer and use it in GitHub Desktop.
Remove tweets that contains terms or topics you are not interested in
// ==UserScript==
// @name Twitter - Filter
// @namespace tf
// @author http://twitter.com/kirsn
// @description Remove tweets which are of no interest
// @include https://twitter.com/
// @version 1
// @grant none
// ==/UserScript==
/* All filter terms in CAPS */
var filterTerms = [
'TRUMP',
'RAKSHAK'
];
/*Remove tweets that match the filter terms*/
function twitterFilter() {
var ts = document.getElementsByClassName('tweet');
for (var i = 0; i < ts.length; i++) {
var tweetText = ts[i].textContent.toUpperCase();
for (var j = 0; j < filterTerms.length; j++) {
if (tweetText.indexOf(filterTerms[j].toUpperCase()) > 0) {
ts[i].remove();
break;
}
}
}
}
/*Perform this cleanup every 5 seconds*/
window.setInterval(twitterFilter, 5000);
@kirsn
Copy link
Author

kirsn commented Aug 4, 2016

Simple Filter for your Twitter timeline

Not interested in reading about some topics on your Twitter timeline? You can just remove them, automatically, with this technique.
I use Twitter to follow some topics - mostly technology, art, some politics and a few other random things. Some topics I choose not to follow on twitter, and instead choose to read about in a newspaper (an editorial, or article with a byline)

So, created the following Greasemonkey script. This should have been a two minute endeavour, but minimal competence in Javascript, it took me a while to figure out things.

How you can use this, from within your desktop browser:

  • Install GreaseMonkey for Firefox, or TamperMonkey for Chrome / Opera
  • Copy the entire script, and paste it as a new script in these addons
  • Reload Twitter.
  • You shouldn't be seeing tweets, that match your filter terms / topics.

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