百度谷歌自动翻页

手机版,移动版,简单搜索,谷歌搜索结果页面自动加载更多内容,自动点击"加载更多"按钮

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         百度谷歌自动翻页
// @description  手机版,移动版,简单搜索,谷歌搜索结果页面自动加载更多内容,自动点击"加载更多"按钮
// @author       psychosisspy
// @version      1.7
// @match        https://m.baidu.com/*
// @match        https://www.baidu.com/*
// @match        https://www.google.com/*
// @match        https://www.google.com.hk/*
// @exclude      https://*.baidu.com/video/
// @run-at        document-end
// @grant         none
// @namespace https://greasyfork.org/users/842064
// ==/UserScript==

(function() {
    'use strict';
    
    const url = window.location.href;
    let lastY = 0;
    
    // 百度逻辑
    if (url.includes('baidu.com')) {
        if (!url.includes('word=') && !url.includes('wd=')) return;
        
        window.addEventListener('scroll', () => {
            if (window.scrollY <= lastY) return; // 只向下滚动
            
            if (window.scrollY + window.innerHeight > document.body.offsetHeight - 600) {
                document.querySelector('div.se-infiniteload-text')?.click();
            }
            lastY = window.scrollY;
        }, { passive: true });
    }
    
    // 谷歌逻辑
    else if (url.includes('google.com')) {
        if (!url.includes('search') || !url.includes('q=')) return;
        
        window.addEventListener('scroll', () => {
            if (window.scrollY <= lastY) return;
            
            if (window.scrollY + window.innerHeight > document.body.offsetHeight - 800) {
                document.querySelector('[aria-label="更多搜索结果"]')?.click();
            }
            lastY = window.scrollY;
        }, { passive: true });
    }
    
})();