Amazon Sponsored Products remover

Removes the terrible sponsored products from Amazon.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Amazon Sponsored Products remover
// @namespace   https://greasyfork.org/en/users/2755-robotoilinc
// @author      RobotOilInc
// @version     0.4.0
// @license     MIT
// @description Removes the terrible sponsored products from Amazon.
// @include     http*://www.amazon.*/*
// @icon        https://i.imgur.com/LGHKHEs.png
// @run-at      document-body
// @grant       GM_registerMenuCommand
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

// ------------------------------------------------------------
// Persistent Settings
// ------------------------------------------------------------
const SETTINGS = {
    logging: GM_getValue("logging", false),
    showStats: GM_getValue("showStats", false)
};

// ------------------------------------------------------------
// Menu System
// ------------------------------------------------------------
const registerMenu = () => {
    GM_registerMenuCommand(`Logging: ${SETTINGS.logging ? "✔" : "✘"}`, () => {
        SETTINGS.logging = !SETTINGS.logging;
        GM_setValue("logging", SETTINGS.logging);
        location.reload();
    });

    GM_registerMenuCommand(`Stats: ${SETTINGS.showStats ? "✔" : "✘"}`, () => {
        SETTINGS.showStats = !SETTINGS.showStats;
        GM_setValue("showStats", SETTINGS.showStats);
        updateStatsVisibility();
        location.reload();
    });
};

// ------------------------------------------------------------
// Stats Counter UI
// ------------------------------------------------------------
let stats = {
    total: 0,
    rules: {}
};

const createStatsBox = () => {
    if (document.getElementById("amazon-remover-stats")) return;

    const box = document.createElement("div");
    box.id = "amazon-remover-stats";
    box.innerHTML = `
        <strong>Amazon Remover</strong><br>
        Removed: <span id="ars-total">0</span>
        <hr id="ars-divider" style="margin:6px 0; border:0; border-top:1px solid rgba(255,255,255,0.25); display:none;">
        <div id="ars-breakdown"></div>
    `;

    // Add some CSS
    Object.assign(box.style, { position: "fixed", bottom: "10px", right: "10px", background: "rgba(0,0,0,0.75)", color: "white", padding: "10px 14px", fontSize: "12px", borderRadius: "6px", zIndex: "999999", maxWidth: "220px", lineHeight: "1.4", display: "none" });

    document.body.appendChild(box);
};


const updateStatsVisibility = () => {
    const box = document.getElementById("amazon-remover-stats");
    if (box) box.style.display = SETTINGS.showStats ? "block" : "none";
};

const updateStats = reason => {
    stats.total++;
    stats.rules[reason] = (stats.rules[reason] || 0) + 1;

    document.getElementById("ars-total").textContent = stats.total;

    // Show divider only after first removal
    if (stats.total === 1) {
        document.getElementById("ars-divider").style.display = "block";
    }

    const breakdown = Object.entries(stats.rules)
    .map(([k, v]) => `${k}: ${v}`)
    .join("<br>");

    document.getElementById("ars-breakdown").innerHTML = breakdown;
};

// ------------------------------------------------------------
// Logging Helper
// ------------------------------------------------------------
const log = (reason, el) => {
    if (SETTINGS.logging) {
        console.log(`[AmazonRemover] ${reason}`, el);
    }
};

// ------------------------------------------------------------
// Rule Engine
// ------------------------------------------------------------
const RULES = [
    { selector: '[data-component-type="sp-sponsored-result"]', reason: 'Sponsored search result', parent: '[data-asin]' },
    { selector: '.sp_desktop_sponsored_label', reason: 'Sponsored carousel ad', parent: '.a-carousel-container' },

    { selector: '[class*="_adPlacements"]', reason: 'Skyscraper ad' },
    { selector: '[data-cel-widget*="adplacements"]', reason: 'Skyscraper ad' },

    { selector: '#discovery-and-inspiration_feature_div', reason: 'Product page ad' },
    { selector: '#sponsoredProducts2_feature_div', reason: 'Product page ad' },
    { selector: '#sims-themis-sponsored-products-2_feature_div', reason: 'Product page ad' },
    { selector: '#dp-ads-center-promo-dramabot_feature_div', reason: 'Product page ad' },
    { selector: '[data-cel-widget="dp-ads-center-promo_feature_div"]', reason: 'Product page ad' },
    { selector: '[data-cel-widget*="desktop-dp-atf_ad-placements"]', reason: 'Product page ad' },
    { selector: '[data-cel-widget="p13n-desktop-carousel_desktop-rhf_1"]', reason: 'Product page ad' },
    { selector: '#percolate-ui-ilm_div', reason: 'Product page ad' },
    { selector: '#rhf-shoveler', reason: 'Product page ad' },

    { selector: '.AdHolder', reason: 'Sponsored product block' },

    { selector: '[data-feature-name="sims-discoveryAndInspiration"]', reason: 'Brand promotion block' },
    { selector: '[data-feature-name="sims-simsContainer"]', reason: 'Brand promotion block' },
    { selector: '[data-feature-name="sims-productBundle"]', reason: 'Brand promotion block' },

    { selector: '[data-csa-c-owner="CustomerReviews"]', reason: 'AI review insights' },

    { selector: '[class*="spSponsored"]', reason: 'Tracking page ad', parent: '#recsWidget' },
    { selector: '[class*="dynamic-sponsored-behaviour-container"]', reason: 'Tracking page carousel ad', parent: '.a-carousel-container' },

    { selector: '[data-id*="AmazonLiveDram"]', reason: 'Amazon Live' },

    { selector: '[data-feature-name="desktop-dp-ilm"]', reason: 'Inspiration / ILM promo' },
];

const applyRule = rule => {
    document.querySelectorAll(rule.selector).forEach(el => {
        const target = rule.parent ? el.closest(rule.parent) : el;
        if (target) {
            log(rule.reason, target);
            target.remove();
            updateStats(rule.reason);
        }
    });
};

// ------------------------------------------------------------
// Mutation Observer
// ------------------------------------------------------------
new MutationObserver(() => {
    // Apply all rules
    RULES.forEach(applyRule);

    // Special case: search clutter
    document.querySelectorAll(        '#search .s-result-list.s-search-results > div:not([data-component-type="s-search-result"])'    ).forEach(el => {
        if (el.querySelector('.s-pagination-strip')) {
            return;
        }

        log('Search clutter', el);
        el.remove();
        updateStats('Search clutter');
    });
}).observe(document.body, { childList: true, subtree: true });

// Initialize everything else
registerMenu();
createStatsBox();
updateStatsVisibility();