Created
April 28, 2021 22:48
-
-
Save Snarp/52e9fb393741a23e7be7a15645de260d to your computer and use it in GitHub Desktop.
Etsy.com - Mute Deceptive Search Result Ads: Hides the difficult-to-identify ads in Etsy 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 Etsy.com - Mute Deceptive Search Result Ads | |
// @author snarp | |
// @version 0.3 | |
// @description Hides the difficult-to-identify ads in Etsy search results. | |
// @run-at document-idle | |
// @include https://www.etsy.com/*/search?q=* | |
// @include https://www.etsy.com/search?q=* | |
// @grant none | |
// @icon https://www.etsy.com/images/favicon.ico | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// By default, turns ads down to 10% opacity. | |
// To entirely remove them, uncomment the `ad.remove();` line. | |
function muteItem(item) { | |
item.style.opacity = 0.1; | |
// item.remove(); | |
} | |
// As of 2021-04-28, all legitimate Etsy search result links contain the | |
// CSS class 'organic-impression'. | |
function muteAllAds() { | |
var listings = document.querySelectorAll('div[data-search-results-region] ul li'); | |
for (const listing of listings) { | |
let link = listing.querySelector('a[data-listing-id]'); | |
if (!link.classList.contains('organic-impression')) { | |
muteItem(listing); | |
} | |
} | |
document.removeEventListener('scroll', muteAllAds, true); | |
} | |
muteAllAds(); | |
// And in case it doesn't fire successfully on idle: | |
document.addEventListener('scroll', muteAllAds, true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment