Outlook live ad-remover

Remove ad's from mirosofts web mail services

  1. // ==UserScript==
  2. // @name Outlook live ad-remover
  3. // @namespace http://monkeyr.com/
  4. // @version 1.6.1
  5. // @description Remove ad's from mirosofts web mail services
  6. // @author mh
  7. // @license MIT
  8. // @match https://outlook.live.com/owa/*
  9. // @match https://outlook.live.com/mail/*
  10. // @icon https://outlook.live.com/favicon.ico
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  15. let adPanel = false;
  16. let o365Button = false;
  17. let emailAd = false;
  18. let emailAdSeenEles = [];
  19. if (MutationObserver) console.log('Outlook live ad-remover is enabled.');
  20. window.addEventListener('resize', function() {adPanel = false; o365Button = false; emailAd = false; console.log('resize event')});
  21. const observer = new MutationObserver(MutationRecords => {
  22. MutationRecords.forEach(function(MutationRecord){
  23. let msFZs = {};
  24. let emailAdEles;
  25. let target = MutationRecord.target;
  26. // Find and remove the right/lower ad panel
  27. if(!adPanel && target.querySelectorAll('[aria-label="advertisement"]').length && target.tagName === 'DIV'){
  28. target.remove();
  29. //adPanel = true;
  30. console.log('adPanel removal', target, parent);
  31. }
  32. // find and remove the upgrade to o365 button
  33. else if(!o365Button && (msFZs = target.querySelectorAll('.ms-FocusZone')) && msFZs.length){
  34. msFZs.forEach(msFZ => {
  35. let nextSibling = msFZ.nextSibling;
  36. if(nextSibling && nextSibling.firstChild && nextSibling.firstChild.tagName == 'BUTTON' ){
  37. nextSibling.remove();
  38. o365Button = true;
  39. console.log('o365Button removal', target, MutationRecord, nextSibling, nextSibling.childElementCount);
  40. return false;
  41. }
  42. });
  43. }
  44. // hide the ad from the top of the inbox, removing it will sometimes crash the outlook "app"
  45. if(!emailAd && (emailAdEles = target.querySelectorAll('[role="listbox"] .customScrollBar > div > div')) && emailAdEles.length && target.tagName === 'DIV'){
  46. emailAdEles.forEach(ele => {
  47. if(!ele.querySelector('[draggable]')){
  48. if(ele.style.display != 'none'){
  49. ele.style.display = 'none';
  50. console.log('owaContainer removal', ele);
  51. //emailAd = true;
  52. }
  53. return false;
  54. }
  55. //console.log(itm, itm.querySelector('[draggable]'))
  56. });
  57. }
  58. });
  59. //console.log(MutationRecords);
  60. });
  61. observer.observe(document.body, {childList: true, subtree: true});