]> src.twobees.de Git - tampermonkeyscripts.git/blob - AzureDevOpsCommentEnhancer.user.js
0.18: make '@@DEPENDENCIES' blue
[tampermonkeyscripts.git] / AzureDevOpsCommentEnhancer.user.js
1 // ==UserScript==
2 // @name         Fix ADS checkin comments in discussion and history of workitems
3 // @version      0.18
4 // @author       Tobias Sachs
5 //  ... in @match replace "ads" with the url of you Azure DevOps Server
6 // @match        https://ads/*
7 // @updateURL    https://src.twobees.de/?p=tampermonkeyscripts.git;a=blob_plain;f=AzureDevOpsCommentEnhancer.user.js;hb=HEAD
8 // @downloadURL  https://src.twobees.de/?p=tampermonkeyscripts.git;a=blob_plain;f=AzureDevOpsCommentEnhancer.user.js;hb=HEAD
9 // @grant        none
10 // @description
11 // ==/UserScript==
12
13 // 0.18: make '@@DEPENDENCIES' blue
14 // 0.17: search caseless for '@@CUST'
15 // 0.16: do not modify a comment more than once
16 // 0.15: fix links to work items found in commitmessages (e.g. #1235)
17 // 0.14: also check html property of comments
18 // 0.13: Allow to manually insert changeset comments, which where not associated with the item during checking.
19 //       Just copy changecomment into the commentsection and prefix with "Associated with changeset CHANGESET_NUMBER:"
20 // 0.12: also fix "Resolved with changeset" comments
21 // 0.11: fix regexp for later changesets attached.
22 // 0.10: #Bugnumber to links, highlight comments for customors in checkins
23 // 0.09: updateq download/update URLs
24 // 0.08: fix typregexp for later changesets attachedos/formatting
25 // 0.07: fix work itlsem tampering
26 // 0.06: Add link to Changeset in diff view
27
28 /* jshint esversion:6 */
29 (function() {
30     'use strict';
31     let timerId;
32
33     let fixWorkitems = () => {
34         let found = document.getElementsByClassName("comment-content");
35         fixCommentContents(found);
36
37         found = document.getElementsByClassName("history-item-comment");
38         fixCommentContents(found);
39
40         console.debug("observe...");
41     };
42
43     let checkRegex = /^.*(Associated|Resolved).*[:.]/;
44     let fixCommentContents = (items) => {
45         if (items === null || items === undefined || items.length === 0) {
46             return;
47         }
48         console.info("fixing '" + items.length +"' comments.");
49         for (var i = 0; i < items.length; i++) {
50             let el = items[i];
51             if(el.wasTampered) { continue; }
52
53             let html = el.innerHTML;
54             if (    checkRegex.test(html)
55                 || (el.textContext && checkRegex.test(el.textContext))
56                ) {
57                 html = html.replace(/((Associated|Resolved) with changeset )(\d*)([:.])/,
58                     "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$3'>$3</a></b>$4<br />");
59                 html = html.replace(/#(\d+)/g, "<a href='/HeBa/Entwicklung/_workitems/edit/$1'>#$1</a>");
60                 html = html.replace(/\n/gi, "<br />");
61                 html = html.replace(/(@@CUST.*)/is, "<br><span style=\"color: green; font-style:italic;\">$1</span>");
62                 html = html.replace(/(@@Dependencies.*)/is, "<span style=\"color: blue; font-style:italic;\">$1</span>");
63                 el.innerHTML = html;
64                 el.wasTampered = "😋";
65             }
66         }
67     };
68
69     let fixVersionControl = () => {
70         let elToFix;
71         let found = document.getElementsByClassName("changeset-version")[0];
72         if (!found) {
73             return;
74         }
75
76         // if opened from email notification, it is the first span in div "changeset-version"
77         elToFix = found.querySelector("span");
78
79         if (!elToFix) {
80             return;
81         }
82
83         elToFix.innerHTML = elToFix.innerHTML
84             .replace(/(Changeset )(\d+)/,
85                 "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
86     };
87
88     let fixit = () => {
89         if (timerId) {
90             console.debug("fixit timerreset...");
91             clearTimeout(timerId);
92         }
93
94         observer.disconnect();
95
96         timerId = setTimeout(function() {
97             timerId = undefined;
98
99             let url = window.location.href;
100
101             if (url.includes("/_versionControl")) {
102                 fixVersionControl();
103             }
104             else {
105                 // if (url.includes("/_workitems")){
106                 // does not work since workitems are often shown in
107                 // dialogs on random pages
108                 fixWorkitems();
109             }
110
111             // keep watching for changes
112             observer.observe(document, { subtree: true, childList: true, characterData: true });
113         }, 300);
114     };
115
116     const observer = new MutationObserver(function() {
117         console.debug('observer was triggered...');
118         fixit();
119     });
120
121     fixit();
122
123 })();
124