IE News Infinite Scroll

Infinite scroll for Interesting Engineering News

// ==UserScript==
// @name         IE News Infinite Scroll
// @description  Infinite scroll for Interesting Engineering News
// @match        https://interestingengineering.com/news*
// @match        https://www.interestingengineering.com/news*
// @version 0.0.1.20250328201013
// @namespace https://gf.qytechs.cn/users/1435046
// ==/UserScript==

(() => {
    let currentPage = 1;
    let isLoading = false;
    const mainContainer = document.querySelector('article.t-w-full');
    if (!mainContainer) return;

    // Remove initial pagination
    document.querySelectorAll('nav[role="navigation"]').forEach(n => n.remove());

    async function loadNextPage() {
        if (isLoading) return;
        isLoading = true;
        
        try {
            currentPage++;
            const res = await fetch(`/news/page/${currentPage}`);
            if (!res.ok) throw new Error(res.status);
            
            const doc = new DOMParser().parseFromString(await res.text(), 'text/html');
            const newSections = Array.from(doc.querySelectorAll('article > section'))
                .filter(s => !s.querySelector('h1.h1-style-desktop, nav[role="navigation"]'));

            newSections.forEach(s => mainContainer.insertBefore(
                document.importNode(s, true), 
                mainContainer.lastElementChild
            ));

        } catch(err) {
            console.error('IE Scroll:', err);
            currentPage--;
        } finally {
            isLoading = false;
        }
    }

    window.addEventListener('scroll', () => {
        if ((window.scrollY + innerHeight + 1000) >= document.documentElement.scrollHeight) {
            loadNextPage();
        }
    }, { passive: true });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址