Skip to content

Instantly share code, notes, and snippets.

@getdave
Last active March 17, 2022 11:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getdave/9b9087055decf6f6cb7bfada08fcd3d1 to your computer and use it in GitHub Desktop.
Save getdave/9b9087055decf6f6cb7bfada08fcd3d1 to your computer and use it in GitHub Desktop.
A Tampermonkey script to automatically expand all those pesky folded Github PR comments.
// ==UserScript==
// @name Recursively expand Github PR comments
// @namespace http://aheadcreative.co.uk/
// @version 1.0
// @description Automatically expands all those pesky folded Github PR comments.
// @author Dave Smith (@getdave). Please contact for questions and feedback
// @match https://github.com/*/*/pull/*
// @copyright 2020, Ahead Creative
// @updateURL https://gist.githubusercontent.com/getdave/9b9087055decf6f6cb7bfada08fcd3d1/raw/
// ==/UserScript==
( function () {
/** To prevent a race condition */
let doingIt = false;
let theTimeout = null;
console.log("⚠️ Loading all comment threads...");
function recursiveExpandLoadMore() {
// Remove all existing timers
if(theTimeout) {
clearTimeout(theTimeout);
}
const disabledLoadBtns = document.querySelector('.ajax-pagination-btn[disabled]');
// If any buttons are already in the loading state then requeue
if(disabledLoadBtns) {
theTimeout = setTimeout(recursiveExpandLoadMore, 1000);
return;
}
const loadBtn = document.querySelector('.ajax-pagination-btn:not([disabled])');
// If there are no more load buttons then we're all done.
if(!loadBtn) {
console.log("🎉🎉 Hooray! All comments loaded. 🎉🎉");
return;
}
// Trigger the next button
console.count("⏳ Loading comment set");
loadBtn.click();
// Requeue
theTimeout = setTimeout(recursiveExpandLoadMore, 1000);
}
window.addEventListener( 'load', () => {
// it takes some time to for the page to be ready
recursiveExpandLoadMore();
} );
// listen to GitHub Turbolinks style navigation events
document.addEventListener( 'pjax:end', () => {
recursiveExpandLoadMore();
} );
// listen to GitHub Turbolinks style navigation events, plan B
window.addEventListener( 'statuschange', () => {
recursiveExpandLoadMore();
} );
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment