Skip to content

Instantly share code, notes, and snippets.

@oflow
Last active August 30, 2016 13:01
Show Gist options
  • Save oflow/1ef73dd2fc789ea5ccd0e0c81a91b45f to your computer and use it in GitHub Desktop.
Save oflow/1ef73dd2fc789ea5ccd0e0c81a91b45f to your computer and use it in GitHub Desktop.
['ajax', 'data-src', 'data-lazy-src', 'data-original', 'rel:bf_image_src'].forEach((attr) => {
var elms = document.querySelectorAll('*[' + attr.replace(/:/, '\\:') + ']');
for (var i = 0; i < elms.length; i++) {
if (elms[i].nodeName !== 'IMG') {
let img = document.createElement('img');
img.src = elms[i].getAttribute(attr);
img.style.cssText = 'max-width: 100%; max-height: 100%;';
elms[i].appendChild(img);
} else {
elms[i].src = elms[i].getAttribute(attr);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment