Outlook Hotmail cleanup

Remove ads on Outlook Hotmail

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name Outlook Hotmail cleanup
// @version 1.5.0
// @grant none
// @include https://outlook.live.com/mail/*
// @license MIT
// @namespace https://greasyfork.org/en/users/759669-sly-north
// @description Remove ads on Outlook Hotmail
// ==/UserScript==

function unscale(p) {
  if (p && p.style.transform) {
    p.style.transform = 'scale(1)';
    p.style.width = "100%";
    p.style.height = "100%";
  }
}

let smallAdsDiv = null;

function RemoveAds() {
  // Small ads above list of messages
  if (!smallAdsDiv) {
    var smallDivs = Array.from(document.getElementsByTagName('div')).filter(e => e.clientWidth > 340 && e.clientWidth < 370 && e.clientHeight > 70 && e.clientHeight < 85);
    if (smallDivs.length > 0) {
      const e = smallDivs[0];
      // Check it's not a valid email.
      const text = e.innerText;
      if (text.search('@') < 0 && !text.search(/\/202/) && !text.match(/\d\/\d/) && text.search(' AM') < 0 && text.search(' PM') < 0) {
        smallAdsDiv = e;
        console.log('- OutlookCleanup: found small ads div: ', e.innerText);
      }
    }
  }
  if (smallAdsDiv && smallAdsDiv.style.zIndex >= 0) {
    console.log('- OutlookCleanup: remove small div: ', smallAdsDiv.innerText);
    smallAdsDiv.style.maxHeight = '0px';
    smallAdsDiv.style.zIndex = -100;
  }

  // Right most vertical ads.
  let main = document.getElementById('MainModule');
  if (main) {
    while (main.childElementCount == 1) main = main.firstChild;
    if (main.childElementCount > 3) {
      let e = main.children[main.childElementCount - 1];
      if (e.getBoundingClientRect().width < 200) {
        // console.log('OutlookCleanup: remove right vertical ad space');
        e.style.zIndex = -100;
        e.style.position = 'fixed';
      }
    }
  }
  for (let e of Array.from(document.getElementsByTagName('button')).filter(e => e.innerText.search('Microsoft 365') > 0)) {
    if (e.done) continue;
    e.done = true;
    e.style.zIndex = -100;
    e.style.position = 'fixed';
    console.log('- OutlookCleanup: remove 365 ads: ', e.innerText);
  }
}

function doAll() {
  RemoveAds();

  // Left icons
  const leftBar = document.getElementById('LeftRail');
  if(leftBar) leftBar.style.zoom = 0.5;
 
  // Less large folder area
  const folderPane = document.querySelector('[aria-label="Navigation pane"]');
  if (folderPane) folderPane.style.width = "12vw";
  const folderContainer = document.getElementById('folderPaneDroppableContainer');
  if (folderContainer) folderContainer.style.padding

  // Make messages not so small
  for (let e of document.getElementsByClassName('wide-content-host')) {
    unscale(e.parentElement);
  }
  unscale(document.getElementById('docking_InitVisiblePart_0'));
  unscale(document.getElementById('docking_InitVisiblePart_1'));

  setTimeout(doAll, 1000);
}

setTimeout(doAll, 3000);