百度搜索结果过滤

兼容AC双列baidu脚本,搜索结果增加屏蔽按钮,有可视化列表查看编辑保存,支持通配符* ?

  1. // ==UserScript==
  2. // @name 百度搜索结果过滤
  3. // @name:zh 百度搜索结果过滤
  4. // @name:zh-CN 百度搜索结果过滤
  5. // @name:zh-TW 百度搜索结果过滤
  6. // @namespace http://tampermonkey.net/
  7. // @version 0.3
  8. // @connect *
  9. // @description 兼容AC双列baidu脚本,搜索结果增加屏蔽按钮,有可视化列表查看编辑保存,支持通配符* ?
  10. // @description:zh 兼容AC双列baidu脚本,搜索结果增加屏蔽按钮,有可视化列表查看编辑保存,支持通配符* ?
  11. // @description:zh-CN 兼容AC双列baidu脚本,搜索结果增加屏蔽按钮,有可视化列表查看编辑保存,支持通配符* ?
  12. // @description:zh-TW 兼容AC双列baidu脚本,搜索结果增加屏蔽按钮,有可视化列表查看编辑保存,支持通配符* ?
  13. // @author 关公说爱情
  14. // @license MIT
  15. // @match https://*.baidu.com/*
  16. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
  17. // @require https://cdn.bootcdn.net/ajax/libs/layer/3.5.1/layer.min.js
  18. // @exclude https://www.baidu.com/img/*
  19. // @grant GM_setValue
  20. // @grant GM_getValue
  21. // @grant GM_deleteValue
  22. // @grant GM_xmlhttpRequest
  23. // ==/UserScript==
  24.  
  25. (function() {
  26. 'use strict';
  27. const baiduHelper={};
  28.  
  29. var $ = $ || window.$,
  30. removing = false,
  31. blacklist,
  32. refUrls={};
  33.  
  34. $(document.body).append(`<link href="https://cdn.bootcdn.net/ajax/libs/layer/3.5.1/theme/default/layer.min.css" rel="stylesheet">`);
  35.  
  36. function globToRegex (glob) {
  37. var specialChars = "\\^$*+?.()|{}[]";
  38. var regexChars = ["^"];
  39. for (var i = 0; i < glob.length; ++i) {
  40. var c = glob.charAt(i);
  41. switch (c) {
  42. case '?':
  43. regexChars.push(".");
  44. break;
  45. case '*':
  46. regexChars.push(".*");
  47. break;
  48. default:
  49. if (specialChars.indexOf(c) >= 0) {
  50. regexChars.push("\\");
  51. }
  52. regexChars.push(c);
  53. }
  54. }
  55. regexChars.push("$");
  56. return new RegExp(regexChars.join(""));
  57. }
  58.  
  59. baiduHelper.init = function(){
  60. blacklist = GM_getValue("blacklist");
  61. if(blacklist==undefined)
  62. {
  63. blacklist = [];
  64. }
  65.  
  66. $('.s_tab_inner').append('<a id="showBlackList" href="javascript:;" class="s-tab-item">屏蔽列表</a>');
  67. $('#showBlackList').on('click', function () {
  68. let listvalue='';
  69. for (let x = 0; x < blacklist.length; x++) {
  70. listvalue += blacklist[x];
  71. if(x<blacklist.length - 1)
  72. {
  73. listvalue += "\n";
  74. }
  75. }
  76.  
  77. layer.prompt({
  78. title: '域名屏蔽列表,一行一个,支持 * ? 通配符!自动过滤空行',
  79. formType: 2,
  80. area: ['500px', '350px'],
  81. value:listvalue,
  82. yes: function (index, layero) {
  83. let pass = $(document.getElementsByClassName('layui-layer-input')[0]).val();
  84. if(pass.length > 0){
  85. blacklist = pass.split('\n');
  86. }
  87. else{
  88. blacklist = [];
  89. }
  90. blacklist = blacklist.filter(function (s) { return s && s.trim(); });
  91. GM_setValue("blacklist",blacklist);
  92. layer.close(index);
  93. }
  94. });
  95. });
  96.  
  97. $('body').on('click', '.removeItemButton', function () {
  98. let domain = $(this).attr('data-domain');
  99. layer.confirm('是否将『'+domain+'』加入到屏蔽列表?', {
  100. btn: ['是','否']
  101. }, function(index){
  102. blacklist.push(domain);
  103. GM_setValue("blacklist",blacklist);
  104. baiduHelper.removeItem();
  105. layer.close(index)
  106. });
  107. });
  108.  
  109. var beforeScrollTop = document.documentElement.scrollTop
  110. window.addEventListener("scroll", function (e) {
  111. var afterScrollTop = document.documentElement.scrollTop,
  112. delta = afterScrollTop - beforeScrollTop;
  113. if (delta === 0) return false;
  114. if (delta > 0) {
  115. var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  116. let scrollDelta = 666;
  117. if (document.documentElement.scrollHeight <= document.documentElement.clientHeight + scrollTop + scrollDelta) {
  118. if(!removing)
  119. {
  120. removing=true;
  121. setTimeout(function() {
  122. baiduHelper.addButton();
  123. baiduHelper.removeItem();
  124. removing=false;
  125. }, 2000);
  126. }
  127. }
  128. }
  129. beforeScrollTop = afterScrollTop;
  130. }, false);
  131. }
  132.  
  133. baiduHelper.cleanAd = function(){
  134. $('#content_right').remove();
  135. $('#rs_new').remove();
  136. $('#foot').remove();
  137. };
  138.  
  139. baiduHelper.removeItem = function(){
  140. let $rows = $('#content_left .new-pmd');
  141. $rows.each(function(){
  142. let $row = $(this);
  143. let mu = $row.attr('mu');
  144. let domain='';
  145. if(mu !== undefined )
  146. {
  147. domain = baiduHelper.getUrlDomain(mu);
  148. }else
  149. {
  150. domain = $row.attr('data-domain');
  151. }
  152.  
  153. for (let x = 0; x < blacklist.length; x++) {
  154. if(globToRegex(blacklist[x]).test(domain))
  155. {
  156. $(this).remove()
  157. break;
  158. }
  159. }
  160. });
  161. };
  162.  
  163. baiduHelper.getUrlDomain = function(refUrl){
  164. let domain = refUrl.split('/');
  165. if(domain[2])
  166. {
  167. return domain[2];
  168. }
  169. return '';
  170. };
  171.  
  172. baiduHelper.addButton = function(){
  173. let $rows = $('#content_left .new-pmd');
  174.  
  175. $rows.each(function(){
  176. let $row = $(this);
  177. let mu = $row.attr('mu');
  178.  
  179. if(mu !==undefined)
  180. {
  181. let $tools = $row.find('.c-icon').closest(".c-row.c-gap-top-xsmall");
  182. let domain = baiduHelper.getUrlDomain(mu);
  183. $row.attr('data-domain',domain);
  184. if($tools.find('.removeItemButton').length==0)
  185. {
  186. $tools.append('<a style="margin-left: 8px" class="removeItemButton" data-domain="' + domain + '"><span class="c-color-gray" aria-hidden="true">✌屏蔽它✌</span></a>');
  187. }
  188. }
  189. else
  190. {
  191. let $a = $(this).find('a').eq(1);
  192. if($a.length > 0)
  193. {
  194. let href = $a.attr('href');
  195. let refUrl = refUrls[href];
  196. if(refUrl == undefined)
  197. {
  198. if(href.startsWith("http"))
  199. {
  200.  
  201. let url = href.replace(/^http:/, "https:");
  202. let request = GM_xmlhttpRequest({
  203. url: url,
  204. headers: {"Accept": "*/*", "Referer": url},
  205. method: "GET",
  206. timeout: 5000,
  207. onreadystatechange: function (response) {
  208. if(response.readyState===4)
  209. {
  210. refUrls[href] = response.finalUrl;
  211. let domain = baiduHelper.getUrlDomain(refUrls[href]);
  212. let $tools = $row.find('.c-icon').closest(".c-row.c-gap-top-xsmall");
  213. if($tools.length==0)
  214. {
  215. $tools = $row.find('.c-icon').closest(".g");
  216. }
  217. if($tools.length >0 )
  218. {
  219. $row.attr('data-domain',domain);
  220. if($tools.find('.removeItemButton').length==0)
  221. {
  222. $tools.append('<a style="margin-left: 8px" class="removeItemButton" data-domain="' + domain + '"><span class="c-color-gray" aria-hidden="true">✌屏蔽它✌</span></a>')
  223. }
  224. }
  225. }
  226. },
  227. onerror: function (response) {
  228.  
  229. }
  230. });
  231. }
  232. }
  233. else
  234. {
  235.  
  236. }
  237. }
  238. }
  239. });
  240. };
  241.  
  242. baiduHelper.cleanAd();
  243. baiduHelper.init();
  244. baiduHelper.addButton();
  245. baiduHelper.removeItem();
  246. })();

QingJ © 2025

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