Hide Outlook Ads

Hide mailing list, sidebar ads

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name             Hide Outlook Ads
// @name:CN          隐藏 Outlook 广告
// @namespace        https://ivanli.cc/
// @version          0.1.0
// @description      Hide mailing list, sidebar ads
// @description:CN   隐藏邮件列表、侧边栏广告
// @author           Ivan Li
// @match            https://outlook.live.com/mail/*
// @icon             https://www.google.com/s2/favicons?sz=64&domain=live.com
// @grant            none
// @run-at           document-body
// @license          MIT
// ==/UserScript==

(function() {
    'use strict';

    // outlook

    if (location.href.includes('outlook')) {
        setInterval(() => {
            const listAdItems = Array.from(document.querySelectorAll('[role=listbox] [id]')).filter(el => /\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/.test(el.id));
            listAdItems.map(el => {el.style.display='none'});
            const rightAd = Array.from(document.querySelectorAll('[role="region"][data-app-section="NavigationPane"]~div')).reverse()[0];
            if (rightAd) {
                rightAd.style.display = 'none';
            }
            const premiumAds = Array.from(document.querySelectorAll('[role="region"][data-app-section="NavigationPane"] [data-focuszone-id]+div'));
            premiumAds.map(el => {el.style.display='none'});
        }, 1000);
    }
})();