Skip to content

  • by

  • by
document.addEventListener("DOMContentLoaded", function () { console.log("SCROLL SCRIPT RUNNING"); // debug let currentPage = 1; let loading = false; window.addEventListener("scroll", function () { let scrollBottom = window.innerHeight + window.scrollY; let pageHeight = document.documentElement.scrollHeight; if (!loading && scrollBottom >= pageHeight - 500) { loading = true; currentPage++; let base = window.location.pathname.replace(/\/\d+\/$/, '/'); let nextUrl = base + currentPage + '/'; console.log("Load:", nextUrl); fetch(nextUrl) .then(res => res.text()) .then(html => { let parser = new DOMParser(); let doc = parser.parseFromString(html, "text/html"); let newContent = doc.querySelector(".single-post-container"); if (newContent) { document.querySelector(".single-post-container") .insertAdjacentHTML("beforeend", newContent.innerHTML); loading = false; if (window._mgc) { _mgc.load(); } } }) .catch(() => { loading = false; }); } }); });