Update 08/12/2010 – There’s now a Firefox Extension in the Add-Ons sandbox available for adding this media preview to Twitter, as well as previews for Daft.ie and Adverts.ie ads.
With their recent site redesign, Twitter added a number of interesting new features. One of the more useful of these is the media preview. From the Twitter blog:
Media. Now, it’s easy to see embedded photos and videos directly on Twitter, thanks to partnerships with DailyBooth, deviantART, Etsy, Flickr, Justin.TV, Kickstarter, Kiva, Photozou, Plixi, Twitgoo, TwitPic, TwitVid, USTREAM, Vimeo, yfrog, and YouTube.
This is definitely one of the more useful features of the new Twitter web interface, and covers most of the more mainstream media sources that I’d notice showing up in my timeline. That said, there are some notable omissions..
Imgur.com
Anyone who has spent any time on reddit will be familiar with the image hosting service imgur.com. Run by redditor MrGrim, a quick browse through any of the more popular sub-reddits show how ubiquituous it has become for media sharing on reddit. It would be very handy if tweets mentioning imgur had the same preview functionality as those mentioning twitpic, yfrog, etc. I’ve recently been digging through the new Twitter javascript whilst working on a Declutter followup, so decided to take a break from that and see how hard it would be to bolt on imgur previewing to the web interface.
Luckily, it turned out to be very straight-forward indeed, and can be done with one simple bookmarklet!
If you’re not interested in the technical nuts and bolts behind it, you can skip ahead to get the bookmarklet now. Otherwise, read on for a bit more technical explanation on the ins and outs of adding a custom media type to Twitter.
Ur Img, My Img, Everybody’s Img..
The recent rewrite of Twitter.com pushed a huge additional amount of their logic in to javascript on the client side. My thinking was that the imgur preview functionality should work the same as the twitpic previewing. Taking a look through the main application logic for twitpic, we can see the declaration of
1 | twttr.media.types |
Below is how we clone the twitpic media type, then tweak for imgur:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | twttr.mediaType("twttr.media.types.Imgur" , { icon:"photo" , domain:"http://imgur.com" , matchers:{media:/imgur.com\/([a-zA-Z0-9\.]+)/g} , process:function(A) { // If link is http://imgur.com, ext usually missing if(this.slug.indexOf('.') < 0) { this.slug = this.slug + '.jpg'; } this.data.src=this.slug; this.data.name=this.constructor._name; A() } , render:function(B) { var A='<div class="twitpic"><a class="inline-media-image" href="http://i.imgur.com/{src}" target="_blank" data-inline-type="{name}"><img alt="" src="http://i.imgur.com/{src}" /></a>'; $(B).append(twttr.supplant(A,this.data)) } } ); void(0); |


Pingback: Links for Friday, 3rd December. | Ross Duggan
Pingback: Avishkar's Blog » #NewTwitter API
Nice blog here! Also your web site loads up
very fast! What host are you using? Can I get your affiliate link to your host?
I wish my website loaded up as fast as yours lol