Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replaces all missing images with images of kittens instead.
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