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