0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -05:00
penpot/docs/js/github-star.js
2024-10-30 13:30:02 +01:00

30 lines
No EOL
786 B
JavaScript

(function (window, document) {
"use strict";
const getRepoStars = async () => {
try {
const response = await fetch("https://api.github.com/repos/penpot/penpot");
const data = await response.json();
return data.stargazers_count;
} catch (error) {
console.error("Error fetching repository data:", error);
return null;
}
};
const updateStarsCount = async () => {
const starsCount = await getRepoStars();
if (starsCount !== null) {
const starsEl = document.getElementById("repo-stars");
if (starsEl) {
starsEl.textContent = `${starsCount}`;
}
}
};
window.addEventListener('load', () => {
updateStarsCount();
});
})(window, document);