Greasy Fork

来自缓存

Greasy Fork is available in English.

简单搜索自动展开

自动展开简单搜索的结果,避免需要多次点击“加载更多”按钮。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         简单搜索自动展开
// @description  自动展开简单搜索的结果,避免需要多次点击“加载更多”按钮。
// @author       ChatGPT
// @version      3.7
// @match        https://m.baidu.com/*
// @match        https://www.baidu.com/*
// @exclude      https://*.baidu.com/video/
// @run-at      document-end
// @grant        none
// @namespace http://greasyfork.icu/users/452911
// ==/UserScript==

(function() {
    'use strict';

    // 检查是否在搜索结果页面
    if (!window.location.href.includes('word=') && !window.location.href.includes('wd=')) {
        return;
    }

    // 检查是否存在加载更多按钮
    var loadMoreButton = document.querySelector('div.se-infiniteload-text');
    if (!loadMoreButton) {
        return;
    }

    // 如果存在"加载更多"span也点击
    var spanLoadMore = document.querySelector('div.se-infiniteload-text');
    if (spanLoadMore) {
        spanLoadMore.click();
    }

    // 滚动时自动加载更多
    window.addEventListener('scroll', function() {
        var distanceToBottom = document.body.scrollHeight - (window.innerHeight + window.pageYOffset);
        if (distanceToBottom < 400) {
            var currentLoadMoreButton = document.querySelector('div.se-infiniteload-text');
            if (currentLoadMoreButton) {
                currentLoadMoreButton.click();
            }
        }
    });

    // 隐藏元素
    var div = document.getElementById("head-queryarea");
    if (div) {
        div.style.display = "none";
    }
})();