Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created July 9, 2011 20:18
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 ayosec/1073923 to your computer and use it in GitHub Desktop.
Save ayosec/1073923 to your computer and use it in GitHub Desktop.
Show images in tweets.
/*
* Copy this to ~/.js/twitter.com.js
* Tested with dotjs for Firefox
*
* http://codingfulness.tumblr.com/post/7476823732/inline-images-twitter
*
* Public Domain Licence
*/
$(function() {
$(window).bind("DOMNodeInserted", function(event) {
var target = $(event.target);
if(target.data("item-type") === "tweet") {
if(target.data("expand-images-done") === "ready")
return;
target.data("expand-images-done", "ready");
var target_width = target.width();
target.find("a.twitter-timeline-link").each(function() {
var url = String.prototype.toString.call(this.href);
if(url.indexOf("http://t.co/") === 0 && this.title)
url = this.title;
unsafeWindow.twttr.media.resolveImageUrl(url, 300, {
success: function(url) {
$("<img>", {
src: url,
width: target_width - 100,
}).
css("margin-left", "50px").
appendTo(target);
},
error: function() { /* ignored */ }
});
})
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment