]> src.twobees.de Git - tampermonkeyscripts.git/blobdiff - AzureDevOpsCommentEnhancer.user.js
typo
[tampermonkeyscripts.git] / AzureDevOpsCommentEnhancer.user.js
old mode 100644 (file)
new mode 100755 (executable)
index 9d1c5a2..71332a6
 // ==UserScript==
 // @name         Fix ADS checkin comments in discussion and history of workitems
-// @version      0.3
+// @version      0.11
 // @author       Tobias Sachs
-//  ... add match eg https://myazerdevops/*
-// @match        https://
-// @updateURL    https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js
-// @downloadURL  https://github.com/tsheba/tampermonkeyscripts/raw/master/AzureDevOpsCommentEnhancer.user.js
+//  ... in @match replace "ads" with the url of you Azure DevOps Server
+// @match        https://ads/*
+// @updateURL    https://src.twobees.de/?p=tampermonkeyscripts.git;a=blob_plain;f=AzureDevOpsCommentEnhancer.user.js;hb=HEAD
+// @downloadURL  https://src.twobees.de/?p=tampermonkeyscripts.git;a=blob_plain;f=AzureDevOpsCommentEnhancer.user.js;hb=HEAD
 // @grant        none
+// @description
 // ==/UserScript==
 
+// 0.11: #fix comments in Bugs opened via mention email notification
+// 0.10: #Bugnumber to links, highlight comments for customors in checkins
+// 0.09: update download/update URLs
+// 0.08: fix typos/formatting
+// 0.07: fix work item tampering
+// 0.06: Add link to Changeset in diff view
+
+/* jshint esversion:6 */
 (function() {
     'use strict';
-    let timerId = undefined;
-    let fixComments = (items) =>
-    {
-        if (items === null || items === undefined || items.length === 0)
-        {
-            return;
+    let timerId;
+
+    let fixWorkitems = () => {
+        console.debug("fixWorkitems...");
+        let found = document.getElementsByClassName("comment-content");
+        if (fixCommentContents(found)) return;
+
+        found = document.getElementsByClassName("history-item-comment");
+        if (fixCommentContents(found)) return;
+
+        found = document.getElementsByClassName("comments-section");
+        if (fixCommentContents(found)) return;
+
+        console.debug("... notihing found to fix..");
+    };
+
+    let fixCommentContents = (items) => {
+        if (items === null || items === undefined || items.length === 0) {
+            return false;
         }
         console.info("fixing '" + items.length +"' comments.");
-        for (var i = 0; i < items.length; i++){
+        for (var i = 0; i < items.length; i++) {
             let el = items[i];
             let html = el.innerHTML;
-            if (html.startsWith("Associated"))
-            {
-                html = html.replace(/(Associated with changeset )(\d*):/, "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a></b>:<br />");
-                el.innerHTML = html.replace(/\n/gi, "<br />");
+            if (html.startsWith("Associated")) {
+                html = html.replace(/(Associated with changeset )(\d*):/,
+                    "<b>$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a></b>:<br />");
+                html = html.replace(/#(\d+)/g, "<a href='/HeBa/Entwicklung/_versionControl/changeset/$1'>#$1</a>");
+                html = html.replace(/\n/gi, "<br />");
+                html = html.replace(/(@@CUST.*)/s, "<br><span style=\"color: green; font-style:italic;\">$1</span>");
+                el.innerHTML = html;
             }
         }
+        return true;
     };
+
+    let fixVersionControl = () => {
+        let elToFix;
+        let found = document.getElementsByClassName("changeset-version")[0];
+        if (!found) {
+            return;
+        }
+
+        // if opened from email notification, it is the first span in div "changeset-version"
+        elToFix = found.querySelector("span");
+
+        if (!elToFix) {
+            return;
+        }
+
+        elToFix.innerHTML = elToFix.innerHTML
+            .replace(/(Changeset )(\d+)/,
+                "$1<a href='/HeBa/Entwicklung/_versionControl/changeset/$2'>$2</a>");
+    };
+
     let fixit = () => {
-        if (timerId){
+        if (timerId) {
             console.debug("fixit timerreset...");
             clearTimeout(timerId);
         }
 
         observer.disconnect();
-        timerId = setTimeout(function(){
+
+        timerId = setTimeout(function() {
             timerId = undefined;
-            let found = document.getElementsByClassName("comment-content");
-            fixComments(found);
 
-            found = document.getElementsByClassName("history-item-comment");
-            fixComments(found);
+            let url = window.location.href;
 
-            console.debug("observe...");
+            if (url.includes("/_versionControl")) {
+                fixVersionControl();
+            }
+            else {
+                // if (url.includes("/_workitems")){
+                // does not work since workitems are often shown in
+                // dialogs on random pages
+                fixWorkitems();
+            }
+
+            // keep watching for changes
             observer.observe(document, { subtree: true, childList: true, characterData: true });
         }, 300);
     };
 
     const observer = new MutationObserver(function() {
-        console.debug('observertriggered...');
+        console.debug('observer was triggered...');
         fixit();
     });
 
     fixit();
 
 })();
+