Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
See github stars on a list of projects
// On this URL
// https://github.com/markerikson/redux-ecosystem-links/blob/master/routing.md
// or this:
// https://github.com/MicheleBertoli/css-in-js
// or any place with links to a github repo;
// go to developer console and run:
const fetchStars = url => {
const [, user, repo] = url.match(/https:\/\/github.com\/([^\/]*)\/(.*)\/?$/);
return fetch(`https://api.github.com/repos/${user}/${repo}`)
.then(response => response.json())
.then(data => {
if (data.message && data.message.startsWith('API rate limit exceeded')) {
return 'API rate limit exceeded'
} else {
return data.stargazers_count
}
})
.catch(error => console.log(error))
}
const bigList = Array.from(document.querySelectorAll('#readme a'))
.filter(a => /^https:\/\/github/.test(a.getAttribute('href')));
bigList.map(a => {
const url = a.getAttribute('href');
fetchStars(url).then(stars =>
a.insertAdjacentHTML('beforeEnd', ` <span>★ ${stars}</span>`)
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.