Unsplash Remove Ads

Unsplash Ads

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         Unsplash Remove Ads
// @namespace    https://www.iplaysoft.com
// @description  Unsplash Ads
// @version      0.33
// @author       X
// @match        https://unsplash.com/*
// @require      https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js
// @icon         https://www.google.com/s2/favicons?sz=64&domain=unsplash.com
// @grant        GM_addStyle
// ==/UserScript==

/* globals $ */

function removeAdsBlock(){
    $($("div[data-test*='AffiliatesGrid-Content']").get(0)).parent().hide();
    //$($("div[data-test*='AffiliatesGrid-Content']").get(0)).parent().parent().hide();
}

function removeAdsInsideList(targetDiv){

    removeAdsBlock();

    if(targetDiv.nodeName=="DIV" ||targetDiv.nodeName=="div"){
        var fig=$(targetDiv).find("figure[itemprop*='image']");

        if(fig.length>0){
            //console.log($(fig).find("a:contains('Unlock')").length);

            //console.log(fig[i]);
            //var ads=$(fig.get()).find("div:contains('Unsplash+')");
            var ads=$(fig.get()).find("a:contains('Unlock')");
            if(ads.length>0){
                // console.log(ads);
                $(ads.get()).parentsUntil("figure").hide();
                //console.log(ads.get());
            }
            //}
            //console.log($(fig).find("a"));
            //var ads=$(fig).find("img");
            //var ads=$(fig.get()).find("div:textEquals('Unsplash+')")
            //var ads=$(fig.get()).find("div:textEquals('Unsplash\+')")
            //if(ads.length>0){
            // console.log(ads);
            //}
        }

        var data_ad=$(targetDiv).find("div[data-ad*='true']");
        if(data_ad.length>0){
            $(data_ad.get()).hide()
            //console.log(data_ad.get());
        }
    }
}

function scrollRemoveAds(){
    var targetDiv=$("div[data-test*='masonry-grid-count-three']").parent().get(0);
    removeAdsInsideList(targetDiv);
}


(function() {
    'use strict';
    $(document).ready(function(){

        removeAdsBlock();

        $("div[data-test*='masonry-grid-count-three']").parent().on('DOMSubtreeModified', function(e) {
           removeAdsInsideList(e.target);
        });

        $(window).scroll(function(){
            scrollRemoveAds();
        });

    });
})();