forked from EuclidStellar/elcostra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
188 lines (152 loc) · 6.79 KB
/
script.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const members = [
'Kartik.json', 'AbhinavD.json', 'Ankita.json', 'Astha.json', 'Lakshay.json', 'Pranav.json',
'Shashwat.json', 'Sneha.json', 'VidushiD.json', 'Aditya.json', 'AnshikaD.json',
'Atul.json', 'Mahak.json', 'Ritik.json', 'Shivang.json', 'Sugandhi.json',
'Vinay.json', 'AkshatD.json', 'Arjun.json', 'Ayush.json', 'Naitik.json',
'Ritika.json', 'ShivaniD.json', 'Tanisha.json', 'Yash.json', 'Amulya.json',
'Arnav.json', 'Dikshant.json', 'Navneet.json', 'Sanvi.json', 'Shivansh.json',
'Tanishka.json', 'Yashvi.json', 'Anchal.json', 'Arpit.json', 'FaizalD.json',
'Navya.json', 'Saumyal.json', 'Shreyaa.json', 'Tushar.json',
'Anish.json', 'Aryan.json', 'Khushi.json', 'Neha.json', 'Shailja.json',
'Siddhartha.json', 'VanshD.json', 'yuga.json', 'Rohit.json','hathaipach.json',
'Maninder.json','JaydeepRawat.json'
];
// Dark Mode Toggle
const toggleButton = document.getElementById('dark-mode-toggle');
function enableDarkMode() {
document.body.classList.add('dark-mode');
const cards = document.querySelectorAll('.card');
cards.forEach((card) => {
card.classList.add('dark-mode');
});
const headings = document.querySelectorAll('h3');
headings.forEach((heading) => {
heading.classList.add('dark-mode');
});
const h1Elements = document.querySelectorAll('h1');
h1Elements.forEach((h1) => {
h1.classList.add('dark-mode');
});
const paragraphs = document.querySelectorAll('p');
paragraphs.forEach((p) => {
p.classList.add('dark-mode');
});
const links = document.querySelectorAll('a');
links.forEach((link) => {
link.classList.add('dark-mode');
});
}
function disableDarkMode() {
document.body.classList.remove('dark-mode');
const cards = document.querySelectorAll('.card');
cards.forEach((card) => {
card.classList.remove('dark-mode');
});
const headings = document.querySelectorAll('h3');
headings.forEach((heading) => {
heading.classList.remove('dark-mode');
});
const h1Elements = document.querySelectorAll('h1');
h1Elements.forEach((h1) => {
h1.classList.remove('dark-mode');
});
const paragraphs = document.querySelectorAll('p');
paragraphs.forEach((p) => {
p.classList.remove('dark-mode');
});
const links = document.querySelectorAll('a');
links.forEach((link) => {
link.classList.remove('dark-mode');
});
}
// Function to apply dark mode based on localStorage preference
function applyDarkModePreference() {
const isDarkMode = localStorage.getItem('darkMode') === 'true'; // Check if dark mode is enabled
if (isDarkMode) {
enableDarkMode();
} else {
disableDarkMode();
}
}
// Toggle dark mode and save preference in localStorage
toggleButton.addEventListener('click', () => {
const isDarkMode = localStorage.getItem('darkMode') === 'true';
if (isDarkMode) {
disableDarkMode(); // Switch to light mode
localStorage.setItem('darkMode', 'false'); // Save light mode state
} else {
enableDarkMode(); // Switch to dark mode
localStorage.setItem('darkMode', 'true'); // Save dark mode state
}
});
async function fetchMemberData(memberFile) {
const response = await axios.get(`members/${memberFile}`);
return response.data;
}
async function fetchMembers() {
const membersDiv = document.getElementById('members');
for (const memberFile of members) {
try {
const member = await fetchMemberData(memberFile);
const memberCard = document.createElement('div');
memberCard.className = 'card';
memberCard.innerHTML = `
<h3>${member.name}</h3>
<p><strong>Branch:</strong> ${member.branch}</p>
<p><strong>GitHub ID:</strong> <a href="${member.url}" target="_blank" class="username" data-name="${member.name}">${member.githubID}</a></p>
`;
// Adding hover effect to fetch joke
memberCard.addEventListener('mouseenter', () => {
let hoverTimer = setTimeout(async () => {
const joke = await fetchJoke(member.name);
showJoke(memberCard, joke);
}, 5000); // 5 seconds
// Clear the timer if the mouse leaves the card before 5 seconds
memberCard.addEventListener('mouseleave', () => {
clearTimeout(hoverTimer);
hideJoke(memberCard);
}, { once: true });
});
membersDiv.appendChild(memberCard);
} catch (error) {
console.error(`Error fetching ${memberFile}:`, error);
}
}
applyDarkModePreference();
}
async function fetchJoke(name) {
try {
const response = await axios.post(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=AIzaSyD27gU3W72I5WmBi3UAGQHwd9ZJy_0d4J8`, {
contents: [
{
parts: [
{
text: `Hi Gemini, please make a tech joke for ${name} as most of the names are from India and are students of AKGEC Ghaziabad so make jokes related to Indian-centric tech memes and areas so that he can laugh a little. Make sure the joke remains professional and yet funny use some tech terms and the name of their college along with the name of the person in the joke to make it more personal and also make fun of frontend developers, backend developers, Flutter Developers and ML developers. Do not make fun of all Frontend, Backend, Flutter and ML developers in one joke choose randomly from them and then give a response also do not create scenarios and multiple jokes and the joke should be a of maximum 100 words. Make sure the probability of joke on each developer is equal.`
}
]
}
]
});
return response.data.candidates[0].content.parts[0].text; // Extracting the joke from the response
} catch (error) {
console.error("Error fetching joke from Gemini API:", error.response ? error.response.data : error.message);
return "Oops! Something went wrong while fetching a joke.";
}
}
function showJoke(memberCard, joke) {
const jokeElement = document.createElement('p');
jokeElement.className = 'joke';
jokeElement.innerText = joke;
jokeElement.style.animation = 'fadeIn 0.5s'; // Minimal animation
memberCard.appendChild(jokeElement);
}
function hideJoke(memberCard) {
const jokeElement = memberCard.querySelector('.joke');
if (jokeElement) {
memberCard.removeChild(jokeElement);
}
}
// Call to fetch members
fetchMembers();
// Call the function to apply the saved preference on page load
applyDarkModePreference();