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