Skip to content

Instantly share code, notes, and snippets.

@ralph-tice
Created July 14, 2013 04:42
Show Gist options
  • Save ralph-tice/5993238 to your computer and use it in GitHub Desktop.
Save ralph-tice/5993238 to your computer and use it in GitHub Desktop.
given the context of a tweet on twitter that has a pic.twitter.com image this is how you get the actual url to the picture... or is it ? Do I just suck at filtering?
//v1, works, normally .each instead of [0]
$($($('a:contains("pic.twitter.com/")')[0]).parent().parent().parent().data('expandedFooter')).children(".cards-media-container").children().children(".media").children("a").data('url')
//v2, found 'find' instead of 'filter'...
$($($('a:contains("pic.twitter.com/")')[0]).parent().parent().parent().data('expandedFooter')).find("a.media-thumbnail").data('url')
@pierceray
Copy link

Seems like you wouldn't need to find pic.twitter.com, and just look for the media thumbnail. Might be able to do that with .filter(). Not sure of the use case or performance constraints.

@ralph-tice
Copy link
Author

The media thumbnail exists inside the data attribute for the tweet -- it isn't actually a rendered DOM element, it only gets put into the DOM if you expand the footer.

So this is 'find a tweet that has a link that has pic.twitter.com, then reach up to the tweet container and grab the data attribute, wrap it in a jQuery object, and grab the media thumbnail link there and pull off its data url...' pic.twitter.com images are actually something like https://pbs.twimg.com/media/BPXqF_YCAAA2yqz.jpg:large

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