Remove ads yandex mail

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

目前為 2025-01-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Remove ads yandex mail
// @version      0.5
// @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 = () => {
        // Ищем элементы с атрибутом data-key="view=*"
        let elements = document.querySelectorAll('[data-key^="view="]');
        if (elements.length) {
            elements.forEach((e) => {
                // Получаем dataset key
                let key = e.dataset['key'];
                // У элементов с рекламой после view= идут только английские буквы
                let matches = key.match(/^view=([a-z]+)$/);
                if (matches == null) {
                    return;
                }
                // Нужные элементы, их не надо удалять
                if (['notifications', 'labels', 'footer', 'app'].indexOf(matches[1]) !== -1) {
                    return;
                }

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

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

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

        // Удаляем кнопку отключения рекламы
        document.querySelectorAll('a[class*="DisableAdsButton"]').forEach((e) => {
            // Уже скрыто
            if (e.style.display === "none") {
                return;
            }

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

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

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

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