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