Created
July 31, 2024 06:38
-
-
Save ricky9w/1fec6e3c9890e29ed0e1b18d7d8672fb to your computer and use it in GitHub Desktop.
Hide 'Sponsored' results from Google search results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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