]> src.twobees.de Git - tampermonkeyscripts.git/blob - AzureDevOpsCommentEnhancer.user.js
version
[tampermonkeyscripts.git] / AzureDevOpsCommentEnhancer.user.js
1 // ==UserScript==
2 // @name         Fix ADS checkin comments in discussion and history of workitems
3 // @version      0.4
4 // @author       Tobias Sachs
5 //  ... add match eg https://myazerdevops/*
6 // @match        https://
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 // ==/UserScript==
11
12 (function() {
13     'use strict';
14     let timerId = undefined;
15     let fixComments = (items) =>
16     {
17         if (items === null || items === undefined || items.length === 0)
18         {
19             return;
20         }
21         console.info("fixing '" + items.length +"' comments.");
22         for (var i = 0; i < items.length; i++){
23             let el = items[i];
24             let html = el.innerHTML;
25             if (html.startsWith("Associated"))
26             {
27                 html = html.replace(/(Associated with changeset )(\d*):/, "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a></b>:<br />");
28                 el.innerHTML = html.replace(/\n/gi, "<br />");
29             }
30         }
31     };
32     let fixit = () => {
33         if (timerId){
34             console.debug("fixit timerreset...");
35             clearTimeout(timerId);
36         }
37
38         observer.disconnect();
39         timerId = setTimeout(function(){
40             timerId = undefined;
41             let found = document.getElementsByClassName("comment-content");
42             fixComments(found);
43
44             found = document.getElementsByClassName("history-item-comment");
45             fixComments(found);
46
47             console.debug("observe...");
48             observer.observe(document, { subtree: true, childList: true, characterData: true });
49         }, 300);
50     };
51
52     const observer = new MutationObserver(function() {
53         console.debug('observertriggered...');
54         fixit();
55     });
56
57     fixit();
58
59 })();