Greasy Fork is available in English.

Google Infinite Scroll

-

// ==UserScript==
// @name:ko           구글 무한 스크롤
// @name              Google Infinite Scroll

// @description:ko    -
// @description	      -

// @namespace         https://ndaesik.tistory.com/
// @version           2024.12.30.21.02
// @author            ndaesik
// @icon              https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://www.google.com
// @match             *://www.google.com/search*
// ==/UserScript==

if(new URL(window.location.href).searchParams.has('udm')) return;
document.head.appendChild(Object.assign(document.createElement('style'), {textContent: '#botstuff [role="navigation"] { display: none !important; }'}));
const fetchNextPage = async pageNumber => {
    const baseUrl = new URL(window.location.href);
    const text = await (await fetch(`${baseUrl.origin}${baseUrl.pathname}?q=${baseUrl.searchParams.get('q')}&start=${pageNumber * 10}`)).text();
    const newDoc = new DOMParser().parseFromString(text, 'text/html');
    const container = document.createElement('div');
    container.id = `page-${pageNumber}`;
    container.style.cssText = 'margin-top: 20px;';
    newDoc.querySelectorAll('#rso > div').forEach(result => container.appendChild(result.cloneNode(true)));
    const lastAddedPage = document.querySelector(`#page-${pageNumber - 1}`) || document.querySelector('#botstuff');
    lastAddedPage.after(container);
    return !!newDoc.querySelector('#pnnext');
};
let [pageNumber, isLoading, hasMore] = [1, false, true];
window.addEventListener('scroll', async () => {
    (!isLoading && hasMore && window.innerHeight + window.pageYOffset >= document.documentElement.offsetHeight - 1000) && (isLoading = true, hasMore = await fetchNextPage(pageNumber), pageNumber += hasMore ? 1 : 0, isLoading = false);
});