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