-
Notifications
You must be signed in to change notification settings - Fork 219
/
script1.js
77 lines (66 loc) · 2.32 KB
/
script1.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
let pageNo = 1;
document.addEventListener("DOMContentLoaded", () => {
const contributorsContainer = document.getElementById("contributors");
const nextBtn = document.getElementById("nextBtn");
const prevBtn = document.getElementById("prevBtn");
const pageNoBox = document.getElementById("pageNoBox");
async function fetchContributors(page) {
pageNo += page;
try {
const response = await fetch(
`https://api.github.com/repos/ankit071105/Ticket-Booking/contributors?page=${pageNo}`
);
const contributors = await response.json();
console.log(contributors.length);
if (contributors.length == 0 || pageNo < 1) {
return;
}
contributorsContainer.innerHTML = "";
pageNoBox.innerText = pageNo;
contributors.forEach((contributor) => {
const contributorCard = document.createElement("div");
contributorCard.className = "contributor-card";
contributorCard.innerHTML = `
<a href="${contributor.html_url}" target="_blank" rel="noopener noreferrer">
<img src="${contributor.avatar_url}" alt="${contributor.login}">
</a>
<h2>${contributor.login}</h2>
<p>Contributions: ${contributor.contributions}</p>
`;
contributorsContainer.appendChild(contributorCard);
});
} catch (error) {
console.error("Error fetching contributors:", error);
}
}
fetchContributors(0);
prevBtn.addEventListener("click", (e) => {
e.preventDefault();
fetchContributors(-1);
});
nextBtn.addEventListener("click", (e) => {
e.preventDefault();
fetchContributors(1);
});
});
// dark mode
document.addEventListener("DOMContentLoaded", () => {
const toggleCheckbox = document.getElementById("themeToggle");
const body = document.body;
// Load saved dark mode preference from localStorage
if (localStorage.getItem("dark-mode") === "enabled") {
body.classList.add("dark-mode");
toggleCheckbox.checked = true;
} else {
toggleCheckbox.checked = false;
}
toggleCheckbox.addEventListener("change", () => {
if (toggleCheckbox.checked) {
body.classList.add("dark-mode");
localStorage.setItem("dark-mode", "enabled");
} else {
body.classList.remove("dark-mode");
localStorage.setItem("dark-mode", "disabled");
}
});
});