Skip to content

Instantly share code, notes, and snippets.

@lizrice
Created Jun 15, 2020
Embed
What would you like to do?
Stargazer count
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<p>Project <span id="repo">aquasecurity/trivy</span> <span id="starcount"></span></p>
</body>
<script>
function getStarcount(repo, resultElement) {
var url = 'https://api.github.com/repos/' + repo;
axios.get(url)
.then(function (response) {
resultElement.innerHTML = response.data.stargazers_count;
})
.catch(function (error) {
console.log(error);
});
}
function repo() {
var repo = document.getElementById('repo').innerHTML;
var starcount = document.getElementById('starcount');
getStarcount(repo, starcount);
}
document.addEventListener('DOMContentLoaded', repo());
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment