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!

目前為 2017-11-04 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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
    });
})();