outlook邮箱广告去除

去除Outlook邮箱所有广告

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         cleanLiveMailAds
// @name:zh-CN   outlook邮箱广告去除
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Remove all ads from Outlook webmail
// @description:zh-CN  去除Outlook邮箱所有广告
// @author       lainsato
// @match        https://outlook.live.com/*
// @icon         https://www.google.com/s2/favicons?domain=live.com
// @grant        none
// @run-at       document-body
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';

    var css = `.GssDD { display: none !important; }`;
    var style = document.createElement('style');
    style.innerText = css;
    document.body.appendChild(style);

    function removeAds() {
        // 移除包含禁止按钮的广告项
        var adButtons = document.querySelectorAll('button[aria-label*="禁止"]');
        adButtons.forEach(function(btn) {
            var adContainer = btn.closest('div[class*="agCiB"]');
            if (adContainer) {
                var parent = adContainer.closest('div[class*="dqDQ"]');
                if (parent) {
                    parent.style.display = 'none';
                }
            }
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(removeAds, 500);
        });
    } else {
        setTimeout(removeAds, 500);
    }

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

    setInterval(removeAds, 2000);
})();