Remove ads yandex mail

Удаляет рекламу из почты yandex

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==
// @name         Remove ads yandex mail
// @version      0.7
// @description  Удаляет рекламу из почты yandex
// @author       BaHeK
// @match        http*://mail.yandex.ru/*
// @grant        none
// @downloadUrl  https://github.com/BaHeK1994/remove-ads-yandex-mail/raw/main/script.user.js
// @updateUrl    https://github.com/BaHeK1994/remove-ads-yandex-mail/raw/main/script.user.js
// @namespace https://greasyfork.org/users/791055
// ==/UserScript==

(function() {
    'use strict';

    let observer = null;

    // Отслеживаем изменения HTML через observer
    let startObserver = () => {
        observer = new MutationObserver(() => {
            remove();
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true,
            attributes: true
        });
    };

    let remove = () => {
        // Ищем div с class="DirectLine"
        document.querySelectorAll('div[class="DirectLine"]').forEach((e) => {
            let banner = e;

            // Уже скрыто
            if (banner.style.display === "none") {
                return;
            }

            // Отключаем листенер изменения DOM, иначе будет рекурсия
            if (observer !== null) {
                observer.disconnect();
                observer = null;
            }

            // Скрываем элемент рекламы
            banner.style.display = 'none';
        });

        // Скрываем родительский элемент .BannersBlock
        document.querySelectorAll('.BannersBlock').forEach((e) => {
            let parent = e.parentElement;

            // Уже скрыто
            if (parent.style.display === "none") {
                return;
            }

            // Отключаем листенер изменения DOM, иначе будет рекурсия
            if (observer !== null) {
                observer.disconnect();
                observer = null;
            }

            // Скрываем
            parent.style.display = 'none';
        });

        // Запускаем observer
        if (observer === null) {
            startObserver();
        }
    };

    // Моментально скрываем рекламу, не дожидаясь изменений на странице
    remove();
})();