Greasy Fork

Greasy Fork is available in English.

Hide Ad Panel in Outlook.com

Hides the right sidebar with ads and stretches the e-mail body to take its place. Enable the beta version of Outlook!

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hide Ad Panel in Outlook.com
// @namespace    http://prantlf.tk/
// @version      0.2
// @description  Hides the right sidebar with ads and stretches the e-mail body to take its place. Enable the beta version of Outlook!
// @author       [email protected]
// @match        https://outlook.live.com/mail/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var observer;

    function removeAds(node) {
        console.log('[Hide Ad Panel in Hotmail] Hiding the ad panel.');
        var i = 3;
        while (i-- > 0) {
            node = node.parentElement;
            if (!node || node.tagName !== 'DIV') {
                console.log('[Hide Ad Panel in Hotmail] HTML structure does not match. Aborting.');
                observer.disconnect();
                return;
            }
        }
        node.style.display = 'none';
        observer.disconnect();
    }

    function checkNode(node) {
        var child;
        if (node instanceof HTMLElement && node.tagName === 'A' &&
            node.href === 'https://windows.microsoft.com/outlook/ad-free-outlook' &&
            node.parentElement && node.parentElement.tagName === 'SPAN') {
            removeAds(node.parentElement);
        }
    }

    function checkNodes(nodes) {
        var i, count, node, children, j, count2;
        if (nodes) {
            for (i = 0, count = nodes.length; i < count; ++i) {
                node = nodes[i];
                checkNode(node);
                if (node.querySelectorAll) {
                    children = node.querySelectorAll('a[target=_blank]');
                    for (j = 0, count2 = children.length; j < count2; ++j) {
                        checkNode(children[j]);
                    }
                }
            }
        }
    }

    observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            var addedNodes = mutation.addedNodes,
                target = mutation.target;
            checkNodes(addedNodes);
            if (target) {
                checkNode(target);
            }
        });
    });

    var nodes = document;
    checkNodes(nodes);

    console.info('[Hide Ad Panel in Hotmail] Listenning to page changes.');
    observer.observe(document.body, {
        childList: true,
        subtree: true,
        attributes: false,
        characterData: false
    });
})();