Skip to content

Instantly share code, notes, and snippets.

@wojciak
Last active February 7, 2016 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wojciak/a594dcc8bcdc1b9a7d7d to your computer and use it in GitHub Desktop.
Save wojciak/a594dcc8bcdc1b9a7d7d to your computer and use it in GitHub Desktop.
DevOps Reactions imgur block fix.
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