forked from akshitagupta15june/PetMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const navBar = document.getElementById("navbar");
const logo = document.getElementById("logo");
const navBtn = document.getElementById("nav-button");
navBtn.addEventListener("click", () => {
navBar.classList.toggle("hidden");
logo.classList.toggle("hidden");
});
// Script for to get Github contributors list
const contributors = document.getElementById("contributors");
const repo = "PetMe";
const owner = "akshitagupta15june";
const apiURL = `https://api.github.com/repos/${owner}/${repo}/contributors`;
function displayContributors(contributorsList) {
contributorsList.forEach((contributor) => {
// create anchor tag and set relevant attributes
const link = document.createElement("a");
link.setAttribute("href", contributor.html_url);
link.setAttribute("target", "_blank");
// create image element and set relevant attributes
const avatar = document.createElement("img");
avatar.setAttribute("class", "avatar");
avatar.setAttribute("src", contributor.avatar_url);
avatar.setAttribute("title", contributor.login);
avatar.setAttribute("alt", contributor.login);
link.appendChild(avatar);
contributors.appendChild(link);
});
}
// get contributors list from github API
async function getContributorsList() {
try {
const response = await fetch(apiURL);
const contributors = await response.json();
displayContributors(contributors);
} catch (error) {
console.log(error);
}
}
getContributorsList();