From 31cc1c2a69c329552c5bb1d1dfe05d7464c05cf2 Mon Sep 17 00:00:00 2001 From: Tobias Sachs Date: Thu, 6 Aug 2020 10:56:37 +0200 Subject: [PATCH] Add link to Changeset in diff view --- AzureDevOpsCommentEnhancer.user.js | 68 ++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) mode change 100644 => 100755 AzureDevOpsCommentEnhancer.user.js diff --git a/AzureDevOpsCommentEnhancer.user.js b/AzureDevOpsCommentEnhancer.user.js old mode 100644 new mode 100755 index ba3df44..083bd5a --- a/AzureDevOpsCommentEnhancer.user.js +++ b/AzureDevOpsCommentEnhancer.user.js @@ -1,16 +1,32 @@ // ==UserScript== // @name Fix ADS checkin comments in discussion and history of workitems -// @version 0.1 +// @version 0.6 // @author Tobias Sachs -// ... add match eg https://myazerdevops/* -// @match https:// +// ... in @match replace "ads" with the url of you Azure DevOps Server +// @match https://ads/* +// @updateURL https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js +// @downloadURL https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js // @grant none +// @description // ==/UserScript== +// 0.6: Add link to Changeset in diff view + (function() { 'use strict'; let timerId = undefined; - let fixComments = (items) => + + let fixWorkitems = () => + { + let found = document.getElementsByClassName("comment-content"); + fixCommentContents(found); + + found = document.getElementsByClassName("history-item-comment"); + fixCommentContents(found); + + console.debug("observe..."); + } + let fixCommentContents = (items) => { if (items === null || items === undefined || items.length === 0) { @@ -27,6 +43,29 @@ } } }; + + let fixVersionControl = () => + { + let elToFix; + let found = document.getElementsByClassName("changeset-version")[0]; + if (found) { + // if opened from email notification it is the first span in div "changeset-version" + elToFix = found.querySelector("span"); + } + else + { + // if opened from histrory in ads it is the span in div "changeset-id" + // elToFix = document.getElementsByClassName("changeset-id")[0]; + } + if (!elToFix) + { + return; + } + + elToFix.innerHTML = elToFix.innerHTML.replace(/(Changeset )(\d+)/, "$1$2"); + + } + let fixit = () => { if (timerId){ console.debug("fixit timerreset..."); @@ -34,15 +73,26 @@ } observer.disconnect(); + timerId = setTimeout(function(){ timerId = undefined; - let found = document.getElementsByClassName("comment-content"); - fixComments(found); - found = document.getElementsByClassName("history-item-comment"); - fixComments(found); + let url = window.location.href; + + if (url.includes("/_versionControl")) + { + fixVersionControl(); + } + else if (url.includes("/_workitems")){ + fixWorkitems(); + } + else + { + console.info("nothing to do here"); + return; + } - console.debug("observe..."); + // keep watching for changes. observer.observe(document, { subtree: true, childList: true, characterData: true }); }, 300); }; -- 2.39.2