Collapse PR File Tree
For use on: Azure DevOps
This bookmarklet automatically collapses all expanded folders in the Azure DevOps pull request file tree view. It's useful when you want to quickly collapse all folders to get a cleaner view of the file structure.
The script runs every 20 milliseconds, finding and clicking any expanded folder buttons until all folders at level 2 are collapsed.
It's not very reliable, so you sometimes need to click it a few times to collapse everything.
Installation
To install this bookmarklet, drag the link below to your bookmarks bar:
Alternative: Right-click the link above and select "Bookmark This Link" or "Add to Bookmarks".
Script Content
Below is the JavaScript code that runs when you click the bookmarklet:
(function() {
const sub = setInterval(() => {
console.log('timeout triggered');
const items = document.querySelectorAll(
'tr.bolt-tree-row[aria-level="2"][aria-expanded="true"] .bolt-tree-expand-button'
);
if (items.length === 0) {
console.log('No elements found');
clearTimeout(sub);
return;
}
console.log(`${items.length} elements found`);
items.forEach(el => el.click());
}, 20);
})();