friendship ended with social-app. php is my new best friend
at main 1.3 kB view raw
1if (document.querySelector('main').classList.contains("profile") && document.querySelectorAll('.postsList > .post').length > 0) { 2 const observerCheck = (entry, observer) => { 3 if (entry[0].isIntersecting) { 4 const container = document.querySelector('.postsList'); 5 const lastPost = document.querySelector('.postsList > .post:last-child'); 6 const cursor = lastPost.getAttribute('data-cursor'); 7 const user = lastPost.getAttribute('data-did'); 8 const params = new URLSearchParams(); 9 params.append("user", user); 10 params.append("cursor", cursor); 11 observer.unobserve(lastPost); 12 fetch(`/api/userPosts?${params}`) 13 .then((data) => { 14 data.text().then((content) => { 15 container.innerHTML += content; 16 const newobserver = new IntersectionObserver(observerCheck); 17 newobserver.observe(document.querySelector('.postsList > .post:last-child')); 18 }); 19 }, (err) => { 20 console.error(err); 21 const newobserver = new IntersectionObserver(observerCheck); 22 newobserver.observe(document.querySelector('.postsList > .post:last-child')); 23 }); 24 } 25 } 26 const observer = new IntersectionObserver(observerCheck); 27 observer.observe(document.querySelector('.postsList > .post:last-child')); 28}