Greasy Fork

Greasy Fork is available in English.

caixin auto load more

财新首页信息流中,滑动到底部自动点击“加载更多文章”

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         caixin auto load more
// @namespace    http://tampermonkey.net/
// @version      2024-12-09
// @description  财新首页信息流中,滑动到底部自动点击“加载更多文章”
// @author       You
// @match        https://www.caixin.com/
// @icon         https://file.caixin.com/file/weixin/cx_logo.jpg
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function debounce(func, wait) {
        let timeout;
        return function(...args) {
            const context = this;
            clearTimeout(timeout);
            timeout = setTimeout(() => func.apply(context, args), wait);
        };
    }

    // Function to check if the user has scrolled to the bottom of the page
    function isScrolledToBottom() {
        return (window.innerHeight + window.scrollY) >= document.body.offsetHeight;
    }

    // Function to click the button
    function clickButton() {
        const button = document.querySelector('#moreArticle a').click()
        if (button) {
            button.click();
        }
    }

    // Debounced scroll event handler
    const handleScroll = debounce(function() {
        if (isScrolledToBottom()) {
            clickButton();
        }
    }, 500); // Adjust the debounce wait time as needed

    // Add an event listener for the scroll event
    window.addEventListener('scroll', handleScroll);
})();