Created
September 23, 2024 19:26
-
-
Save dandelany/c13412ab127b99a49ba5d414ccaf957d to your computer and use it in GitHub Desktop.
Bookmarklet to expand all "Load More" hidden items in a GitHub PR (not resolved conversations)
This file contains hidden or 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
javascript:(() => { | |
const DEFAULT_NUM_TRIES_AFTER_DONE = 5; | |
const MILLIS_TO_SLEEP = 500; | |
const MAX_ITERATIONS = 50; | |
const MAX_PARENTS_TO_CHECK = 7; | |
/* based on https://gist.github.com/bradcupit/3880c34245a465a0fe82e869a168e61b */ | |
/* Originally taken from https://github.com/broadinstitute/gatk/wiki/Expand-outdated-Github-Comments */ | |
function loadAll(numIterations, triesRemainingAfterDone) { | |
let loadMoreButtonArray = Array.from(document.getElementsByClassName('ajax-pagination-btn')); | |
let foundSome = loadMoreButtonArray.length > 0; | |
loadMoreButtonArray.forEach(loadMoreButton => loadMoreButton.click()); | |
scheduledNext(foundSome, numIterations, triesRemainingAfterDone); | |
} | |
function scheduledNext(foundSome, numIterations, triesRemainingAfterDone) { | |
if (numIterations > MAX_ITERATIONS) { | |
console.log(`stopped loading to prevent infinite loop. numIterations = ${numIterations}`); | |
return; | |
} | |
if (foundSome) { | |
setTimeout(() => loadAll(numIterations + 1, DEFAULT_NUM_TRIES_AFTER_DONE), MILLIS_TO_SLEEP); | |
} else if (triesRemainingAfterDone > 0) { | |
setTimeout(() => loadAll(numIterations + 1, triesRemainingAfterDone - 1), MILLIS_TO_SLEEP); | |
} else { | |
done(); | |
} | |
} | |
/* inspired from this: https://stackoverflow.com/a/15466856/152061 */ | |
function done() { | |
let div = document.createElement('div'); | |
div.setAttribute('style', 'position:fixed; top:15%; left:1%; background-color:white; color:black display:inline-block; border-style:solid; border-color:black;'); | |
div.innerHTML = 'finished expanding hidden items'; | |
document.body.appendChild(div); | |
setTimeout(() => div.parentNode.removeChild(div), 2500); | |
console.log('done'); | |
} | |
loadAll(0, DEFAULT_NUM_TRIES_AFTER_DONE); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment