forked from akshitagupta15june/PetMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (45 loc) · 1.58 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
47
48
49
50
51
52
53
// 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);
});
}
function hideBackToTopButton() {
const bttButton = document.getElementById("bttbutton");
window.addEventListener("scroll", function() {
if (window.pageYOffset > 0) {
bttButton.style.opacity = "1";
bttButton.style.transform = 'translateY(0px)';
} else {
bttButton.style.opacity = "0";
bttButton.style.transform = 'translateY(500px)';
}
});
}
// 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);
}
}
hideBackToTopButton()
getContributorsList();