Hide OLX Promoted Ads

It hides all promoted ads on OLX

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Hide OLX Promoted Ads
// @name:ro      Ascunde Anunțuri De Tip PROMOVAT Pe OLX
// @name:bg      Скриване На Реклами Тип ПРОМОТИРАНА ОБЯВА На OLX
// @name:ua      Приховати Оголошення Типу ТОП На OLX
// @name:pt      Ocultar Anúncios Do Tipo TOP No OLX
// @name:pl      Ukryj Ogłoszenia Typu WYRÓŻNIONE Na OLX
// @description  It hides all promoted ads on OLX
// @description:ro Ascunde toate anunțurile de tip PROMOVAT de pe OLX
// @description:bg Скрива всички реклами тип ПРОМОТИРАНА ОБЯВА на OLX
// @description:ua Сховує всі оголошення типу ТОП на OLX
// @description:pt Oculta todos os anúncios do tipo TOP no OLX
// @description:pl Ukrywa wszystkie ogłoszenia typu WYRÓŻNIONE na OLX
// @author       NWP
// @namespace    https://greasyfork.org/users/877912
// @version      0.3
// @license      MIT
// @match        *://www.olx.ro/*
// @match        *://www.olx.bg/*
// @match        *://www.olx.ua/*
// @match        *://www.olx.pt/*
// @match        *://www.olx.pl/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  const DEBUG = false;

  const PROMO_LABELS = {
    'olx.ro': ['PROMOVAT'],
    'olx.bg': ['ПРОМОТИРАНА ОБЯВА'],
    'olx.ua': ['ТОП'],
    'olx.pt': ['TOP'],
    'olx.pl': ['WYRÓŻNIONE']
  };

  const hostKey = window.location.hostname.replace(/^www\./, '');
  const keywords = PROMO_LABELS[hostKey] || Object.values(PROMO_LABELS).flat();

  let totalHidden = 0;
  let lastHideTime = Date.now();

  function hidePromotedElements() {
    const now = Date.now();
    if (DEBUG) console.log(`[DEBUG ${new Date().toISOString()}] hidePromotedElements() called`);

    const beforeCount = totalHidden;

    document.querySelectorAll('[data-cy="l-card"]').forEach(card => {
      const badge = card.querySelector('div.css-144z9p2');
      if (!badge) return;

      const label = badge.textContent.trim().toUpperCase();
      if (keywords.includes(label) && card.style.display !== 'none') {
        card.style.display = 'none';
        totalHidden++;
        if (DEBUG) {
          const id = card.id || card.getAttribute('data-id') || '(no-id)';
          console.log(
            `[DEBUG ${new Date().toISOString()}] ➔ Hiding card ${id} (“${label}”). Total hidden: ${totalHidden}`
          );
        }
      }
    });

    if (DEBUG && totalHidden > beforeCount) {
      const delta = now - lastHideTime;
      console.log(
        `[DEBUG ${new Date().toISOString()}] hid ${totalHidden - beforeCount}` +
        ` new card(s) — cumulative ${totalHidden}` +
        ` (Δ ${delta} ms since last hide)`
      );
      lastHideTime = now;
    }
  }

  if (DEBUG) console.log(`[DEBUG ${new Date().toISOString()}] Initial hide run`);
  hidePromotedElements();

  new MutationObserver(hidePromotedElements)
    .observe(document.body, { childList: true, subtree: true });

  setInterval(hidePromotedElements, 2000);

})();