Last active
February 7, 2016 22:35
-
-
Save wojciak/a594dcc8bcdc1b9a7d7d to your computer and use it in GitHub Desktop.
DevOps Reactions imgur block fix.
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
function fixIframe() { | |
// get the images | |
var images = $("img[src*=imgur]"); | |
images.each(function(i, image) { | |
var $image = $(image), | |
iframe, | |
content; | |
// wrap each image into an iframe that pretends we load the images from our local computer | |
$image.wrap('<iframe src="http://localhost"></iframe>'); | |
// get the iframe wrapper | |
iframe = $image.parent()[0]; | |
// expand the image so it's big enough to laught at | |
iframe.style.width = '100%'; | |
iframe.style.height = '250px'; | |
iframe.style.overflow = 'hidden'; | |
// get into the iframe content | |
content = iframe.contentWindow.document; | |
// rewrite the content with the original image source | |
content.open(); | |
content.write('<html style="margin:0;padding:0;overflow:hidden;"><body="style:margin:0;padding:0;overflow:hidden;"><div><img src="'+image.src+'" style="max-width:100%;max-height:100%;"/></div></body></html>'); | |
content.close(); | |
}); | |
} | |
// profit | |
fixIframe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment