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.16: do not modify a comment more than once
14 // 0.15: fix links to work items found in commitmessages (e.g. #1235)
15 // 0.14: also check html property of comments
16 // 0.13: Allow to manually insert changeset comments, which where not associated with the item during checking.
17 // Just copy changecomment into the commentsection and prefix with "Associated with changeset CHANGESET_NUMBER:"
18 // 0.12: also fix "Resolved with changeset" comments
19 // 0.11: fix regexp for later changesets attached.
20 // 0.10: #Bugnumber to links, highlight comments for customors in checkins
21 // 0.09: updateq download/update URLs
22 // 0.08: fix typregexp for later changesets attachedos/formatting
23 // 0.07: fix work itlsem tampering
24 // 0.06: Add link to Changeset in diff view
26 /* jshint esversion:6 */
31 let fixWorkitems = () => {
32 let found = document.getElementsByClassName("comment-content");
33 fixCommentContents(found);
35 found = document.getElementsByClassName("history-item-comment");
36 fixCommentContents(found);
38 console.debug("observe...");
41 let checkRegex = /^.*(Associated|Resolved).*[:.]/;
42 let fixCommentContents = (items) => {
43 if (items === null || items === undefined || items.length === 0) {
46 console.info("fixing '" + items.length +"' comments.");
47 for (var i = 0; i < items.length; i++) {
49 if(el.wasTampered) { continue; }
51 let html = el.innerHTML;
52 if ( checkRegex.test(html)
53 || (el.textContext && checkRegex.test(el.textContext))
55 html = html.replace(/((Associated|Resolved) with changeset )(\d*)([:.])/,
56 "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$3'>$3</a></b>$4<br />");
57 html = html.replace(/#(\d+)/g, "<a href='/HeBa/Entwicklung/_workitems/edit/$1'>#$1</a>");
58 html = html.replace(/\n/gi, "<br />");
59 html = html.replace(/(@@CUST.*)/s, "<br><span style=\"color: green; font-style:italic;\">$1</span>");
61 el.wasTampered = "😋";
66 let fixVersionControl = () => {
68 let found = document.getElementsByClassName("changeset-version")[0];
73 // if opened from email notification, it is the first span in div "changeset-version"
74 elToFix = found.querySelector("span");
80 elToFix.innerHTML = elToFix.innerHTML
81 .replace(/(Changeset )(\d+)/,
82 "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
87 console.debug("fixit timerreset...");
88 clearTimeout(timerId);
91 observer.disconnect();
93 timerId = setTimeout(function() {
96 let url = window.location.href;
98 if (url.includes("/_versionControl")) {
102 // if (url.includes("/_workitems")){
103 // does not work since workitems are often shown in
104 // dialogs on random pages
108 // keep watching for changes
109 observer.observe(document, { subtree: true, childList: true, characterData: true });
113 const observer = new MutationObserver(function() {
114 console.debug('observer was triggered...');