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