|
1 | 1 | // ==UserScript== |
2 | 2 |
|
3 | 3 | // @name More Awesome Azure DevOps (userscript) |
4 | | -// @version 3.5.2 |
| 4 | +// @version 3.5.3 |
5 | 5 | // @author Alejandro Barreto (NI) |
6 | 6 | // @description Makes general improvements to the Azure DevOps experience, particularly around pull requests. Also contains workflow improvements for NI engineers. |
7 | 7 | // @license MIT |
|
332 | 332 | value="${regexFilterString}"> |
333 | 333 | <div id="agentFilterCounter" style="color: var(--text-secondary-color);"/> |
334 | 334 | <div> |
| 335 | + <button |
| 336 | + id="copyMatchedAgentsToClipboard" |
| 337 | + class="bolt-button bolt-icon-button subtle bolt-focus-treatment" |
| 338 | + role="button" |
| 339 | + tabindex="0" |
| 340 | + type="button" |
| 341 | + style="padding: 0px; margin-left: 10px;" |
| 342 | + title="Copy Matched Agents to Clipboard"> |
| 343 | + <span class="left-icon flex-noshrink fabric-icon ms-Icon--Copy medium" style="padding: 5px 10px"/> |
| 344 | + </button> |
335 | 345 | <button |
336 | 346 | id="agentFilterRefresh" |
337 | 347 | class="refresh-dashboard-button bolt-button bolt-icon-button subtle bolt-focus-treatment" |
338 | 348 | role="button" |
339 | 349 | tabindex="0" |
340 | 350 | type="button" |
341 | | - style="padding: 0px; margin-left: 10px;"> |
| 351 | + style="padding: 0px;"> |
342 | 352 | <span class="left-icon flex-noshrink fabric-icon ms-Icon--Refresh medium" style="padding: 5px 10px"/> |
343 | 353 | </button> |
344 | 354 | </div> |
|
352 | 362 | document.getElementById('agentFilterInput').addEventListener('input', filterAgentsDebouncer); |
353 | 363 | document.getElementById('agentFilterInput').addEventListener('keydown', filterAgentsNow); |
354 | 364 | document.getElementById('agentFilterRefresh').addEventListener('click', filterAgentsNow); |
| 365 | + document.getElementById('copyMatchedAgentsToClipboard').addEventListener('click', copyMatchedAgentsToClipboard); |
355 | 366 | } |
356 | 367 | filterAgents(); |
357 | 368 | }); |
|
360 | 371 | setInterval(filterAgents, 60000); |
361 | 372 | } |
362 | 373 |
|
| 374 | + function copyMatchedAgentsToClipboard() { |
| 375 | + if (filterAgents.running) return; |
| 376 | + |
| 377 | + let matchString = ''; |
| 378 | + let total = 0; |
| 379 | + const agentRows = document.querySelectorAll('a.bolt-list-row.single-click-activation'); |
| 380 | + agentRows.forEach(agentRow => { |
| 381 | + const agentCells = agentRow.querySelectorAll('div'); |
| 382 | + const agentName = agentCells[1].innerText; |
| 383 | + if ($(agentRow).is(':visible')) { |
| 384 | + matchString += `${agentName}.*,`; |
| 385 | + total += 1; |
| 386 | + } |
| 387 | + }); |
| 388 | + |
| 389 | + navigator.clipboard.writeText(matchString); |
| 390 | + swal.fire({ |
| 391 | + icon: 'success', |
| 392 | + title: `${total} matched agents copied to clipboard!`, |
| 393 | + showConfirmButton: false, |
| 394 | + timer: 1500, |
| 395 | + }); |
| 396 | + } |
| 397 | + |
363 | 398 | function filterAgentsNow(event) { |
364 | 399 | if (event.key === 'Enter' || event.type === 'click') { |
365 | 400 | filterAgents.enter = true; |
|
405 | 440 | } |
406 | 441 | document.getElementById('agentFilterCounter').innerText = 'Filtering...'; |
407 | 442 | document.getElementById('agentFilterInput').readOnly = true; |
| 443 | + document.getElementById('copyMatchedAgentsToClipboard').disabled = true; |
408 | 444 |
|
409 | 445 | // Try to push the filter term if possible. |
410 | 446 | try { |
|
461 | 497 | if (!regexFilter.test(rowValue)) { |
462 | 498 | agentRow.classList.add('hiddenAgentRow'); |
463 | 499 | } else { |
464 | | - agentCells[1].querySelectorAll('span')[0].classList.add('agent-name-span'); |
465 | 500 | agentRow.classList.remove('hiddenAgentRow'); |
466 | | - if (atNI) { |
467 | | - matchedAgents[agentName] = agentCells; |
468 | | - } |
| 501 | + matchedAgents[agentName] = agentCells; |
469 | 502 | } |
470 | 503 | }); |
471 | 504 | $('.hiddenAgentRow').hide(); |
472 | 505 |
|
473 | 506 | for (const [agentName, agentCells] of Object.entries(matchedAgents)) { |
474 | | - addAgentExtraInformation(agentCells, agentName, currentPoolId, poolAgentsInfo); |
| 507 | + if (atNI) { |
| 508 | + agentCells[1].querySelectorAll('span')[0].classList.add('agent-name-span'); |
| 509 | + addAgentExtraInformation(agentCells, agentName, currentPoolId, poolAgentsInfo); |
| 510 | + } |
475 | 511 | } |
476 | 512 | document.getElementById('agentFilterCounter').innerText = `(${Object.keys(matchedAgents).length}/${totalCount})`; |
477 | 513 | } catch (e) { |
|
483 | 519 |
|
484 | 520 | function exitFilterAgents() { |
485 | 521 | document.getElementById('agentFilterInput').readOnly = false; |
| 522 | + document.getElementById('copyMatchedAgentsToClipboard').disabled = false; |
486 | 523 | filterAgents.running = false; |
487 | 524 | filterAgents.enter = false; |
488 | 525 | } |
|
0 commit comments