]> src.twobees.de Git - tampermonkeyscripts.git/blob - AzureDevOpsCommentEnhancer.user.js
083bd5a441a798e649b6b2eec7a1855f0e634101
[tampermonkeyscripts.git] / AzureDevOpsCommentEnhancer.user.js
1 // ==UserScript==
2 // @name         Fix ADS checkin comments in discussion and history of workitems
3 // @version      0.6
4 // @author       Tobias Sachs
5 //  ... in @match replace "ads" with the url of you Azure DevOps Server
6 // @match        https://ads/*
7 // @updateURL    https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js
8 // @downloadURL  https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js
9 // @grant        none
10 // @description
11 // ==/UserScript==
12
13 // 0.6: Add link to Changeset in diff view
14
15 (function() {
16     'use strict';
17     let timerId = undefined;
18
19     let fixWorkitems = () =>
20     {
21         let found = document.getElementsByClassName("comment-content");
22         fixCommentContents(found);
23
24         found = document.getElementsByClassName("history-item-comment");
25         fixCommentContents(found);
26
27         console.debug("observe...");
28     }
29     let fixCommentContents = (items) =>
30     {
31         if (items === null || items === undefined || items.length === 0)
32         {
33             return;
34         }
35         console.info("fixing '" + items.length +"' comments.");
36         for (var i = 0; i < items.length; i++){
37             let el = items[i];
38             let html = el.innerHTML;
39             if (html.startsWith("Associated"))
40             {
41                 html = html.replace(/(Associated with changeset )(\d*):/, "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a></b>:<br />");
42                 el.innerHTML = html.replace(/\n/gi, "<br />");
43             }
44         }
45     };
46
47     let fixVersionControl = () =>
48     {
49         let elToFix;
50         let found = document.getElementsByClassName("changeset-version")[0];
51         if (found) {
52             // if opened from email notification it is the first span in div "changeset-version"
53             elToFix = found.querySelector("span");
54         }
55         else
56         {
57             // if opened from histrory in ads it is the span in div "changeset-id"
58             // elToFix = document.getElementsByClassName("changeset-id")[0];
59         }
60         if (!elToFix)
61         {
62             return;
63         }
64
65         elToFix.innerHTML = elToFix.innerHTML.replace(/(Changeset )(\d+)/, "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
66
67     }
68
69     let fixit = () => {
70         if (timerId){
71             console.debug("fixit timerreset...");
72             clearTimeout(timerId);
73         }
74
75         observer.disconnect();
76
77         timerId = setTimeout(function(){
78             timerId = undefined;
79
80             let url = window.location.href;
81
82             if (url.includes("/_versionControl"))
83             {
84                 fixVersionControl();
85             }
86             else if (url.includes("/_workitems")){
87                 fixWorkitems();
88             }
89             else
90             {
91                 console.info("nothing to do here");
92                 return;
93             }
94
95             // keep watching for changes.
96             observer.observe(document, { subtree: true, childList: true, characterData: true });
97         }, 300);
98     };
99
100     const observer = new MutationObserver(function() {
101         console.debug('observertriggered...');
102         fixit();
103     });
104
105     fixit();
106
107 })();