Created
April 25, 2012 09:59
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* === 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