Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- [].forEach.call(document.querySelectorAll('img'), function (image) {
- if (image.parentNode.tagName == 'NOSCRIPT') {
- let _img = new Image();
- _img.setAttribute('sizes', image.getAttribute('sizes') || '100vw');
- if (image.getAttribute('class')) {
- _img.setAttribute('class', image.getAttribute('class'));
- }
- if (image.getAttribute('alt')) {
- _img.setAttribute('alt', image.getAttribute('alt'));
- }
- if (image.getAttribute('title')) {
- _img.setAttribute('title', image.getAttribute('title'));
- }
- _img.setAttribute('cld-src', image.getAttribute('cld-src'));
- // insert new image before NOSCRIPT tag
- image.parentNode.parentNode.insertBefore(_img, image.parentNode);
- // remove NOSCRIPT tag
- image.parentNode.remove();
- image = _img;
- }
- if (image.getAttribute('cld-src')) {
- image.setAttribute('data-src', image.getAttribute('cld-src').replace('dpr_auto', 'dpr_' + window.DPR));
- image.removeAttribute('cld-src');
- }
- if (! /lazy/.test(image.getAttribute('class'))) {
- image.setAttribute('src', image.getAttribute('data-src'));
- image.removeAttribute('data-src');
- }
- });
- })();
Add Comment
Please, Sign In to add comment