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