Google 搜索结果屏蔽

根据网站、网址和关键字来屏蔽不想要的搜索结果

  1. // ==UserScript==
  2. // @name Google 搜索结果屏蔽
  3. // @name:en Google Search Results Block
  4. // @namespace Cheez.Search
  5. // @version 1.0
  6. // @description 根据网站、网址和关键字来屏蔽不想要的搜索结果
  7. // @description:en Block Google bad results by sites, urls and keywords.
  8. // @icon https://www.google.co.jp/images/branding/product/ico/googleg_lodp.ico
  9. // @author 以茄之名
  10. // @author:en Cheez
  11. // @include https://www.google.*/search*
  12. // @include https://www.google.*.*/search*
  13. // @require https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @grant GM_registerMenuCommand
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. var $=jQuery,
  22. blacklist=GM_getValue('blacklist')&&JSON.parse(GM_getValue('blacklist'))||{
  23. host:[],
  24. url:[],
  25. word:[]
  26. },
  27. logs=[];
  28. if (GM_getValue('version')==''||GM_getValue('version')&&GM_getValue('version')<GM_info.script.version){
  29. var changes='';
  30. if(changes)alert(changes);
  31. GM_setValue('version',GM_info.script.version);
  32. }
  33. console.log(blacklist);
  34. $('[onmousedown]').attr('onmousedown','');
  35. $.each(jQuery('[href*=webcache]'),function(i,o){jQuery(o).attr('href',jQuery(o).attr('href').replace('p:','ps:'));});
  36.  
  37. function hid(hosts,urls,words){
  38. $('.g:not(.hiden,.checked) .r>a').filter(function(i,o){
  39.  
  40. if($.inArray(o.host,hosts)>-1){
  41. logs.push({'域名':o.host,'地址':o.href,'匹配类型':'域名'});
  42. return true;
  43. }
  44. var flag=false;
  45. $.each(urls,function(i,oo){
  46. if( (new RegExp(oo)).test(o.href) ){
  47. logs.push({'域名':o.host,'地址':o.href,'匹配类型':'地址','匹配':oo});
  48. flag=true; return false;
  49. }
  50. });
  51. $.each(words,function(i,oo){
  52. if( o.textContent.indexOf(oo) >-1 ){
  53. logs.push({'域名':o.host,'地址':o.href,'匹配类型':'关键字','匹配':oo});
  54. flag=true; return false;
  55. }
  56. });
  57.  
  58.  
  59. if(!flag){
  60. var p=$(o).parents('.g').addClass('checked');
  61. var menu=$(p).find('.action-menu-panel>ol');
  62. var li=$('<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl" data-host="'+o.host+'" data-url="'+o.href+'" tabindex="-1">屏蔽该类网址</a></li>');
  63. if( menu.size() ){
  64. //'<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl block-site" data-url="'+o.href+'" tabindex="-1">屏蔽该类网址</a></li>'+'<li class="action-menu-item ab_dropdownitem" role="menuitem" aria-selected="false"><a class="fl block" data-host="'+o.host+'" tabindex="-1">屏蔽该网站</a></li>');
  65. }else{
  66. var text='<div class="action-menu ab_ctl"><a class="_Fmb ab_button" href="#" aria-label="结果详情" aria-expanded="false" aria-haspopup="true" role="button" jsaction="m.tdd;keydown:m.hbke;keypress:m.mskpe" ><span class="mn-dwn-arw"></span></a><div class="action-menu-panel ab_dropdown" role="menu" tabindex="-1" jsaction="keydown:m.hdke;mouseover:m.hdhne;mouseout:m.hdhue"><ol> </ol></div></div>';
  67. menu=$(p).find('.kv').append(text ).find('.action-menu-panel>ol');
  68. }
  69. menu.filter(':not(:has(.block-site))').append(li.clone().find('a').addClass('block-site').end(),li.clone().find('a').addClass('block').text('屏蔽该网站').end()) ;
  70.  
  71. }
  72.  
  73. return flag;
  74. }).parents('.g').addClass('hiden').hide();
  75. if(logs.length){console.table(logs);logs=[];}
  76.  
  77. }
  78. var aThing;
  79. $(document.body).on('DOMNodeInserted', function () {
  80. clearTimeout(aThing);
  81. aThing = setTimeout(function () {
  82. if($('.sp-separator').size()){$(document.body).trigger('aThing');}
  83. }, 50);
  84. });
  85.  
  86. $(document.body).on('aThing', function () { //监听DOM树插入
  87. hid(blacklist.host,blacklist.url,blacklist.word);
  88. $('[onmousedown]').attr('onmousedown','');
  89. $.each(jQuery('[href*=webcache]'),function(i,o){jQuery(o).attr('href',jQuery(o).attr('href').replace('p:','ps:'));});
  90. });
  91. hid(blacklist.host,blacklist.url,blacklist.word);
  92. $('#rso').delegate('a.block','click',function(e){
  93. $(this).parents('.g').addClass('hiden').hide();
  94. blacklist.host.push($(this).data('host'));
  95. GM_setValue('blacklist',JSON.stringify(blacklist));
  96. hid([$(this).data('host')],[],[]);
  97. });
  98. $('#rso').delegate('a.block-site','click',function(e){
  99. var mch=prompt("请输入对应的匹配",$(this).data('url').replace(/(?!\\)([\$\(\)\*\+\.\[\]\?\^\{\}\|\\])/g,/\\$1/));
  100. if(mch){
  101. mch=str2reg(mch);
  102. $(this).parents('.g').addClass('hiden').hide();
  103. blacklist.url.push(mch);
  104. GM_setValue('blacklist',JSON.stringify(blacklist));
  105. hid([],[mch],[]);
  106. }
  107. });
  108.  
  109. function addKeyword() {
  110. var word=prompt("请输入要屏蔽的关键字(Input the keyword.)" );
  111. if(word){
  112. blacklist.word.push(word);
  113. GM_setValue('blacklist',JSON.stringify(blacklist));
  114. hid([],[ ],[word]);
  115. }
  116. }
  117.  
  118. GM_registerMenuCommand("增加屏蔽关键字(Add keyword)", addKeyword);
  119.  
  120. $(window).on('close', function () { GM_setValue('blacklist',JSON.stringify(blacklist));});
  121.  
  122. function str2reg(str){
  123. return str.replace(/(?!\\)([\$\(\)\*\+\.\[\]\?\^\{\}\|\\])/g,/\\$1/);
  124. }
  125.  
  126. })();

QingJ © 2025

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