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