Automaticky loading produktu po dojeti na konec stránky

<script>

const elements=document.querySelectorAll(".pagination-wrapper"),observer=new IntersectionObserver(handleIntersection);function handleIntersection(e,o){e.forEach(e=>{e.intersectionRatio>0&&($(".load-products").click(),o.unobserve(e.target))})}elements.forEach(e=>{observer.observe(e)}),$.ajaxSetup({beforeSend:function(){},complete:function(){elements.forEach(e=>{let o=document.querySelectorAll(".pagination-wrapper"),n=new IntersectionObserver(function e(o,n){o.forEach(e=>{e.intersectionRatio>0&&($(".load-products").click(),n.unobserve(e.target))})});o.forEach(e=>{n.observe(e)})})}});

</script>