// SPDX-License-Identifier: AGPL-3.0-or-later /* global searxng */ searxng.ready(() => { searxng.infinite_scroll_supported = "IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype; if (searxng.endpoint !== "results") { return; } if (!searxng.infinite_scroll_supported) { console.log("IntersectionObserver not supported"); return; } const d = document; const onlyImages = d.getElementById("results").classList.contains("only_template_images"); function newLoadSpinner() { const loader = d.createElement("div"); loader.classList.add("loader"); return loader; } function replaceChildrenWith(element, children) { element.textContent = ""; children.forEach((child) => element.appendChild(child)); } function loadNextPage(callback) { const form = d.querySelector("#pagination form.next_page"); if (!form) { return; } replaceChildrenWith(d.querySelector("#pagination"), [newLoadSpinner()]); const formData = new FormData(form); searxng .http("POST", d.querySelector("#search").getAttribute("action"), formData) .then((response) => { const nextPageDoc = new DOMParser().parseFromString(response, "text/html"); const articleList = nextPageDoc.querySelectorAll("#urls article"); const paginationElement = nextPageDoc.querySelector("#pagination"); d.querySelector("#pagination").remove(); if (articleList.length > 0 && !onlyImages) { // do not add