Avito filter

Hide aliexpress like shit

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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 });

})();