Skip to content

Instantly share code, notes, and snippets.

@stefanzweifel
Created December 18, 2023 18:25
Show Gist options
  • Save stefanzweifel/882bb6d6b6aab33c20e9dcfd020eccbf to your computer and use it in GitHub Desktop.
Save stefanzweifel/882bb6d6b6aab33c20e9dcfd020eccbf to your computer and use it in GitHub Desktop.
JavaScript function to cycle through the "Dependents" off a GitHub repository and create a collection of repos with the most stars.
function $$(selector, scope = document) {
return Array.from(scope.querySelectorAll(selector));
}
const stats = [];
const threshold = 100;
function processPage() {
let buttons = $$('a.btn');
let nextButton = buttons.find(function (button) {
return button.innerText.trim() === 'Next';
});
if (nextButton) {
let boxRows = $$('div.Box-row');
boxRows.forEach(function (repository) {
var repositoryName = repository.children[1].innerText.replaceAll(' ', '')
var statsDiv = repository.children[2];
var stars = Number(statsDiv.children[0].innerText.trim().replaceAll(',', ''));
if (stars > threshold) {
stats.push({ repo: repositoryName, stars: stars });
}
});
nextButton.click();
// Wait for the new page to load, then process it recursively
setTimeout(processPage, 1000); // Adjust the timeout as needed
} else {
// No more "Next" button, do something with the collected data
console.log(stats);
}
}
// Start the process by calling the function
processPage();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment