2 // @name Fix ADS checkin comments in discussion and history of workitems
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
13 // 0.15: fix links to work items found in Commitmessages (e.g. #1235)
14 // 0.14: also check html property of comments
15 // 0.13: Allow to manually insert changeset comments, which where not associated with the item during checking.
16 // Just copy changecomment into the commentsection and prefix with "Associated with changeset CHANGESET_NUMBER:"
17 // 0.12: also fix "Resolved with changeset" comments
18 // 0.11: fix regexp for later changesets attached.
19 // 0.10: #Bugnumber to links, highlight comments for customors in checkins
20 // 0.09: updateq download/update URLs
21 // 0.08: fix typregexp for later changesets attachedos/formatting
22 // 0.07: fix work itlsem tampering
23 // 0.06: Add link to Changeset in diff view
25 /* jshint esversion:6 */
30 let fixWorkitems = () => {
31 let found = document.getElementsByClassName("comment-content");
32 fixCommentContents(found);
34 found = document.getElementsByClassName("history-item-comment");
35 fixCommentContents(found);
37 console.debug("observe...");
40 let checkRegex = /^.*(Associated|Resolved).*[:.]/;
41 let fixCommentContents = (items) => {
42 if (items === null || items === undefined || items.length === 0) {
45 console.info("fixing '" + items.length +"' comments.");
46 for (var i = 0; i < items.length; i++) {
48 let html = el.innerHTML;
51 if ( checkRegex.test(html)
52 || (el.textContext && checkRegex.test(el.textContext))
54 html = html.replace(/((Associated|Resolved) with changeset )(\d*)([:.])/,
55 "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$3'>$3</a></b>$4<br />");
56 html = html.replace(/#(\d+)/g, "<a href='/HeBa/Entwicklung/_workitems/edit/$1'>#$1</a>");
57 html = html.replace(/\n/gi, "<br />");
58 html = html.replace(/(@@CUST.*)/s, "<br><span style=\"color: green; font-style:italic;\">$1</span>");
64 let fixVersionControl = () => {
66 let found = document.getElementsByClassName("changeset-version")[0];
71 // if opened from email notification, it is the first span in div "changeset-version"
72 elToFix = found.querySelector("span");
78 elToFix.innerHTML = elToFix.innerHTML
79 .replace(/(Changeset )(\d+)/,
80 "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
85 console.debug("fixit timerreset...");
86 clearTimeout(timerId);
89 observer.disconnect();
91 timerId = setTimeout(function() {
94 let url = window.location.href;
96 if (url.includes("/_versionControl")) {
100 // if (url.includes("/_workitems")){
101 // does not work since workitems are often shown in
102 // dialogs on random pages
106 // keep watching for changes
107 observer.observe(document, { subtree: true, childList: true, characterData: true });
111 const observer = new MutationObserver(function() {
112 console.debug('observer was triggered...');