forked from akshitagupta15june/PetMe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (66 loc) · 2.38 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// 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();
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{pageLanguage: 'en'},
'google_translate_element'
);
}
var imageIndex = 0;
var imagesArray = [
"url('./Assets/Images/main-heading-body-bg.jpg') center",
"url('./Assets/Images/main-heading-body-bg2.png') center",
"url('./Assets/Images/main-heading-body-bg3.png') center",
"url('./Assets/Images/main-heading-body-bg4.png') center"
];
function changeBackground() {
var index = imageIndex++ % imagesArray.length;
document.querySelector(".main-body-section-div").style.background = imagesArray[index];
}
document.addEventListener("DOMContentLoaded", function() {
document.querySelector(".main-body-section-div").style.background = imagesArray[0];
setInterval(changeBackground, 2000);
});