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