Azure DevOps Commit Compare

Compare commits like pull requests

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Azure DevOps Commit Compare
// @namespace    https://fxzfun.com/userscripts
// @version      1.0.0
// @description  Compare commits like pull requests
// @author       FXZFun
// @match        https://dev.azure.com/*/*/_git/*/commit/*
// @match        https://dev.azure.com/*/*/_git/*
// @icon         https://cdn.vsassets.io/content/icons/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function run() {
        if (document.getElementById("__bolt-compare-commits")) return;

        const commitId = location.href.match(/(?<=commit\/)(.+)(?=\?)/gi)?.[0];
        const storedCommitId = localStorage.getItem("azureDevOpsCommitCompareId");

        document.getElementById("__bolt-browse-files").insertAdjacentHTML("beforeBegin",
                                                                          `<a aria-roledescription="link"
                                                                              class="bolt-header-command-item-button bolt-button bolt-link-button enabled ${storedCommitId && "primary"} bolt-focus-treatment"
                                                                              data-focuszone="focuszone-3"
                                                                              data-is-focusable="true"
                                                                              id="__bolt-compare-commits"
                                                                              role="menuitem"
                                                                              tabindex="0">
                                                                               <span class="bolt-button-text body-m">${storedCommitId ? "Start Compare" : "Compare Commits"}</span>
                                                                           </a>`);

        document.getElementById("__bolt-compare-commits").addEventListener("click", () => {
            let url = location.href.substring(0, location.href.indexOf('commit'));

            if (!storedCommitId) {
                localStorage.setItem("azureDevOpsCommitCompareId", commitId);
                url += "commits";
            } else {
                localStorage.removeItem("azureDevOpsCommitCompareId");
                url += `/branchCompare?baseVersion=GC${storedCommitId}&targetVersion=GC${commitId}&_a=files`;
            }

            location.href = url;
        });
    }

    let currentURL = "";
    setInterval(() => {
        if (location.href !== currentURL && /https:\/\/dev\.azure\.com\/.*\/.*\/_git\/.*\/commit\/.*/.test(location.href)) {
            run()
            currentURL = location.href;
        }
    }, 1000); // Check every second

})();