Created
March 9, 2024 13:08
-
-
Save daronspence/7117e1930fadd6c5feaa28e944d51abc to your computer and use it in GitHub Desktop.
Bulk Delete Stale Branches Userscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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