Skip to content

Instantly share code, notes, and snippets.

@jsocol
Created January 6, 2012 04:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jsocol/1568904 to your computer and use it in GitHub Desktop.
Save jsocol/1568904 to your computer and use it in GitHub Desktop.
Bookmarklet to add inline full-size images to Reddit.
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