Filter Tweets Bookmarklet

Filter Tweets

What is this?

It's a bookmarklet to filter tweets. If you go to twitter.com and click this bookmarklet, all tweets will be removed from the page which do not contain at least one hashtag or at least one link. As more tweets are loaded into the page, either from infinite scrolling or by clicking the "View new Tweets" link, they will also be filtered.

How do I use it?

To install the bookmarklet, drag the red button to your bookmarks toolbar.

What is it doing?

Here's the non-minified code:

(function() {
    var filterTweets = function() {
        $('.js-tweet-text').each(function(i, elem) {
            var $e = $(elem);
            var eText = $e.text();
            
            if (eText && 
                eText.search(/\B#\w\w+/) === -1 &&
                $e.find('.js-display-url').not('.u-hidden > .js-display-url').length === 0)
            {
                $e.closest('.js-stream-item').remove();
            }
        });
    };
    
    // Filter once when the bookmarklet is clicked
    filterTweets();
    
    // Filter again on all future changes
    var streamElem = $('.js-navigable-stream')[0];
    var config = {
        attributes: false,
        childList: true,
        characterData: false
    };
    
    var observer = new MutationObserver(function(mutations) {
        filterTweets();
    });
    observer.observe(streamElem, config);
})();
Fork me on GitHub