简单搜索自动展开

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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";
    }
})();