Optimize work experience at Microsoft

Optimize work experience at Microsoft!

// ==UserScript==
// @name         Optimize work experience at Microsoft
// @namespace    https://www.microsoft.com/
// @version      1.0.0
// @description  Optimize work experience at Microsoft!
// @author       Guosen Wang
// @match        https://ms.portal.azure.com/*
// @match        https://*.visualstudio.com/*
// @match        https://m365pulse.microsoft.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==
(function () {
  'use strict';
  const host = location.host;

  switch (true) {
    case 'ms.portal.azure.com' === host:
      azure();
      break;
    case 'm365pulse.microsoft.com' === host:
      m365pulse();
      break;
    case ["developercommunity", "vssps"].indexOf(host.match(/([^\.]+).visualstudio.com/)[1].toLowerCase()) == -1:
      vsts();
      break;
  }
})();

function azure() {
  let checkExist = setInterval(function () {
    const selector = '#_weave_e_6';
    if (document.querySelector(selector)) {
      document.querySelector(selector).remove();
      const bannerLabel = document.querySelector("#_weave_e_5 > div.fxs-topbar-internal.fxs-internal-full");
      bannerLabel.innerText = bannerLabel.innerText.replace(" (Preview)", "");
      clearInterval(checkExist);
    }
  }, 100);
  setTimeout(() => {
    clearInterval(checkExist);
  }, 5000);
}

// Redirect VSTS to DevOps
function vsts() {
  let url = location.href.replace(/(\w+)\.visualstudio.com(\/DefaultCollection)?/, 'dev.azure.com/$1');
  location.replace(url);
}

function m365pulse() {
  // Remove the "New Version" link
  let checkExist_NewVersionLink = setInterval(function () {
    const newVersionLink = document.querySelector('a.right:nth-child(1)');
    if (newVersionLink) {
      if (newVersionLink.innerText === 'New Version') {
        newVersionLink.remove();
      }
      clearInterval(checkExist_NewVersionLink);
    }
  }, 100);
  setTimeout(() => {
    clearInterval(checkExist_NewVersionLink);
  }, 5000);

  // Remove feedback widget
  let checkExist_FeedbackWidget = setInterval(function () {
    const feedbackWidget = document.querySelector('div[class^="feedback-"]');
    if (feedbackWidget) {
      feedbackWidget.parentElement.remove();
      clearInterval(checkExist_FeedbackWidget);
    }
  }, 100);
  setTimeout(() => {
    clearInterval(checkExist_FeedbackWidget);
  }, 10000);
}