Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created July 12, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netsi1964/572f904e878226e5968e0003eb2a4444 to your computer and use it in GitHub Desktop.
Save netsi1964/572f904e878226e5968e0003eb2a4444 to your computer and use it in GitHub Desktop.
Replaces any image on page with a Dummyimage.com image showing size
var image = Array.from(document.querySelectorAll('img'));
image.map((ele,i) => {
var {width, height} = getComputedStyle(ele);
var newSrc = `http://dummyimage.com/${parseInt(width)}x${parseInt(height)}`;
if ('src' in ele) {
ele.setAttribute('src', newSrc)
} else {
var url = ele.style.backgroundImage;
console.log(url)
if (url) {
ele.style.backgroundImage = `url(${newSrc})`
}
}
ele.style.outline = 'solid blue'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment