let load = false; (() => { const posts = document.querySelector("#posts"); document.addEventListener("wheel", e => { if((((document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop + window.innerHeight) + 310 >= ((document.documentElement && document.documentElement.scrollHeight) || document.body.scrollHeight)) && !load) { load = true; fetch(`./api/p/${posts.dataset.last}`) .then(res => res.json()) .then((msg, html = "") => { for(let i = 0; i < msg.items.length; i++) if(msg.items[i].id) html += `
  • \n`; posts.insertAdjacentHTML("beforeend", html); posts.dataset.last = msg.last; load = false; }) .catch(err => console.log(err)); } }); })();