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.18: make '@@DEPENDENCIES' blue
14 // 0.17: search caseless for '@@CUST'
15 // 0.16: do not modify a comment more than once
16 // 0.15: fix links to work items found in commitmessages (e.g. #1235)
17 // 0.14: also check html property of comments
18 // 0.13: Allow to manually insert changeset comments, which where not associated with the item during checking.
19 // Just copy changecomment into the commentsection and prefix with "Associated with changeset CHANGESET_NUMBER:"
20 // 0.12: also fix "Resolved with changeset" comments
21 // 0.11: fix regexp for later changesets attached.
22 // 0.10: #Bugnumber to links, highlight comments for customors in checkins
23 // 0.09: updateq download/update URLs
24 // 0.08: fix typregexp for later changesets attachedos/formatting
25 // 0.07: fix work itlsem tampering
26 // 0.06: Add link to Changeset in diff view
28 /* jshint esversion:6 */
33 let fixWorkitems = () => {
34 let found = document.getElementsByClassName("comment-content");
35 fixCommentContents(found);
37 found = document.getElementsByClassName("history-item-comment");
38 fixCommentContents(found);
40 console.debug("observe...");
43 let checkRegex = /^.*(Associated|Resolved).*[:.]/;
44 let fixCommentContents = (items) => {
45 if (items === null || items === undefined || items.length === 0) {
48 console.info("fixing '" + items.length +"' comments.");
49 for (var i = 0; i < items.length; i++) {
51 if(el.wasTampered) { continue; }
53 let html = el.innerHTML;
54 if ( checkRegex.test(html)
55 || (el.textContext && checkRegex.test(el.textContext))
57 html = html.replace(/((Associated|Resolved) with changeset )(\d*)([:.])/,
58 "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$3'>$3</a></b>$4<br />");
59 html = html.replace(/#(\d+)/g, "<a href='/HeBa/Entwicklung/_workitems/edit/$1'>#$1</a>");
60 html = html.replace(/\n/gi, "<br />");
61 html = html.replace(/(@@CUST.*)/is, "<br><span style=\"color: green; font-style:italic;\">$1</span>");
62 html = html.replace(/(@@Dependencies.*)/is, "<span style=\"color: blue; font-style:italic;\">$1</span>");
64 el.wasTampered = "😋";
69 let fixVersionControl = () => {
71 let found = document.getElementsByClassName("changeset-version")[0];
76 // if opened from email notification, it is the first span in div "changeset-version"
77 elToFix = found.querySelector("span");
83 elToFix.innerHTML = elToFix.innerHTML
84 .replace(/(Changeset )(\d+)/,
85 "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
90 console.debug("fixit timerreset...");
91 clearTimeout(timerId);
94 observer.disconnect();
96 timerId = setTimeout(function() {
99 let url = window.location.href;
101 if (url.includes("/_versionControl")) {
105 // if (url.includes("/_workitems")){
106 // does not work since workitems are often shown in
107 // dialogs on random pages
111 // keep watching for changes
112 observer.observe(document, { subtree: true, childList: true, characterData: true });
116 const observer = new MutationObserver(function() {
117 console.debug('observer was triggered...');