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