Skip to content

Instantly share code, notes, and snippets.

@DrummerHead
Last active September 24, 2017 21:13
Show Gist options
  • Save DrummerHead/748630dd98848878acce94b5100b8299 to your computer and use it in GitHub Desktop.
Save DrummerHead/748630dd98848878acce94b5100b8299 to your computer and use it in GitHub Desktop.
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