Skip to content

Instantly share code, notes, and snippets.

@BrianPuccio
Forked from jsocol/gist:1568904
Created August 4, 2014 00:51
Show Gist options
  • Save BrianPuccio/2c3ac7ddfab56c7acc24 to your computer and use it in GitHub Desktop.
Save BrianPuccio/2c3ac7ddfab56c7acc24 to your computer and use it in GitHub Desktop.
javascript: (function () {
var things = document.querySelectorAll("div.thing");
for (var j = things.length - 1; j > 0; j--) {
var thing = things[j],
entry = thing.querySelectorAll("div.entry")[0],
thumb = thing.querySelectorAll("a.thumbnail")[0],
img = new Image;
img.style.display = 'block';
if (thumb) {
var href = thumb.href;
if (/\.(png|gif|jpe?g)$/i.test(href)) img.src = href;
else if (/imgur\.com/i.test(href) && !/\/a\//.test(href)) {
var id = /\w+?$/.exec(href)[0];
img.src = "http://i.imgur.com/" + id + ".jpg";
}
if (img.src) entry.appendChild(img);
img.onload = function() {
var ho = this.height;
var wo = this.width;
var hn = 800, wn = 800;
if (ho <= 800 && wo <= 800) return;
if (ho > wo) {
wn = Math.round(hn * wo / ho);
} else if (wo > ho) {
hn = Math.round(ho * wn / wo);
}
this.height = hn;
this.width = wn;
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment