Hide Outlook Ads

Hide mailing list, sidebar ads

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             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);
    }
})();