Skip to content

Instantly share code, notes, and snippets.

@Seroczynski
Last active March 20, 2026 09:46
Show Gist options
  • Select an option

  • Save Seroczynski/73d594b60cd272017f7718e1202882dc to your computer and use it in GitHub Desktop.

Select an option

Save Seroczynski/73d594b60cd272017f7718e1202882dc to your computer and use it in GitHub Desktop.
TamperMonkey - Marktplaats Consumer Only
// ==UserScript==
// @name Marktplaats Consumer Only
// @version 0.4
// @description Remove any business ad on Marktplaats and 2dehands.be
// @author Christiaan Seehöfer
// @match https://www.marktplaats.nl/*
// @match https://www.2dehands.be/*
// @grant none
// ==/UserScript==
(function() {
"use strict";
const bannerSpaces = [
"#top-banner-wrapper",
"#top-banner-root",
"#right-banner-root",
"#bottom-banner-root",
"#adsense-container",
".AdsenseForShopping-root",
".AdmarktSimilarItems-root",
".mp-Banner",
".Banners-bannerFeedItem",
".hz-Banner--inline-gv",
".hz-Banner--sticky-left",
".hz-Banner--fluid",
".dataDrivenContent",
".faqFooter",
".u-resetFooter",
".hz-SuggestedSearches",
".hz-H1Title",
".hz-Listings__container--casGallery",
".FooterLinkWrapper-listContainer",
];
let debounceTimer;
const processedElements = new WeakSet();
function hideNoneConsumerAdsFrontPage(element) {
if (processedElements.has(element)) return;
processedElements.add(element);
try {
const href = element.getAttribute("href");
if (!href || href.charAt(1) !== "v") return;
const consumerCheck = href.match(/[m]\d{10}/);
if (consumerCheck === null) {
const targetElement = (window.location.pathname === "/" || window.location.pathname === "")
? element.parentElement
: element.parentElement?.parentElement;
if (targetElement) {
targetElement.style.display = 'none';
}
}
} catch(error) {
console.error("Error in hideNoneConsumerAdsFrontPage:", error);
}
}
function hideNonConsumerAds(element) {
if (processedElements.has(element)) return;
processedElements.add(element);
if (element.parentElement) {
element.parentElement.style.display = 'none';
}
}
function hideBannerSpaces(element) {
if (processedElements.has(element)) return;
processedElements.add(element);
element.style.display = 'none';
}
function processExistingElements() {
// Front page listings
document.querySelectorAll(".hz-StructuredListing > .hz-Link--block").forEach(hideNoneConsumerAdsFrontPage);
// Category listings
document.querySelectorAll("[data-tracking]").forEach(hideNonConsumerAds);
// Bottom "Admarkt" section
document.querySelectorAll(".mp-Listings__admarktTitle").forEach(hideNonConsumerAds);
// Banner spaces
bannerSpaces.forEach(selector => {
document.querySelectorAll(selector).forEach(hideBannerSpaces);
});
}
function debouncedProcess() {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(processExistingElements, 50);
}
// Initial cleanup
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', processExistingElements);
} else {
processExistingElements();
}
// Watch for dynamic content
const observer = new MutationObserver((mutations) => {
let shouldProcess = false;
for (const mutation of mutations) {
if (mutation.addedNodes.length > 0) {
shouldProcess = true;
break;
}
}
if (shouldProcess) {
debouncedProcess();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Fallback check every 2 seconds (lightweight)
setInterval(processExistingElements, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment