Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
Created April 25, 2012 09:59
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 simonwhitaker/2488632 to your computer and use it in GitHub Desktop.
Save simonwhitaker/2488632 to your computer and use it in GitHub Desktop.
Expanded JS source for the bookmarklets introduced at http://blog.goosoftware.co.uk/2012/04/25/twitter-bookmarklets/
/*
* === Routine for toggling @replies ===
*
* Step 1: Using jQuery (which Twitter already loads), select the div
* elements of class stream-item that contain tweets where the
* data-is-reply-to attribute is true.
*/
var tweets = $('div.tweet[data-is-reply-to=true]').parents('div.stream-item');
/*
* Step 2: Determine whether we're hiding or showing. If there are no replies
* visible then we'll show replies, otherwise we'll hide them.
*
* FAQs :)
*
* Why not just call tweets.toggle()?
*
* Because that gets all messed up if you scroll down and Twitter auto-loads
* some more tweets. At that point if you've got replies hidden then the
* bookmarklet will hide the visible tweets and show the hidden ones.
* (This way the bookmarklet also plays better with the one for hiding
* retweets where you have retweeted replies.)
*/
var shouldShow = tweets.filter(':visible').size() == 0;
/*
* Step 3: Toggle the replies on or off
*/
tweets.toggle(shouldShow);
/*
* === Routine for toggling retweets ===
*
* Exactly the same logic as for replies, only in the first line we filter
* div.tweet elements based on whether they have a data-retweet-id attribute.
*/
var tweets = $('div.tweet[data-retweet-id]').parents('div.stream-item');
var shouldShow = tweets.filter(':visible').size() == 0;
tweets.toggle(shouldShow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment