Google Search Results Filter

Hides specific Google search results based on href values. Motivation: I keep wasting my time opening reddit from search results and realizing that I don't have an access there

目前為 2025-01-16 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Google Search Results Filter
  3. // @namespace https://greasyfork.org/en/users/1413127-tumoxep
  4. // @version 1.0
  5. // @description Hides specific Google search results based on href values. Motivation: I keep wasting my time opening reddit from search results and realizing that I don't have an access there
  6. // @license WTFPL
  7. // @match https://www.google.com/search*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // List of keywords or URL substrings to hide
  15. const blacklist = [
  16. "reddit.com",
  17. ];
  18.  
  19. // Function to hide unwanted search results
  20. function filterResults() {
  21. // Select all results inside the #search element
  22. const results = document.querySelectorAll(`#search div[data-async-context*="query:"] > div`); // Adjust if necessary based on class structure
  23.  
  24. results.forEach((result) => {
  25. try {
  26. // Get the link nested 9 levels deep
  27. const link = result.querySelector("a");
  28. if (link && blacklist.some(keyword => link.href.includes(keyword))) {
  29. // Hide the result if it matches the blacklist
  30. result.style.display = "none";
  31. }
  32. } catch (e) {
  33. console.error("Error processing result:", e);
  34. }
  35. });
  36. }
  37.  
  38. // Run the filter when the page loads or updates
  39. const observer = new MutationObserver(filterResults);
  40. observer.observe(document.body, { childList: true, subtree: true });
  41.  
  42. // Initial filter run
  43. filterResults();
  44. })();