jadyboy / Amazon AdFree

// ==UserScript==
// @name          Amazon AdFree
// @author        jadyboy
// @description   Use this script for a completely Ad-free, Sponsored-products-free Amazon. 
// @version       2018.06.14
// @icon          data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAActpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx4bXA6Q3JlYXRvclRvb2w+QWRvYmUgSW1hZ2VSZWFkeTwveG1wOkNyZWF0b3JUb29sPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KKS7NPQAACcRJREFUaAXdmWuMXVUVx/c+9z20tIMtA5RCK1DkGbAPStQ+TFMNUg0SoGjkg22pRmP0gyaGGAcT9ZNRqtFMO05IJArUR2IVQ0zaGBqSmoImTRFRoIZS2kHaYjv3ztzH2f5/5941Pb3eO51Opxhdyf/s19rrtdd+3Bnn/sfJT7P9yIsEyrTsoHYsUIJpo7SSqQrFYIBhjUkIybZ4zaFJTOnOci4OWKTbjb5I6sBMAWNrwnHhTWFEMEI3M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853JzYMJS/XZMp+pcOwnFvVTLHY949v6mTcPke/n7+pWPCrZNidkXcri72+4KrBVU66n5Si6hf9xqaDspN/qNR7NlVvY64nRbxP0sGFQXdROS58q5QPm/1M7fSjgTfOTnHs9sH/KY6il3pmlo+kVwchZ0uk5/G3ivOlZ1EIYXkjDquiyN9cKugvGEWFrhbc6Ijbr9x8uGdjdbvJ18rcWg/+qYaLPjlz0+hO9qy4kxTxz2112SWbkw3pqkO599Zj/2UdYevzc8SirVo5FmKt1wH5qvSI/i6lB9R+XXzDvhEfrzl/suGjsWzwNR11YawesqViyDUa8YzIZ2aHEPdpt8xXSl3tXbxIsbtaqi8v8Yoi+RR2Ij465l6S4T8uNaoDfnPys9QFDJVtiV0Nf42i/wT7QbOaHyqQdj55Or7M5YHcbRL+KbHdVbrAXebymsPBqgTlzKkJ9Ybj/NbBFka1UlWtJacPJFlBM3xR3D3ZjMvlkG5bVJ2mvVLRfgtujxz8WRxlt8/YNMJtnBjuHuTS0jZMZ8op4zlATqfEswGXxWMbqfyouMBnG2u1BHeob1kmcpfmuQ1sNsYYTVRv8ccKQrXmKmL9q0zb5TOZHcWR0Wf9F5JDIDkB3QsKR/94MEw6QY5cf/Pko9NMGGewSsK4Ugu7+nQhlW3FhcHHSxSxpZp8QxzcAgVojtTxli8oWsq8JmkMqil6FfWznw5htFbleRfHe0qutk+BGv8dIb7IPSydHQxPJHX4mK4OQ82uxJHr5egL8rrDCXJUl0xPpjA39o25Ic70ypkeGZvXjonlSSV20YlG1HjL13PDPb3l4fYDgNRw21uJda/SV5nT1ZhzGZBU36/la73Hs5RTkYfBCkoyn+AkDkxFUGvOGVdgItnj0VO+6j8GXWVxcC/u1fbvsooT6fi/H/s3V5a/unurQvIAAAAASUVORK5CYII=
// @supportURL    https://www.reddit.com/user/jadyboy
// @updateURL     https://openuserjs.org/meta/jadyboy/Amazon_AdFree.meta.js
// @downloadURL   https://openuserjs.org/src/scripts/jadyboy/Amazon_AdFree.user.js
// @license       GPL-3.0
// @include       https://*.amazon.com/*
// @include       https://*.amazon.in/*
// @include       https://*.amazon.co.uk/*
// @include       https://*.amazon.co.jp/*
// @include       https://*.amazon.fr/*
// @include       https://*.amazon.de/*
// @include       https://*.amazon.it/*
// @include       https://*.amazon.es/*
// @include       https://*.amazon.com.mx/*
// @run-at        document-end
// @version       1.1
// ==/UserScript==

var hideAds = function() {
    var count = 0;

    document.querySelectorAll('.s-sponsored-info-icon').forEach(function(el){
        var product = el.closest('.s-result-item');
        if(product!==undefined && product!==null){
            product.style.display = "none";
            count++;
            return;
        }

        var adsBox = el.closest('.a-box');
        if(adsBox!==undefined && adsBox!==null){
            adsBox.style.display = "none";
            count++;
            return;
        }
    });

    document.querySelectorAll('#pdagEncapsulated').forEach( function(el) {
        el.style.display = "none";
        count++;
    });

    document.querySelectorAll('.display-dashboard-ad').forEach( function(el) {
        el.style.display = "none";
        count++;
    });

    document.querySelectorAll('.displayAd').forEach( function(el) {
        el.style.display = "none";
        count++;
    });

    document.querySelectorAll('#desktop-unrec-ad').forEach( function(el) {
        el.style.display = "none";
        count++;
    });
    
    document.querySelectorAll('#centerBelowExtraSponsoredLinks').forEach( function(el) {
        el.style.display = "none";
        count++;
    });

    if (count>0)
        console.log('Amazon AdFree has successfully hidden ' + count + ' ads.');
};

hideAds();

if(document.querySelector('#rightResultsATF')) {
    var observer = new MutationObserver(hideAds);
    observer.observe(document.querySelector('#rightResultsATF'),
                     {subtree: true,
                      childList: true,
                      attributes: false});
}