--- /dev/null
+// ==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, `<span style="background: orange;">$1</span>`);
+ let item =
+ `<div style='margin: 2px;' >`
+ + `<a href='` + changeSetUrl
+ + cs.changesetId + `'>` + cs.changesetId + '</a>'
+ + ": " + comment + " (" + cs.author.displayName + ")"
+ + `</div>`;
+ 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 = `<div id="supersearch" style="display: block;position: absolute; left: 450px; top: 0px; height: auto; z-index: 9999;" >
+ <input id="suchBox" placeholder="search commit" />
+ <span id="suchStats"> </span>
+ <div id="suchErg" style="max-height: 500px; background:#CCCCCC; overflow: auto;" ></div>
+ </div>`;
+
+ 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();
+
+})();