简单搜索自动展开

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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 https://greasyfork.org/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";
    }
})();