SearX Results Filter

Remove links from search results.

  1. // ==UserScript==
  2. // @name SearX Results Filter
  3. // @namespace i2p.schimon.searxfilter
  4. // @description Remove links from search results.
  5. // @author Schimon Jehudah, Adv.
  6. // @copyright 2023, Schimon Jehudah (http://schimon.i2p)
  7. // @license MIT; https://opensource.org/licenses/MIT
  8. // @grant none
  9. // @homepageURL https://openuserjs.org/scripts/sjehuda/SearX_Results_Filter
  10. // @supportURL https://openuserjs.org/scripts/sjehuda/SearX_Results_Filter/issues
  11. // @include https://SearxngInstanceUrl/search*
  12. // @version 23.03
  13. // @run-at document-end
  14. // @icon data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjRtbSIgaGVpZ2h0PSI2NG1tIiB2aWV3Qm94PSIwIDAgNjQgNjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHRleHQgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgc3R5bGU9ImZvbnQtd2VpZ2h0OjQwMDtmb250LXNpemU6MTkycHg7bGluZS1oZWlnaHQ6MDt0ZXh0LWluZGVudDowO3RleHQtYWxpZ246c3RhcnQ7dGV4dC1kZWNvcmF0aW9uLXN0eWxlOnNvbGlkO3RleHQtZGVjb3JhdGlvbi1jb2xvcjojMDAwO3dyaXRpbmctbW9kZTpsci10YjtkaXJlY3Rpb246bHRyO3RleHQtb3JpZW50YXRpb246bWl4ZWQ7ZG9taW5hbnQtYmFzZWxpbmU6YXV0bztiYXNlbGluZS1zaGlmdDpiYXNlbGluZTt0ZXh0LWFuY2hvcjpzdGFydDtzaGFwZS1wYWRkaW5nOjA7c2hhcGUtbWFyZ2luOjA7aW5saW5lLXNpemU6MDtvcGFjaXR5OjE7ZmlsbDojMDAwO2ZpbGwtb3BhY2l0eToxO3N0cm9rZS13aWR0aDoxLjI3OTgyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eToxO3N0b3AtY29sb3I6IzAwMDtzdG9wLW9wYWNpdHk6MSIgeD0iMTcuMDA1MjQ1IiB5PSIzMS42NTg0MDUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC00LjQzNjg1NjQgNDAuODk0OTQpIHNjYWxlKC4yNjQ1OCkiPjx0c3BhbiB4PSIxNy4wMDUyNDUiIHk9IjMxLjY1ODQwNSIgc3R5bGU9ImZvbnQtc2l6ZToxOTJweCI+8J+boO+4jzwvdHNwYW4+PC90ZXh0Pjwvc3ZnPgo=
  15. // ==/UserScript==
  16.  
  17. // Javascript implementation of Java’s String.hashCode() method
  18. String.prototype.hashCode = function(){
  19. var hash = 0;
  20. if (this.length == 0) return hash;
  21. for (i = 0; i < this.length; i++) {
  22. char = this.charCodeAt(i);
  23. hash = ((hash<<5)-hash)+char;
  24. hash = hash & hash; // Convert to 32bit integer
  25. }
  26. return hash;
  27. };
  28. // Manwe Security Consulting
  29.  
  30. const domains = [
  31. 1011086976,1072789513,1746076303,1873419916,1807696995,200689189,208906360,
  32. 165020600,-138065189,-554920372,1482490179,2041621832,508927357,332286469,
  33. 2127428686,1803821636,-772970925,60433162,2056911440,-696086213,-226216208,
  34. 568696146,2056911440,-1376709159,374301332,-1710483397,-491772566,58427465,
  35. -2051420948,-1031144132,-333386213,1837301364,204018826,-972811757,-686515808,
  36. -2044679369,540535309,-383025757,1591598804,-2032889839,-516285098,2056053460,
  37. 904207091,-774960864,-1704017372,754392788,253824854,1331596452,-1394732048,
  38. -2049573906,-1694642173,1877757210,707076672,-2050497427,1073639165,1011107447,
  39. -2067829511,1561330680,2004471051,-964488554,-2044898019,129388118,1042705622,
  40. 659999749,-1986430767,-1557529491,-1473409395,-640005308,-1830313082,1320172991,
  41. -1452764056,1530878469,1672584528,1912841799,-631031994,-1759516559,-373274299,
  42. 1472103342,28462918,-1384399005,-1025028954,-1002905536,-1536293812,847444939,
  43. -1240091005,-1240090634,-1610658671,426751880,1349062171,-1423874876,855396316,
  44. -1057382331,
  45. -1207901707, // abc.com
  46. -224401944, // www.abc.net.au
  47. 91124052, // abcnews.go.com
  48. -1413024603, // ap.org
  49. -255548196, // www.ap.org
  50. -1059667691, // apnews.com
  51. -593770790, // ground.news
  52. -347527963, // bbcnews.bbcstudios.com
  53. -1856091953, // wwwnews.live.bbc.co.uk
  54. 1201632223, // www.bbc.com
  55. 824039218, // www.bbcnews.com
  56. -770409358, // news.bbc.co.uk
  57. 1335085517, // bbc.co.uk
  58. -577693130, // www.bbc.co.uk
  59. 758316297, // bbcnews.com
  60. 941125331, // bing.com
  61. 879422794, // www.bing.com
  62. 317218970, // bloomberglaw.com
  63. -1802373298, // bloomberg.com
  64. 1227811639, // www.bloomberg.com
  65. -1057277710, // www.businessinsider.com
  66. 1100257225, // businessinsider.com
  67. 106864602, // cbsnews.com
  68. 172587523, // www.cbsnews.com
  69. -1815724417, // cnbc.com
  70. -1877426954, // www.cnbc.com
  71. 920814198, // cnn.com
  72. -1852122849, // www.cnn.com
  73. 369654750, // www.foxnews.com
  74. 303931829, // foxnews.com
  75. -1242184837, // go.com
  76. 1617840950, // guardian.ng
  77. 1001802679, // www.huffpost.com
  78. -1035607872, // huffpost.com
  79. -471498931, // www.independent.co.uk
  80. 1881581540, // independent.co.uk
  81. 1668850948, // latimes.com
  82. 1734573869, // www.latimes.com
  83. 'mozilla.com',
  84. 'mozilla.org',
  85. 669736469, // nbcnews.com
  86. 735459390, // www.nbcnews.com
  87. 955565566, // nypost.com
  88. -2140583194, // npr.org
  89. 2014281623, // www.nytimes.com
  90. 1948558702, // nytimes.com
  91. 1065885552, // politico.com
  92. -1191671193, // www.politico.com
  93. -381258527, // politico.eu
  94. -315535606, // www.politico.eu
  95. 802420432, // www.reuters.com
  96. 736697511, // reuters.com
  97. -2134724812, // sky.com
  98. 1103245374, // www.theguardian.com
  99. 1083347605, // theguardian.com
  100. 622620063, // thetimes.co.uk
  101. 69072598, // www.thetimes.co.uk
  102. -2036711631, // usatoday.com
  103. 698920, // www.usatoday.com
  104. 1149470915, // washingtonpost.com
  105. 1218420346, // www.washingtonpost.com
  106. -1328826067, // wikipedia.org
  107. 1630470305, // wsj.com
  108. -1142466742, // www.wsj.com
  109. -1311829293, // yahoo.com
  110. 1070359356, // www.yahoo.com
  111. 1123383988, // ca.sports.yahoo.com
  112. 'yewtu.be',
  113. 'youtu.be',
  114. 'youtube.com',
  115. -12310945, // www.youtube.com
  116. -78033866, // youtube.com
  117. ];
  118.  
  119. console.info('Copy the following string, if you want to filter results of this website');
  120. console.info(location.hostname.hashCode() + ', // ' + location.hostname);
  121.  
  122. (function removeResultItems() {
  123.  
  124. // Scan results to filter
  125. for (const link of document.querySelectorAll('a[href^="http"]')) {
  126.  
  127. var hostname, url, i = 0;
  128.  
  129. try {
  130. url = new URL (link.href);
  131. hostname = url.hostname;
  132. } catch (err) {
  133. var invalidLink = link.href;
  134. var locationHrf = location.href;
  135. var searchQuery = document.querySelector('input').value;
  136. console.error(`Error: ${err}`);
  137. console.warn(
  138. `
  139. WARNING! Invalid URL
  140. URL: "${invalidLink}"
  141. Instance: "${locationHrf}"
  142. Query: "${searchQuery}".
  143. Please report this to SearXNG.
  144. `
  145. );
  146. }
  147.  
  148. if (hostname.endsWith('.xxx') ||
  149. hostname.endsWith('.sex') ||
  150. hostname.endsWith('.porn') ||
  151. hostname.endsWith('.adult')) {
  152. removeNode(link);
  153. removalReason(link.href, null);
  154. continue;
  155. }
  156.  
  157. if (domains.includes(hostname) ||
  158. domains.includes(hostname.hashCode())) {
  159. removalReason(link.href, hostname);
  160. removeNode(link);
  161. continue;
  162. }
  163.  
  164. if (hostname.startsWith('www.')) {
  165. hostname =
  166. hostname
  167. .slice(
  168. hostname
  169. .indexOf('www.')+4
  170. );
  171. }
  172.  
  173. /*
  174. if (domains.includes(hostname)) {
  175. link
  176. .closest('.result')
  177. .remove();
  178. }
  179. */
  180.  
  181. if (domains.includes(hostname) ||
  182. domains.includes(hostname.hashCode())) {
  183. removalReason(link.href, hostname);
  184. removeNode(link);
  185. continue;
  186. }
  187.  
  188. var partedHost = hostname.split('.');
  189. var tld = partedHost[partedHost.length-2] + '.' + partedHost[partedHost.length-1];
  190.  
  191. if (domains.includes(tld) ||
  192. domains.includes(tld.hashCode())) {
  193. removalReason(link.href, tld);
  194. removeNode(link);
  195. continue;
  196. }
  197.  
  198. }
  199.  
  200. // When all result were filtered, navigate to next page
  201. if (document.querySelectorAll('.result').length < 1) {
  202. try {
  203. document.querySelector('.next_page > * > button').click();
  204. } catch {
  205. alert('No results.');
  206. }
  207. }
  208.  
  209. // TODO Execute upon content change
  210. document.addEventListener('scroll', removeResultItems);
  211.  
  212. // Display block rule
  213. document.addEventListener("mouseover", function(e) {
  214. if (e.target && e.target.nodeName == "A") {
  215. url = new URL (e.target);
  216. console.info(`INFO: To filter results from ${url.hostname}, use the following string ${url.hostname.hashCode() + ', // ' + url.hostname}`);
  217. }
  218. });
  219.  
  220. })();
  221.  
  222. function removeNode(link) {
  223. try {
  224. link
  225. .closest('.result')
  226. .remove();
  227. } catch {
  228. try {
  229. link
  230. .closest('#infoboxes')
  231. .remove();
  232. } catch (err) {
  233. console.error('Error: ' + err);
  234. }
  235. }
  236.  
  237. }
  238.  
  239. function removalReason(url, rule) {
  240.  
  241. if (rule) {
  242. try {
  243. rule = domains[domains.indexOf(rule.hashCode())];
  244. } catch {
  245. rule = domains[domains.indexOf(rule)];
  246. }
  247. console.log(`Link: ${url} has been blocked by rule ${rule}`);
  248. } else {
  249. console.log(`Link: ${url} has been blocked by TLD rule.`);
  250. }
  251. }

QingJ © 2025

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