ADO Build & Deploy - Viewer+

Rework HTML of build view in Azure DevOps

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ADO Build & Deploy - Viewer+
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Rework HTML of build view in Azure DevOps
// @author       You
// @match        https://*.visualstudio.com/*/_build/results?*view=logs*
// @match        https://dev.azure.com/*/*/_build/results?*view=logs*
// @icon         https://www.google.com/s2/favicons?domain=azure.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    "use strict";

    const STAGE_PREFIX_ID = "icon-stage-";

    /**
     * Hide stage on click.
     * @param {Event} Event.
     * @param {number} Header index.
     * @returns {undefined} Nothing.
     */
    function hideStage(_event, _i) {
        console.log(_event);
        _event.stopPropagation();
        _event.preventDefault();

        const classList = document.getElementById(`${STAGE_PREFIX_ID}${_i}`).classList;
        const newClassList = [];
        // Change icon className
        classList.forEach((_className) => {
            if(_className === "ms-Icon--ChevronDownMed"){
                newClassList.push("ms-Icon--ChevronRightMed");
            } else if ( _className === "ms-Icon--ChevronRightMed" ){
                newClassList.push("ms-Icon--ChevronDownMed");
            } else {
                newClassList.push(_className);
            }
        });
        document.getElementById(`${STAGE_PREFIX_ID}${_i}`).className = newClassList.join(" ");
        document.getElementsByTagName("tbody")[_i].hidden = !document.getElementsByTagName("tbody")[_i].hidden;
    }

    // Get all stages headers
    const headers = document.getElementsByClassName("bolt-table-header-cell-content");
    for(let i = 0; i < headers.length; i++) {
        const currentHeader = headers[i];
        const parentHeader = currentHeader.parentElement;
        // Add icon to collapse/expand stages
        const iconHeaderHtml = '<span aria-hidden="true" id="' + STAGE_PREFIX_ID + i + '" class="bolt-tree-expand-button font-size cursor-pointer flex-noshrink fabric-icon ms-Icon--ChevronRightMed small" role="presentation"></span>';
        currentHeader.innerHTML = iconHeaderHtml + currentHeader.innerHTML;
        const iconHeader = document.getElementById(`${STAGE_PREFIX_ID}${i}`);
        // Hide all stages
        document.getElementsByTagName("tbody")[i].hidden = true;
        // Add listeners to hide/show stages
        iconHeader.addEventListener("click", (_event) => hideStage(_event, i));
        parentHeader.addEventListener("click", (_event) => hideStage(_event, i));
    }
})();