Last active
August 29, 2015 14:07
-
-
Save adeubank/fa2f8b83a0698cb36c2a to your computer and use it in GitHub Desktop.
Replaces all missing images with images of kittens instead.
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 kittenizeAllImages() { | |
var images = document.getElementsByTagName('img'); | |
for (var i = 0; !!images[i]; i++) { | |
if (!! images[i].dataset.notChecked) | |
continue; | |
checkImage(images[i]); | |
} | |
} | |
function checkImage(originalImage) { | |
var tempImage = document.createElement('img'); | |
tempImage.onerror = function () { | |
var imageHeight = originalImage.height; | |
var imageWidth = originalImage.width; | |
originalImage.src = "http://placekitten.com/g/" + imageWidth + "/" + imageHeight; | |
}; | |
tempImage.onload = function () { | |
originalImage.dataset.checked = true; | |
}; | |
tempImage.src = originalImage.src; | |
} | |
console.log("Kittenizing all images"); | |
kittenizeAllImages(); | |
setInterval(kittenizeAllImages, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment