Last active
September 24, 2017 21:13
-
-
Save DrummerHead/748630dd98848878acce94b5100b8299 to your computer and use it in GitHub Desktop.
See github stars on a list of projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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