搜索引擎自动加载下一页

搜索引擎自动加载下一页,包括baidu sogou bing 360so

  1. // ==UserScript==
  2. // @name 搜索引擎自动加载下一页
  3. // @namespace http://tampermonkey.net/
  4. // @home-url https://github.com/jueserencai/search-engines-next-page
  5. // @description 搜索引擎自动加载下一页,包括baidu sogou bing 360so
  6. // @version 0.0.2
  7. // @author 绝色人才
  8. // @include https://www.sogou.com/web*
  9. // @include https://cn.bing.com/search*
  10. // @include https://www.baidu.com/s*
  11. // @include https://www.so.com/s*
  12. // @require https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
  13. // @run-at document-end
  14. // @connect *
  15. // ==/UserScript==
  16.  
  17.  
  18. (function () {
  19. 'use strict';
  20. // console.log("ok1");
  21. /* 返回网址对应的搜索引擎类,包含ajax参数,更新下一页码、查询关键词等的方法 */
  22. function Config() {
  23. this.sogou = function () {
  24. // 类型1是搜索引擎
  25. this.type = 1;
  26. this.config = {
  27. url: "https://www.sogou.com/web",
  28. data: {
  29. ie: "utf8",
  30. query: "",
  31. page: 1,
  32. },
  33. getOrPost: "GET",
  34. parentNodeName: "#main",
  35. contentNodeName: ".results",
  36. inputId: "#upquery",
  37. };
  38. let sogouObj = this;
  39. this.nextPage = function () {
  40. sogouObj.config.data.page += 1;
  41. };
  42. this.resetPage = function () {
  43. sogouObj.config.data.page = 1;
  44. };
  45. this.getQuery = function() {
  46. return sogouObj.config.data.query;
  47. };
  48. this.updateQuery = function(queryString) {
  49. sogouObj.config.data.query = queryString;
  50. };
  51. };
  52.  
  53. this.bing = function() {
  54. // 类型1是搜索引擎
  55. this.type = 1;
  56. this.config = {
  57. url: "https://cn.bing.com/search",
  58. data: {
  59. q: "",
  60. first: 0,
  61. },
  62. getOrPost: "GET",
  63. parentNodeName: "#b_results",
  64. contentNodeName: ".b_algo",
  65. inputId: "#sb_form_q",
  66. };
  67. let bingObj = this;
  68. this.nextPage = function () {
  69. return bingObj.config.data.first += 10;
  70. };
  71. this.resetPage = function () {
  72. bingObj.config.data.first = 0;
  73. };
  74. this.getQuery = function() {
  75. return bingObj.config.data.q;
  76. };
  77. this.updateQuery = function(queryString) {
  78. bingObj.config.data.q = queryString;
  79. };
  80.  
  81. (function() {
  82. // 隐藏第一页底部的页码
  83. $(bingObj.config.parentNodeName).children().slice(-3).hide();
  84. })();
  85. };
  86.  
  87. this.baidu = function() {
  88. // 类型1是搜索引擎
  89. this.type = 1;
  90. this.config = {
  91. url: "https://www.baidu.com/s",
  92. data: {
  93. ie: "utf-8",
  94. wd: "",
  95. pn: 0,
  96. },
  97. getOrPost: "GET",
  98. parentNodeName: "#content_left",
  99. contentNodeName: ".result",
  100. inputId: "#kw",
  101. };
  102. let baiduObj = this;
  103. this.nextPage = function () {
  104. baiduObj.config.data.pn += 10;
  105. };
  106. this.resetPage = function () {
  107. baiduObj.config.data.pn = 0;
  108. };
  109. this.getQuery = function() {
  110. return baiduObj.config.data.wd;
  111. };
  112. this.updateQuery = function(queryString) {
  113. baiduObj.config.data.wd = queryString;
  114. };
  115.  
  116. (function() {
  117. // 页面中点击搜索按钮,重置页码
  118. $("#su").click(function() {
  119. baiduObj.resetPage();
  120. });
  121. })();
  122. };
  123.  
  124. this.so360 = function() {
  125. // 类型1是搜索引擎
  126. this.type = 1;
  127. this.config = {
  128. url: "https://www.so.com/s",
  129. data: {
  130. q: "",
  131. pn: 1,
  132. },
  133. getOrPost: "GET",
  134. parentNodeName: "#main > .result",
  135. contentNodeName: ".res-list",
  136. inputId: "#keyword",
  137. };
  138. let so360Obj = this;
  139. this.nextPage = function () {
  140. so360Obj.config.data.pn += 1;
  141. };
  142. this.resetPage = function () {
  143. so360Obj.config.data.pn = 1;
  144. };
  145. this.getQuery = function() {
  146. return so360Obj.config.data.q;
  147. };
  148. this.updateQuery = function(queryString) {
  149. so360Obj.config.data.q = queryString;
  150. };
  151. };
  152.  
  153. // 根据网址返回对应的配置类
  154. // return new this.bing();
  155. let configObj = this;
  156. return (function() {
  157. let host = window.location.host;
  158. let reg = /\.[a-z|0-9]+\.com/;
  159. let res = reg.exec(host)[0];
  160. res = res.substring(1, res.length-4);
  161. if (res == "sogou") {
  162. return new configObj.sogou();
  163. } else if (res == "bing") {
  164. return new configObj.bing();
  165. } else if (res == "baidu") {
  166. return new configObj.baidu();
  167. } else if (res == "so") {
  168. return new configObj.so360();
  169. }
  170. })();
  171. };
  172. var searchEngine = new Config();
  173. // console.log("ok2");
  174.  
  175. /* 加载下一页数据,插入当前页 */
  176. function PreLoader() {
  177. let preLoaderObj = this;
  178. // 预处理
  179. this.preprocessing = function(searchEngine) {
  180. // 更新查询字符串,页码
  181. let queryString = $(searchEngine.config.inputId).val();
  182. let oldQueryString = searchEngine.getQuery();
  183. searchEngine.updateQuery(queryString);
  184. if (oldQueryString == "") {
  185. searchEngine.nextPage();
  186. }else if (oldQueryString != queryString) {
  187. searchEngine.resetPage();
  188. }
  189. };
  190. this.loadNextPage = function(callback) {
  191. // 调用预处理
  192. preLoaderObj.preprocessing(searchEngine);
  193.  
  194. // ajax请求下一页,并插进当前页中
  195. $.ajax({
  196. url: searchEngine.config.url,
  197. type: searchEngine.config.getOrPost,
  198. data: searchEngine.config.data,
  199. success: function(data, status) {
  200. let contentNode = $(data).find(searchEngine.config.parentNodeName).find(searchEngine.config.contentNodeName);
  201. let $div = $(searchEngine.config.parentNodeName);
  202. // 下一页内容插入当前页末尾
  203. $div.append(contentNode);
  204. // 两页之间添加分割线
  205. $div.append(`
  206. <div style="height: 20px;"><HR style="FILTER: progid:DXImageTransform.Microsoft.Glow(color=#987cb9,strength=10)" width="100%" color=#987cb9 SIZE=1></div>
  207. `);
  208. searchEngine.nextPage();
  209.  
  210. // 调用滚动到底部检测
  211. callback();
  212. },
  213. error: function(e) {
  214. if (e.status == 404) {
  215. $(searchEngine.config.parentNodeName).append(`<p style="text-align: center; font-size: 18px;">已完</p>`);
  216. }
  217. },
  218. });
  219. };
  220. }
  221. var preLoader = new PreLoader();
  222. // console.log("ok3");
  223.  
  224. /* 滚动到底部检测,判断是否要插入下一页 */
  225. (function scrollLoadPage() {
  226. $(window).unbind("scroll").scroll(function() {
  227. let scrollTop = $(this).scrollTop(); //获取滚动条到顶部的距离
  228. let windowHeight = window.screen.height * 1.5; //获取窗口的高度
  229. let documentHeight = $(document).height(); //获取文档区域高度
  230.  
  231. // console.log(scrollTop, windowHeight, documentHeight);
  232. if (scrollTop + windowHeight >= documentHeight) {
  233. $(this).unbind("scroll");
  234. preLoader.loadNextPage(scrollLoadPage);
  235. }
  236. });
  237. })();
  238. })();

QingJ © 2025

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