Optimize work experience at Microsoft

Optimize work experience at Microsoft!

目前為 2023-03-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Optimize work experience at Microsoft
// @namespace    https://001.io/
// @version      1.0
// @description  Optimize work experience at Microsoft!
// @author       Guosen Wang
// @match        https://ms.portal.azure.com/*
// @match        https://*.visualstudio.com/*
// @match        https://portal.microsofticm.com/imp/v3/incidents/details/*
// @match        https://eng.ms/docs/*
// @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 'portal.microsofticm.com' === host:
            icm();
            break;
        case 'eng.ms' === host:
            eng_ms();
            break;
        case ["1essharedassets", "o365exchange", "supportability", "ceacc", "devdiv", "domoreexp", "imsandbox", "microsoft", "msazure", "msblox", "mscosmos", "msdata", "mseng", "office", "onebranch", "onedrive", "ossmsft", "powerbi"].indexOf(host.match(/([^\.]+).visualstudio.com/)[1].toLowerCase()) !== -1:
            vsts();
            break;
    }
})();

function azure() {
    let checkExist = setInterval(function () {
        if (document.querySelector('#_weave_e_5')) {
            document.querySelector('#_weave_e_5').remove();
            const bannerLabel = document.querySelector("#_weave_e_4 > 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);
}

// Optimize ICM fullscreen experience
function icm() {
    window.onload = () => {
        const style = document.createElement('style');
        style.innerText = '.widget.full-frame{padding:25px 25% 0;}.in.collapse::-webkit-scrollbar{display:none;}.widget.full-frame>header{padding-left:0;}';
        document.querySelector('head').appendChild(style);

        const body = document.querySelector('body');
        body.addEventListener('keydown', e => {
            if (e.ctrlKey || e.altKey || e.shiftKey) {
                return;
            }
            if (e.key == 'f') {
                const enterFullScreenBtn = document.querySelector('body > div:nth-child(1) > main > div > ui-view > div > div > div.maintabs-tabset > div > div.tab-pane.active > div > detail-view > div > div.col-12.col-sm-8 > widget-panel > div > section:nth-child(1) > header > button:nth-child(4)');
                if (enterFullScreenBtn) {
                    enterFullScreenBtn.click();
                }
            } else if (e.key == "Escape") {
                const exitFullScreenBtn = document.querySelector('body > div:nth-child(1) > main > div > ui-view > div > div > div.maintabs-tabset > div > div.tab-pane.active > div > detail-view > div > div.col-12.col-sm-8 > widget-panel > div > section.widget.full.full-frame.non-draggable > header > button:nth-child(4)');
                if (exitFullScreenBtn) {
                    exitFullScreenBtn.click();
                }
            }
        });
    };
}

function eng_ms() {
    let checkExist = setInterval(
        function () {
            if (document.querySelector("#mainContent > style")) {
                document.querySelector("#mainContent > style").innerHTML = document.querySelector("#mainContent > style").innerHTML.replace(".docfx-container pre{", ".docfx-container pre{line-height:0;");
                clearInterval(checkExist);
            }
        },
        100);
    setTimeout(() => {
        clearInterval(checkExist);
    }, 5000);
}