Skip to content

Instantly share code, notes, and snippets.

@daronspence
Created March 9, 2024 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daronspence/7117e1930fadd6c5feaa28e944d51abc to your computer and use it in GitHub Desktop.
Save daronspence/7117e1930fadd6c5feaa28e944d51abc to your computer and use it in GitHub Desktop.
Bulk Delete Stale Branches Userscript
// Copy and paste this into the browser console: https://github.com/<your-username>/<your-repo-name>/branches/stale
// Helper function
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function clickDeleteElements() {
// Note: the label here may be different if you are not using English
const elements = Array.from(document.querySelectorAll('button[aria-label*=Delete]'));
for (let index = 0; index < elements.length; index++) {
elements[index].click(); // Perform the click action
await sleep(500);
}
}
async function doAll(x) {
for (let index = 0; index < x; index++) {
await clickDeleteElements();
console.log(`Done with page ${index + 1}`);
document.querySelector("a[rel=next]").click()
await sleep(1500)
}
console.log('Done! Run the doAll() function again to delete more pages.')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment