Skip to content

Instantly share code, notes, and snippets.

@ricky9w
Created July 31, 2024 06:38
Show Gist options
  • Save ricky9w/1fec6e3c9890e29ed0e1b18d7d8672fb to your computer and use it in GitHub Desktop.
Save ricky9w/1fec6e3c9890e29ed0e1b18d7d8672fb to your computer and use it in GitHub Desktop.
Hide 'Sponsored' results from Google search results
// ==UserScript==
// @name Hide Ads From Google Search Page
// @description Hide 'Sponsored' results from Google search results
// @match https://www.google.com/search*
// ==/UserScript==
(function() {
'use strict';
// Function to hide elements
function hideElements() {
var elements = [...document.querySelectorAll('div.qGXjvb'), ...document.querySelectorAll('div#tads')]
elements.forEach(function(element) {
element.style.display = 'none';
});
}
// Hide elements when the page loads
window.addEventListener('load', hideElements);
// Hide elements when the DOM changes
var observer = new MutationObserver(hideElements);
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment