Skip to content

Instantly share code, notes, and snippets.

@oalders
Created April 16, 2025 20:23
Show Gist options
  • Save oalders/d09a35201ba3f5cab4bdf4a90ead76db to your computer and use it in GitHub Desktop.
Save oalders/d09a35201ba3f5cab4bdf4a90ead76db to your computer and use it in GitHub Desktop.
Load GitHub Pr Hidden Converations
(async function clickAllLoadMoreButtons() {
const delay = ms => new Promise(res => setTimeout(res, ms));
const selector = 'button.ajax-pagination-btn';
let attempts = 0;
const maxAttempts = 50; // Stop after 50 attempts
// Set up MutationObserver to detect DOM changes and watch for 'Load more...' buttons
const observer = new MutationObserver(async function(mutationsList, observer) {
// Stop observing once max attempts are reached
if (attempts >= maxAttempts) {
console.log("Reached maximum attempts. Stopping...");
observer.disconnect(); // Stop observing after max attempts
return;
}
const btn = document.querySelector(selector);
// Only click when a new 'Load more...' button is visible and it's not loading
if (btn && !btn.disabled && !btn.innerText.trim().toLowerCase().includes('loading')) {
console.log(`Clicking 'Load more…' button (attempt ${attempts + 1})`);
btn.scrollIntoView({ behavior: "smooth", block: "center" });
btn.click();
attempts++;
// Wait for content to load before observing again
await delay(2000);
}
});
// Configure the observer to look for changes in the DOM (button insertions)
observer.observe(document.body, {
childList: true,
subtree: true
});
// Start by looking for an existing "Load more..." button
const initialBtn = document.querySelector(selector);
if (initialBtn) {
console.log("Found an initial 'Load more...' button.");
// If the button already exists, click it initially
initialBtn.click();
attempts++;
await delay(2000); // Wait for content to load
} else {
console.log("No 'Load more...' button found initially.");
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment