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