forked from NageshMandal/Engineering-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
151 lines (126 loc) · 4.45 KB
/
script.js
File metadata and controls
151 lines (126 loc) · 4.45 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Get the "return to top" button element
var returnToTopButton = document.getElementById('returnToTop');
// Function to scroll to the top of the page
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
// Function to toggle the visibility of the "return to top" button
function toggleReturnToTopButton() {
if (window.scrollY > 200) {
returnToTopButton.classList.add('active');
} else {
returnToTopButton.classList.remove('active');
}
}
// Add event listeners
window.addEventListener('scroll', toggleReturnToTopButton);
returnToTopButton.addEventListener('click', scrollToTop);
//! dark mode
const header = document.querySelector(".header");
const toggle = document.querySelector(".toggle-mode");
const body = document.querySelector("body");
const paragraph = document.querySelector("p");
const links = document.querySelectorAll(".nav-link");
const title = document.querySelectorAll("h2");
const para = document.querySelectorAll(".para");
const pcol = document.querySelector(".col-2 p");
if (localStorage.getItem("dark-mode") == "true") {
body.classList.add("dark-mode");
header.classList.add("header-dark-mode");
paragraph.classList.add("header-dark-mode");
links.forEach(function (e) {
e.classList.add("header-dark-mode");
});
document.querySelector(`.sun`).style.display = "inline-block";
document.querySelector(`.moon`).style.display = "none";
title.forEach(function (e) {
e.classList.add("dark-mode");
});
}
toggle.addEventListener("click", function (e) {
const nextIcon = e.target.getAttribute("data-set");
e.target.style.display = "none";
console.log(nextIcon);
// document.querySelector("")
if (nextIcon === "sun") {
body.classList.add("dark-mode");
header.classList.add("header-dark-mode");
paragraph.classList.add("header-dark-mode");
pcol.style.color="white";
links.forEach(function (e) {
e.classList.add("header-dark-mode");
});
document.querySelector(`.${nextIcon}`).style.display = "inline-block";
title.forEach(function (e) {
e.classList.add("dark-mode");
});
localStorage.setItem("dark-mode", true);
} else {
body.classList.remove("dark-mode");
header.classList.remove("header-dark-mode");
paragraph.classList.remove("header-dark-mode");
pcol.style.color="black";
links.forEach(function (e) {
e.classList.remove("header-dark-mode");
});
document.querySelector(`.${nextIcon}`).style.display = "inline-block";
title.forEach(function (e) {
e.classList.remove("dark-mode");
});
localStorage.setItem("dark-mode", false);
}
});
// Script for to get Github contributors list
const contributors = document.getElementById("contributors");
const repo = "Engineering-Notes-Website";
const owner = "NageshMandal";
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();
// Search bar functionality
const searchForm = document.getElementById("search-form");
const searchInput = document.getElementById("search-input");
searchForm.addEventListener("submit", function (event) {
event.preventDefault();
const searchTerm = searchInput.value.toLowerCase();
searchContributors(searchTerm);
});
function searchContributors(searchTerm) {
const contributorLinks = contributors.getElementsByTagName("a");
for (const link of contributorLinks) {
const username = link.getAttribute("title").toLowerCase();
if (username.includes(searchTerm)) {
link.style.display = "inline-block";
} else {
link.style.display = "none";
}
}
}