简单搜索自动展开

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

  1. // ==UserScript==
  2. // @name 简单搜索自动展开
  3. // @description 自动展开简单搜索的结果,避免需要多次点击“加载更多”按钮。
  4. // @author ChatGPT
  5. // @version 3.7
  6. // @match https://m.baidu.com/*
  7. // @match https://www.baidu.com/*
  8. // @exclude https://*.baidu.com/video/
  9. // @run-at document-end
  10. // @grant none
  11. // @namespace https://gf.qytechs.cn/users/452911
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // 检查是否在搜索结果页面
  18. if (!window.location.href.includes('word=') && !window.location.href.includes('wd=')) {
  19. return;
  20. }
  21.  
  22. // 检查是否存在加载更多按钮
  23. var loadMoreButton = document.querySelector('div.se-infiniteload-text');
  24. if (!loadMoreButton) {
  25. return;
  26. }
  27.  
  28. // 如果存在"加载更多"span也点击
  29. var spanLoadMore = document.querySelector('div.se-infiniteload-text');
  30. if (spanLoadMore) {
  31. spanLoadMore.click();
  32. }
  33.  
  34. // 滚动时自动加载更多
  35. window.addEventListener('scroll', function() {
  36. var distanceToBottom = document.body.scrollHeight - (window.innerHeight + window.pageYOffset);
  37. if (distanceToBottom < 400) {
  38. var currentLoadMoreButton = document.querySelector('div.se-infiniteload-text');
  39. if (currentLoadMoreButton) {
  40. currentLoadMoreButton.click();
  41. }
  42. }
  43. });
  44.  
  45. // 隐藏元素
  46. var div = document.getElementById("head-queryarea");
  47. if (div) {
  48. div.style.display = "none";
  49. }
  50. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址