From: Tobias Sachs Date: Sun, 1 Nov 2020 11:04:38 +0000 (+0100) Subject: Skrip to inject Changeset comment search X-Git-Url: https://src.twobees.de/?a=commitdiff_plain;h=84d85d920265138e85f86eeefcd093ec99b37dd8;p=tampermonkeyscripts.git Skrip to inject Changeset comment search --- diff --git a/AzureDevOpsChangesetCommentSearch.js b/AzureDevOpsChangesetCommentSearch.js new file mode 100644 index 0000000..1176942 --- /dev/null +++ b/AzureDevOpsChangesetCommentSearch.js @@ -0,0 +1,138 @@ +// ==UserScript== +// @name ADS changeset comment search +// @version 0.1 +// @description Places a searchbox somewhere to search commit messages +// @author Tobias Sachs +// @match https://ads/* +// @grant none +// ==/UserScript== + +/* jshint esversion:6 */ +(function() { + 'use strict'; + let timerId; + let timerSuche; + let pollUrl = 'https://ads/HeBa/Entwicklung/_apis/tfvc/changesets?$top=1000?maxCommentLength=500'; + let skipParm = '&$skip='; + let changeSetUrl = `/HeBa/Entwicklung/_versionControl/changeset/`; + + let totalReceived = 0; + let matchesFound = 0; + + let suchWasDelayed = function(){ + console.debug("blub"); + if (timerSuche) { + clearTimeout(timerSuche); + } + timerSuche = setTimeout( () => + { + timerSuche = undefined; + suchWas(); + }, 200); + }; + + let requestNext = function(skipCnt){ + console.debug("get next. skip: "+ skipCnt); + let xhr = new XMLHttpRequest(); + xhr.onload = () => searchItems(xhr); + xhr.onerror = function (e){ + console.info(`poll error: ${e.type}: ${e.loaded} bytes transferred\n` + JSON.stringify(e)); + }; + xhr.open('GET', pollUrl + skipParm + skipCnt, true); + xhr.send(); + }; + + let searchItems = function(xhr){ + + console.info("Die daten sind da..."); + if (xhr.status !== 200){ + console.info("poll failed: " + xhr.statusText); + return; + } + let s = document.getElementById('suchBox').value; + let resultDiv = document.getElementById('suchErg'); + let statsSpan = document.getElementById('suchStats'); + + var d = JSON.parse(xhr.responseText); + var regex = new RegExp("("+s+")", 'gi'); + totalReceived += d.value.length; + for (let e in d.value){ + let cs = d.value[e]; + + if (cs.comment && regex.test(cs.comment)){ + matchesFound++; + let comment = cs.comment.replace(regex, `$1`); + let item = + `
` + + `` + cs.changesetId + '' + + ": " + comment + " (" + cs.author.displayName + ")" + + `
`; + resultDiv.innerHTML += item; + } + } + statsSpan.innerHTML = "matches: " + matchesFound +" searched comments: " + totalReceived; + if (d.value.length > 0) + { + requestNext(totalReceived); + } + else + { + statsSpan.innerHTML += " -- All comments searched."; + } + }; + + let suchWas = function (){ + let s = document.getElementById('suchBox'); + let results = document.getElementById('suchErg'); + totalReceived = 0; + matchesFound = 0; + results.innerHTML = ""; + document.getElementById('suchStats').innerHTML = ""; + if (s.value.length < 3){ + return; + } + + requestNext(0); + }; + + let addSearch = () => { + if (timerId) { + clearTimeout(timerId); + } + observer.disconnect(); + + timerId = setTimeout(function() { + timerId = undefined; + if (window.location.href.includes("_apis")){ + return; + } + if (window.location.href.includes("_sprints")){ + // macht sonst irgendwie das man im sprintboard nix anklicken kann ¯\_(ツ)_/¯ + return; + } + let search = document.getElementById('supersearch'); + if (!search){ + let html = `
+ + +
+
`; + + document.body.insertAdjacentHTML('afterbegin', html); + let s = document.getElementById('suchBox'); + s.addEventListener("keyup", suchWasDelayed); + } + + // keep watching for changes + observer.observe(document, { subtree: true, childList: true, characterData: true }); + }, 500); + }; + + const observer = new MutationObserver(function() { + addSearch(); + }); + + addSearch(); + +})();