mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
* [upd] web-client (simple): Bump the minor group Bumps the minor group in /client/simple with 4 updates: [ol](https://github.com/openlayers/openlayers), [@biomejs/biome](https://github.com/biomejs/biome/tree/HEAD/packages/@biomejs/biome), [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) and [sharp](https://github.com/lovell/sharp). Updates `ol` from 10.6.1 to 10.7.0 - [Release notes](https://github.com/openlayers/openlayers/releases) - [Commits](https://github.com/openlayers/openlayers/compare/v10.6.1...v10.7.0) Updates `@biomejs/biome` from 2.3.2 to 2.3.4 - [Release notes](https://github.com/biomejs/biome/releases) - [Changelog](https://github.com/biomejs/biome/blob/main/packages/@biomejs/biome/CHANGELOG.md) - [Commits](https://github.com/biomejs/biome/commits/@biomejs/biome@2.3.4/packages/@biomejs/biome) Updates `@types/node` from 24.9.2 to 24.10.0 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `sharp` from 0.34.4 to 0.34.5 - [Release notes](https://github.com/lovell/sharp/releases) - [Commits](https://github.com/lovell/sharp/compare/v0.34.4...v0.34.5) --- updated-dependencies: - dependency-name: ol dependency-version: 10.7.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: minor - dependency-name: "@biomejs/biome" dependency-version: 2.3.4 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: minor - dependency-name: "@types/node" dependency-version: 24.10.0 dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor - dependency-name: sharp dependency-version: 0.34.5 dependency-type: direct:development update-type: version-update:semver-patch dependency-group: minor ... Signed-off-by: dependabot[bot] <support@github.com> * [upd] web-client (simple): rebuild static --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ivan Gabaldon <igabaldon@inetol.net>
101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import { assertElement, http, settings } from "../core/toolkit.ts";
|
|
|
|
const newLoadSpinner = (): HTMLDivElement => {
|
|
return Object.assign(document.createElement("div"), {
|
|
className: "loader"
|
|
});
|
|
};
|
|
|
|
const loadNextPage = async (onlyImages: boolean, callback: () => void): Promise<void> => {
|
|
const searchForm = document.querySelector<HTMLFormElement>("#search");
|
|
assertElement(searchForm);
|
|
|
|
const form = document.querySelector<HTMLFormElement>("#pagination form.next_page");
|
|
assertElement(form);
|
|
|
|
const action = searchForm.getAttribute("action");
|
|
if (!action) {
|
|
throw new Error("Form action not defined");
|
|
}
|
|
|
|
const paginationElement = document.querySelector<HTMLElement>("#pagination");
|
|
assertElement(paginationElement);
|
|
|
|
paginationElement.replaceChildren(newLoadSpinner());
|
|
|
|
try {
|
|
const res = await http("POST", action, { body: new FormData(form) });
|
|
const nextPage = await res.text();
|
|
if (!nextPage) return;
|
|
|
|
const nextPageDoc = new DOMParser().parseFromString(nextPage, "text/html");
|
|
const articleList = nextPageDoc.querySelectorAll<HTMLElement>("#urls article");
|
|
const nextPaginationElement = nextPageDoc.querySelector<HTMLElement>("#pagination");
|
|
|
|
document.querySelector("#pagination")?.remove();
|
|
|
|
const urlsElement = document.querySelector<HTMLElement>("#urls");
|
|
if (!urlsElement) {
|
|
throw new Error("URLs element not found");
|
|
}
|
|
|
|
if (articleList.length > 0 && !onlyImages) {
|
|
// do not add <hr> element when there are only images
|
|
urlsElement.appendChild(document.createElement("hr"));
|
|
}
|
|
|
|
urlsElement.append(...Array.from(articleList));
|
|
|
|
if (nextPaginationElement) {
|
|
const results = document.querySelector<HTMLElement>("#results");
|
|
results?.appendChild(nextPaginationElement);
|
|
callback();
|
|
}
|
|
} catch (error) {
|
|
console.error("Error loading next page:", error);
|
|
|
|
const errorElement = Object.assign(document.createElement("div"), {
|
|
textContent: settings.translations?.error_loading_next_page ?? "Error loading next page",
|
|
className: "dialog-error"
|
|
});
|
|
errorElement.setAttribute("role", "alert");
|
|
document.querySelector("#pagination")?.replaceChildren(errorElement);
|
|
}
|
|
};
|
|
|
|
const resultsElement: HTMLElement | null = document.getElementById("results");
|
|
if (!resultsElement) {
|
|
throw new Error("Results element not found");
|
|
}
|
|
|
|
const onlyImages: boolean = resultsElement.classList.contains("only_template_images");
|
|
const observedSelector = "article.result:last-child";
|
|
|
|
const intersectionObserveOptions: IntersectionObserverInit = {
|
|
rootMargin: "320px"
|
|
};
|
|
|
|
const observer: IntersectionObserver = new IntersectionObserver((entries: IntersectionObserverEntry[]) => {
|
|
const [paginationEntry] = entries;
|
|
|
|
if (paginationEntry?.isIntersecting) {
|
|
observer.unobserve(paginationEntry.target);
|
|
|
|
void loadNextPage(onlyImages, () => {
|
|
const nextObservedElement = document.querySelector<HTMLElement>(observedSelector);
|
|
if (nextObservedElement) {
|
|
observer.observe(nextObservedElement);
|
|
}
|
|
}).then(() => {
|
|
// wait until promise is resolved
|
|
});
|
|
}
|
|
}, intersectionObserveOptions);
|
|
|
|
const initialObservedElement: HTMLElement | null = document.querySelector<HTMLElement>(observedSelector);
|
|
if (initialObservedElement) {
|
|
observer.observe(initialObservedElement);
|
|
}
|