Guest User

Untitled

a guest
Oct 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. (function () {
  2. [].forEach.call(document.querySelectorAll('img'), function (image) {
  3. if (image.parentNode.tagName == 'NOSCRIPT') {
  4. let _img = new Image();
  5.  
  6. _img.setAttribute('sizes', image.getAttribute('sizes') || '100vw');
  7.  
  8. if (image.getAttribute('class')) {
  9. _img.setAttribute('class', image.getAttribute('class'));
  10. }
  11.  
  12. if (image.getAttribute('alt')) {
  13. _img.setAttribute('alt', image.getAttribute('alt'));
  14. }
  15.  
  16. if (image.getAttribute('title')) {
  17. _img.setAttribute('title', image.getAttribute('title'));
  18. }
  19.  
  20. _img.setAttribute('cld-src', image.getAttribute('cld-src'));
  21.  
  22. // insert new image before NOSCRIPT tag
  23. image.parentNode.parentNode.insertBefore(_img, image.parentNode);
  24.  
  25. // remove NOSCRIPT tag
  26. image.parentNode.remove();
  27.  
  28. image = _img;
  29. }
  30.  
  31. if (image.getAttribute('cld-src')) {
  32. image.setAttribute('data-src', image.getAttribute('cld-src').replace('dpr_auto', 'dpr_' + window.DPR));
  33. image.removeAttribute('cld-src');
  34. }
  35.  
  36. if (! /lazy/.test(image.getAttribute('class'))) {
  37. image.setAttribute('src', image.getAttribute('data-src'));
  38. image.removeAttribute('data-src');
  39. }
  40. });
  41. })();
Add Comment
Please, Sign In to add comment