Avito filter

Hide aliexpress like shit

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==
// @license MIT
// @name         Avito filter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Hide aliexpress like shit
// @author       penisai
// @match        https://www.avito.ru/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';


    const BADGE_EXACT = [
        'Из-за рубежа',
    ];


    const KEYWORDS_ANYWHERE = [
        'Китайская лавка',
        'Дао-покупао',
        'Китайская грамота',
    ];

    // -------------------------

    const CARD_SELECTOR = 'div[data-marker="item"], div[class*="iva-item-root"], div[class*="item-root"], div[class*="snippet"], li[class*="item"]';

    function hideCard(el) {

        const card = el.closest('[data-marker="item"]') || el.closest(CARD_SELECTOR);
        if (card) {
            card.style.setProperty('display', 'none', 'important');
        } else {
            let parent = el;
            for (let i = 0; i < 5; i++) {
                if (parent.parentElement) parent = parent.parentElement;
            }
            parent.style.setProperty('display', 'none', 'important');
        }
    }

    function hideBlocks() {
        const leafNodes = document.querySelectorAll('span, div, p, a');

        for (const el of leafNodes) {
            if (el.childElementCount !== 0) continue;

            const text = el.textContent.trim();


            if (BADGE_EXACT.includes(text)) {
                hideCard(el);
                continue;
            }


            const card = el.closest(CARD_SELECTOR);
            if (card && !card._avito_checked) {
                const cardText = card.textContent;
                for (const kw of KEYWORDS_ANYWHERE) {
                    if (cardText.includes(kw)) {
                        card.style.setProperty('display', 'none', 'important');
                        break;
                    }
                }
                card._avito_checked = true;
            }
        }
    }

    hideBlocks();

    const observer = new MutationObserver(hideBlocks);
    observer.observe(document.body, { childList: true, subtree: true });

})();