2 // @name ADS changeset comment search
4 // @description Places a searchbox somewhere to search commit messages
5 // @author Tobias Sachs
6 // @match https://ads/*
8 // @updateURL https://src.twobees.de/?p=tampermonkeyscripts.git;a=blob_plain;f=AzureDevOpsChangesetCommentSearch.js;hb=HEAD
9 // @downloadURL https://src.twobees.de/?p=tampermonkeyscripts.git;a=blob_plain;f=AzureDevOpsChangesetCommentSearch.js;hb=HEAD
12 /* jshint esversion:6 */
17 let pollUrl = 'https://ads/HeBa/Entwicklung/_apis/tfvc/changesets?$top=1000?maxCommentLength=500';
18 let skipParm = '&$skip=';
19 let changeSetUrl = `/HeBa/Entwicklung/_versionControl/changeset/`;
21 let totalReceived = 0;
24 let suchWasDelayed = function(){
25 console.debug("blub");
27 clearTimeout(timerSuche);
29 timerSuche = setTimeout( () =>
31 timerSuche = undefined;
36 let requestNext = function(skipCnt){
37 console.debug("get next. skip: "+ skipCnt);
38 let xhr = new XMLHttpRequest();
39 xhr.onload = () => searchItems(xhr);
40 xhr.onerror = function (e){
41 console.info(`poll error: ${e.type}: ${e.loaded} bytes transferred\n` + JSON.stringify(e));
43 xhr.open('GET', pollUrl + skipParm + skipCnt, true);
47 let searchItems = function(xhr){
49 console.info("Die daten sind da...");
50 if (xhr.status !== 200){
51 console.info("poll failed: " + xhr.statusText);
54 let s = document.getElementById('suchBox').value;
55 let resultDiv = document.getElementById('suchErg');
56 let statsSpan = document.getElementById('suchStats');
58 var d = JSON.parse(xhr.responseText);
59 var regex = new RegExp("("+s+")", 'gi');
60 totalReceived += d.value.length;
61 for (let e in d.value){
64 if (cs.comment && regex.test(cs.comment)){
66 let comment = cs.comment.replace(regex, `<span style="background: orange;">$1</span>`);
68 `<div style='margin: 2px;' >`
69 + `<a href='` + changeSetUrl
70 + cs.changesetId + `'>` + cs.changesetId + '</a>'
71 + ": " + comment + " (" + cs.author.displayName + ")"
73 resultDiv.innerHTML += item;
76 statsSpan.innerHTML = "matches: " + matchesFound +" searched comments: " + totalReceived;
77 if (d.value.length > 0)
79 requestNext(totalReceived);
83 statsSpan.innerHTML += " -- All comments searched.";
87 let suchWas = function (){
88 let s = document.getElementById('suchBox');
89 let results = document.getElementById('suchErg');
92 results.innerHTML = "";
93 document.getElementById('suchStats').innerHTML = "";
94 if (s.value.length < 3){
101 let addSearch = () => {
103 clearTimeout(timerId);
105 observer.disconnect();
107 timerId = setTimeout(function() {
109 if (window.location.href.includes("_apis")){
112 if (window.location.href.includes("_sprints")){
113 // macht sonst irgendwie das man im sprintboard nix anklicken kann ¯\_(ツ)_/¯
116 let search = document.getElementById('supersearch');
118 let html = `<div id="supersearch" style="display: block;position: absolute; left: 450px; top: 0px; height: auto; z-index: 9999;" >
119 <input id="suchBox" placeholder="search commit" />
120 <span id="suchStats"> </span>
121 <div id="suchErg" style="max-height: 500px; background:#CCCCCC; overflow: auto;" ></div>
124 document.body.insertAdjacentHTML('afterbegin', html);
125 let s = document.getElementById('suchBox');
126 s.addEventListener("keyup", suchWasDelayed);
129 // keep watching for changes
130 observer.observe(document, { subtree: true, childList: true, characterData: true });
134 const observer = new MutationObserver(function() {