Skip to content

Instantly share code, notes, and snippets.

@sanjeed5
Created January 27, 2026 14:11
Show Gist options
  • Select an option

  • Save sanjeed5/a447d495d0b680616ea10ad769708ff3 to your computer and use it in GitHub Desktop.

Select an option

Save sanjeed5/a447d495d0b680616ea10ad769708ff3 to your computer and use it in GitHub Desktop.
Tampermonkey script to hide sponsored products on Amazon India search results
// ==UserScript==
// @name Amazon India - Hide Sponsored Products
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Hides sponsored product listings on Amazon.in search results
// @author You
// @match https://www.amazon.in/s*
// @match https://www.amazon.in/s?*
// @grant GM_addStyle
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// CSS-based hiding (fastest, works immediately)
const style = document.createElement('style');
style.textContent = `
/* Primary: AdHolder class on the result container */
.AdHolder {
display: none !important;
}
/* Backup selectors */
.s-result-item:has(.puis-sponsored-label-text) {
display: none !important;
}
div[data-component-type="s-search-result"]:has(a[href*="/sspa/click"]) {
display: none !important;
}
`;
document.head.appendChild(style);
// JS fallback for older browsers or if CSS doesn't catch everything
function hideSponsored() {
// Method 1: AdHolder class (most reliable based on the HTML)
document.querySelectorAll('.AdHolder').forEach(el => {
el.style.display = 'none';
});
// Method 2: Find by sponsored label and traverse up
document.querySelectorAll('.puis-sponsored-label-text').forEach(el => {
const card = el.closest('[data-component-type="s-search-result"]');
if (card) card.style.display = 'none';
});
// Method 3: Find by sspa click tracking URLs
document.querySelectorAll('a[href*="/sspa/click"]').forEach(el => {
const card = el.closest('[data-component-type="s-search-result"]');
if (card) card.style.display = 'none';
});
}
// Run when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', hideSponsored);
} else {
hideSponsored();
}
// Watch for dynamically loaded content
const observer = new MutationObserver(() => {
hideSponsored();
});
// Start observing once body exists
const startObserver = () => {
if (document.body) {
observer.observe(document.body, {
childList: true,
subtree: true
});
} else {
requestAnimationFrame(startObserver);
}
};
startObserver();
// Run a few times in the first seconds to catch late-loading ads
setTimeout(hideSponsored, 500);
setTimeout(hideSponsored, 1000);
setTimeout(hideSponsored, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment