Azure DevOps Commit Compare

Compare commits like pull requests

当前为 2023-10-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Azure DevOps Commit Compare
  3. // @namespace https://fxzfun.com/userscripts
  4. // @version 1.0.0
  5. // @description Compare commits like pull requests
  6. // @author FXZFun
  7. // @match https://dev.azure.com/*/*/_git/*/commit/*
  8. // @match https://dev.azure.com/*/*/_git/*
  9. // @icon https://cdn.vsassets.io/content/icons/favicon.ico
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function run() {
  18. if (document.getElementById("__bolt-compare-commits")) return;
  19.  
  20. const commitId = location.href.match(/(?<=commit\/)(.+)(?=\?)/gi)?.[0];
  21. const storedCommitId = localStorage.getItem("azureDevOpsCommitCompareId");
  22.  
  23. document.getElementById("__bolt-browse-files").insertAdjacentHTML("beforeBegin",
  24. `<a aria-roledescription="link"
  25. class="bolt-header-command-item-button bolt-button bolt-link-button enabled ${storedCommitId && "primary"} bolt-focus-treatment"
  26. data-focuszone="focuszone-3"
  27. data-is-focusable="true"
  28. id="__bolt-compare-commits"
  29. role="menuitem"
  30. tabindex="0">
  31. <span class="bolt-button-text body-m">${storedCommitId ? "Start Compare" : "Compare Commits"}</span>
  32. </a>`);
  33.  
  34. document.getElementById("__bolt-compare-commits").addEventListener("click", () => {
  35. let url = location.href.substring(0, location.href.indexOf('commit'));
  36.  
  37. if (!storedCommitId) {
  38. localStorage.setItem("azureDevOpsCommitCompareId", commitId);
  39. url += "commits";
  40. } else {
  41. localStorage.removeItem("azureDevOpsCommitCompareId");
  42. url += `/branchCompare?baseVersion=GC${storedCommitId}&targetVersion=GC${commitId}&_a=files`;
  43. }
  44.  
  45. location.href = url;
  46. });
  47. }
  48.  
  49. let currentURL = "";
  50. setInterval(() => {
  51. if (location.href !== currentURL && /https:\/\/dev\.azure\.com\/.*\/.*\/_git\/.*\/commit\/.*/.test(location.href)) {
  52. run()
  53. currentURL = location.href;
  54. }
  55. }, 1000); // Check every second
  56.  
  57. })();