Optimize work experience at Microsoft

Optimize work experience at Microsoft!

Από την 15/09/2025. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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://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;
  }
})();

/**
 * General DOM handling function
 * @param {Array} targets - Array of targets to process, each object can include:
 *   - selector: CSS selector
 *   - remove: whether to remove the element
 *   - removeParent: whether to remove the parent element
 *   - text: text to match
 *   - modifyText: function to modify the element's text
 * @param {number} timeout - timeout in milliseconds (optional, default 10000)
 */
function handleDOMTargets(targets, timeout = 10000) {
  const processed = Array(targets.length).fill(false);
  let observer = null;

  function checkAndProcess() {
    targets.forEach((target, index) => {
      if (processed[index]) return;

      const element = document.querySelector(target.selector);
      if (!element) return;

      // Check text match if specified
      if (target.text && element.innerText !== target.text) return;

      // Remove element or parent element
      if (target.removeParent && element.parentElement) {
        element.parentElement.remove();
      } else if (target.remove) {
        element.remove();
      }

      // Modify text if modifyText function is provided
      if (target.modifyText) {
        element.innerText = target.modifyText(element.innerText);
      }

      processed[index] = true;
    });

    // Disconnect observer if all targets have been processed
    if (processed.every(Boolean) && observer) {
      observer.disconnect();
      observer = null;
      clearTimeout(timeoutId);
    }
  }

  // Run initial check immediately
  checkAndProcess();

  // If there are unprocessed targets, create an observer
  if (!processed.every(Boolean)) {
    observer = new MutationObserver(checkAndProcess);
    observer.observe(document.body, { childList: true, subtree: true });

    // Timeout protection
    const timeoutId = setTimeout(() => {
      if (observer) {
        observer.disconnect();
        observer = null;
      }
    }, timeout);
  }
}

function m365pulse() {
  handleDOMTargets([
    { selector: 'a.right:nth-child(1)', text: 'New Version', remove: true },
    { selector: 'div[class^="feedback-"]', removeParent: true }
  ], 10000);
}

function azure() {
  handleDOMTargets([
    { selector: '#_weave_e_6', remove: true },
    {
      selector: '#_weave_e_5 > div.fxs-topbar-internal.fxs-internal-full',
      modifyText: text => text.replace(' (Preview)', '')
    }
  ], 5000);
}