Created
January 6, 2012 04:03
-
-
Save jsocol/1568904 to your computer and use it in GitHub Desktop.
Bookmarklet to add inline full-size images to Reddit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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