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