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!

  1. // ==UserScript==
  2. // @name Hide Ad Panel in Outlook.com
  3. // @namespace http://prantlf.tk/
  4. // @version 0.2
  5. // @description Hides the right sidebar with ads and stretches the e-mail body to take its place. Enable the beta version of Outlook!
  6. // @author prantlf@gmail.com
  7. // @match https://outlook.live.com/mail/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. var observer;
  15.  
  16. function removeAds(node) {
  17. console.log('[Hide Ad Panel in Hotmail] Hiding the ad panel.');
  18. var i = 3;
  19. while (i-- > 0) {
  20. node = node.parentElement;
  21. if (!node || node.tagName !== 'DIV') {
  22. console.log('[Hide Ad Panel in Hotmail] HTML structure does not match. Aborting.');
  23. observer.disconnect();
  24. return;
  25. }
  26. }
  27. node.style.display = 'none';
  28. observer.disconnect();
  29. }
  30.  
  31. function checkNode(node) {
  32. var child;
  33. if (node instanceof HTMLElement && node.tagName === 'A' &&
  34. node.href === 'https://windows.microsoft.com/outlook/ad-free-outlook' &&
  35. node.parentElement && node.parentElement.tagName === 'SPAN') {
  36. removeAds(node.parentElement);
  37. }
  38. }
  39.  
  40. function checkNodes(nodes) {
  41. var i, count, node, children, j, count2;
  42. if (nodes) {
  43. for (i = 0, count = nodes.length; i < count; ++i) {
  44. node = nodes[i];
  45. checkNode(node);
  46. if (node.querySelectorAll) {
  47. children = node.querySelectorAll('a[target=_blank]');
  48. for (j = 0, count2 = children.length; j < count2; ++j) {
  49. checkNode(children[j]);
  50. }
  51. }
  52. }
  53. }
  54. }
  55.  
  56. observer = new MutationObserver(function(mutations) {
  57. mutations.forEach(function(mutation) {
  58. var addedNodes = mutation.addedNodes,
  59. target = mutation.target;
  60. checkNodes(addedNodes);
  61. if (target) {
  62. checkNode(target);
  63. }
  64. });
  65. });
  66.  
  67. var nodes = document;
  68. checkNodes(nodes);
  69.  
  70. console.info('[Hide Ad Panel in Hotmail] Listenning to page changes.');
  71. observer.observe(document.body, {
  72. childList: true,
  73. subtree: true,
  74. attributes: false,
  75. characterData: false
  76. });
  77. })();