Skip to content

Instantly share code, notes, and snippets.

@vjk2005
Last active August 27, 2018 11:55
Show Gist options
  • Save vjk2005/19839176087c6d349869849c9d8c2e93 to your computer and use it in GitHub Desktop.
Save vjk2005/19839176087c6d349869849c9d8c2e93 to your computer and use it in GitHub Desktop.
Copy-paste this script in your browser console to load all comments on that reddit thread. (added resume after some time as well as a way to pause all downloads)
pause = false, timeout = lastFetch = restarter = null, moreCommentSelector = 'span.morecomments > a'
moreCommentLinks = () => document.querySelectorAll(moreCommentSelector)
showProgress = msg => {
lastFetch = Date.now()
console.log(`${new Date().toLocaleTimeString()} — ${msg}`)
}
restartIfPaused = () => {
if(!pause && moreCommentLinks().length && ((Date.now() - lastFetch)/1000 > 20)) {
loadMore()
console.log('Resumed loading new comments...')
}
}
clearAllTimers = () => {
clearTimeout(timeout)
clearInterval(restarter)
pause = true
console.log('Timers cleared.')
}
restarter = setInterval(restartIfPaused, 30000)
loadMore = () => {
timeout = setTimeout(() => {
if(!pause) {
let links = moreCommentLinks()
links[0].click()
let remainingLinks = links().length - 1
showProgress(remainingLinks)
remainingLinks? loadMore() : clearAllTimers()
}
}, 5000)
}
loadMore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment