Skip to content

Commit

Permalink
cnn lazy image.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Schwarzenberger committed Dec 15, 2020
1 parent bb0931a commit 23805b0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,18 @@ window.addEventListener('DOMContentLoaded', function () {
}
}
})
});

window.addEventListener('DOMContentLoaded', function () {
const elements = document.querySelectorAll('img[src^="https://dynaimage.cdn.cnn.com"');

Array.from(elements, e => {
const src = e.getAttribute('src');
const probably = src.split('/').reverse()[0];
const url = new URL(decodeURIComponent(probably));
e.setAttribute('lazy', src);
if (url) {
e.setAttribute('src', url.toString());
}
})
});

0 comments on commit 23805b0

Please sign in to comment.