]> src.twobees.de Git - tampermonkeyscripts.git/blob - AzureDevOpsCommentEnhancer.user.js
fix work item tampering
[tampermonkeyscripts.git] / AzureDevOpsCommentEnhancer.user.js
1 // ==UserScript==
2 // @name         Fix ADS checkin comments in discussion and history of workitems
3 // @version      0.7
4 // @author       Tobias Sachs
5 //  ... in @match replace "ads" with the url of you Azure DevOps Server
6 // @match        https://ads/*
7 // @updateURL    https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js
8 // @downloadURL  https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js
9 // @grant        none
10 // @description
11 // ==/UserScript==
12
13 // 0.7: fix work item tampering
14 // 0.6: Add link to Changeset in diff view
15
16 (function() {
17     'use strict';
18     let timerId = undefined;
19
20     let fixWorkitems = () =>
21     {
22         let found = document.getElementsByClassName("comment-content");
23         fixCommentContents(found);
24
25         found = document.getElementsByClassName("history-item-comment");
26         fixCommentContents(found);
27
28         console.debug("observe...");
29     }
30     let fixCommentContents = (items) =>
31     {
32         if (items === null || items === undefined || items.length === 0)
33         {
34             return;
35         }
36         console.info("fixing '" + items.length +"' comments.");
37         for (var i = 0; i < items.length; i++){
38             let el = items[i];
39             let html = el.innerHTML;
40             if (html.startsWith("Associated"))
41             {
42                 html = html.replace(/(Associated with changeset )(\d*):/, "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a></b>:<br />");
43                 el.innerHTML = html.replace(/\n/gi, "<br />");
44             }
45         }
46     };
47
48     let fixVersionControl = () =>
49     {
50         let elToFix;
51         let found = document.getElementsByClassName("changeset-version")[0];
52         if (found) {
53             // if opened from email notification it is the first span in div "changeset-version"
54             elToFix = found.querySelector("span");
55         }
56         else
57         {
58             // if opened from histrory in ads it is the span in div "changeset-id"
59             // elToFix = document.getElementsByClassName("changeset-id")[0];
60         }
61         if (!elToFix)
62         {
63             return;
64         }
65
66         elToFix.innerHTML = elToFix.innerHTML.replace(/(Changeset )(\d+)/, "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
67
68     }
69
70     let fixit = () => {
71         if (timerId){
72             console.debug("fixit timerreset...");
73             clearTimeout(timerId);
74         }
75
76         observer.disconnect();
77
78         timerId = setTimeout(function(){
79             timerId = undefined;
80
81             let url = window.location.href;
82
83             if (url.includes("/_versionControl"))
84             {
85                 fixVersionControl();
86             }
87             else{
88                 // if (url.includes("/_workitems")){
89                 // does not work since workitem are often shown in 
90                 // diaolgs on random pages
91                 fixWorkitems();
92             }
93
94             // keep watching for changes.
95             observer.observe(document, { subtree: true, childList: true, characterData: true });
96         }, 300);
97     };
98
99     const observer = new MutationObserver(function() {
100         console.debug('observertriggered...');
101         fixit();
102     });
103
104     fixit();
105
106 })();