Last active
February 13, 2021 03:38
-
-
Save guyskk/c35c8a29b14a48bd2fca8512cb2f89a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.uscreditcards101.com/wp-content/cache/autoptimize/js/autoptimize_9a2cfd2fee7b6b64b5fa19e57f03bc6c.js | |
// https://www.uscreditcards101.com/how-to-use-plastiq-bill-pay/ | |
// https://www.v2ex.com/t/752795#reply113 | |
$(document).ready(function () { | |
setTimeout(function () { | |
var observer = new IntersectionObserver( | |
function (entries, observer) { | |
entries.forEach(function (entry) { | |
if (!entry.isIntersecting) return; | |
var options = JSON.parse(entry.target.getAttribute("data-options")); | |
var containerWidth = entry.target.offsetWidth; | |
var url = options[0][1]; | |
for (var i = 1; i < options.length; i++) { | |
if (containerWidth >= options[i][0]) url = options[i][1]; | |
} | |
var xhr = new XMLHttpRequest(); | |
xhr.responseType = "arraybuffer"; | |
xhr.onload = function () { | |
var blb = new Blob([xhr.response], { type: "image" }); | |
var bloburl = (window.URL || window.webkitURL).createObjectURL(blb); | |
entry.target.src = bloburl; | |
}; | |
xhr.open("GET", url); | |
xhr.send(); | |
observer.unobserve(entry.target); | |
}); | |
}, | |
{ rootMargin: "300px 0px 300px 0px" } | |
); | |
document.querySelectorAll("img[data-options]").forEach(function (elem) { | |
observer.observe(elem); | |
}); | |
}, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment