-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
270 lines (232 loc) · 9.88 KB
/
script.js
File metadata and controls
270 lines (232 loc) · 9.88 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
document.addEventListener('DOMContentLoaded', function() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
const resumeButtons = document.querySelectorAll('.resume-btn');
const projectCards = document.querySelectorAll('.project-card');
const themeToggle = document.getElementById('themeToggle');
const videoModal = document.getElementById('videoModal');
const modalVideo = document.getElementById('modalVideo');
const closeModal = document.getElementById('closeModal');
const videoLinks = document.querySelectorAll('.project-link.video');
const contactForm = document.getElementById('contactForm');
const reposList = document.getElementById('reposList');
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
hamburger.addEventListener('click', function() {
navMenu.classList.toggle('active');
hamburger.classList.toggle('active');
});
resumeButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const link = document.createElement('a');
link.href = 'assets/resume.pdf';
link.download = 'Resume-Md.Sameer Sayed.pdf';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
});
themeToggle.addEventListener('click', function() {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
function updateThemeIcon(theme) {
const icon = themeToggle.querySelector('i');
if (theme === 'dark') {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
}
}
projectCards.forEach(card => {
const video = card.querySelector('.project-video');
card.addEventListener('mouseenter', function() {
if (video) {
video.play().catch(e => console.log('Video autoplay failed:', e));
}
});
card.addEventListener('mouseleave', function() {
if (video) {
video.pause();
video.currentTime = 0;
}
});
});
videoLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const videoSrc = this.getAttribute('data-video');
const projectCard = this.closest('.project-card');
const projectTitle = projectCard.querySelector('h3').textContent;
const projectDesc = projectCard.querySelector('p').textContent;
if (videoSrc) {
modalVideo.src = videoSrc;
document.getElementById('videoTitle').textContent = projectTitle;
document.getElementById('videoDescription').textContent = projectDesc;
videoModal.style.display = 'flex';
}
});
});
closeModal.addEventListener('click', function() {
videoModal.style.display = 'none';
modalVideo.pause();
});
window.addEventListener('click', function(e) {
if (e.target === videoModal) {
videoModal.style.display = 'none';
modalVideo.pause();
}
});
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
if (this.getAttribute('href').startsWith('#') && !this.getAttribute('href').includes('resume')) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
window.scrollTo({
top: targetSection.offsetTop - 80,
behavior: 'smooth'
});
}
if (navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
}
}
});
});
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
if (validateForm()) {
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData);
const mailtoLink = `mailto:mdsameersayed0@gmail.com?subject=${encodeURIComponent(data.subject)}&body=${encodeURIComponent(`Name: ${data.name}\nEmail: ${data.email}\n\nMessage: ${data.message}`)}`;
window.location.href = mailtoLink;
contactForm.reset();
alert('Thank you for your message! Your email client will open to send the message.');
}
});
function validateForm() {
let isValid = true;
const name = document.getElementById('name');
const email = document.getElementById('email');
const subject = document.getElementById('subject');
const message = document.getElementById('message');
const nameError = document.getElementById('nameError');
const emailError = document.getElementById('emailError');
const subjectError = document.getElementById('subjectError');
const messageError = document.getElementById('messageError');
nameError.style.display = 'none';
emailError.style.display = 'none';
subjectError.style.display = 'none';
messageError.style.display = 'none';
if (!name.value.trim()) {
nameError.textContent = 'Name is required';
nameError.style.display = 'block';
isValid = false;
}
if (!email.value.trim()) {
emailError.textContent = 'Email is required';
emailError.style.display = 'block';
isValid = false;
} else if (!isValidEmail(email.value)) {
emailError.textContent = 'Please enter a valid email address';
emailError.style.display = 'block';
isValid = false;
}
if (!subject.value.trim()) {
subjectError.textContent = 'Subject is required';
subjectError.style.display = 'block';
isValid = false;
}
if (!message.value.trim()) {
messageError.textContent = 'Message is required';
messageError.style.display = 'block';
isValid = false;
}
return isValid;
}
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function fetchGitHubRepos() {
const username = 'sameer-at-git';
const apiUrl = `https://api.github.com/users/${username}/repos?sort=updated&per_page=24`;
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('GitHub API limit exceeded or user not found');
}
return response.json();
})
.then(repos => {
displayRepos(repos);
})
.catch(error => {
console.error('Error fetching GitHub repos:', error);
reposList.innerHTML = '<div class="repo-loading">Unable to load repositories. Please check your GitHub username or try again later.</div>';
});
}
function displayRepos(repos) {
if (!repos || repos.length === 0) {
reposList.innerHTML = '<div class="repo-loading">No repositories found.</div>';
return;
}
reposList.innerHTML = '';
repos.forEach(repo => {
const repoCard = document.createElement('div');
repoCard.className = 'repo-card';
repoCard.innerHTML = `
<a href="${repo.html_url}" class="repo-name" target="_blank">${repo.name}</a>
<p class="repo-description">${repo.description || 'No description available'}</p>
<div class="repo-meta">
<span class="repo-language">
<span class="language-color" style="background-color: ${getLanguageColor(repo.language)}"></span>
${repo.language || 'Unknown'}
</span>
<span><i class="fas fa-star"></i> ${repo.stargazers_count}</span>
<span><i class="fas fa-code-branch"></i> ${repo.forks_count}</span>
</div>
`;
reposList.appendChild(repoCard);
});
}
function getLanguageColor(language) {
const colors = {
'JavaScript': '#f1e05a',
'Python': '#3572A5',
'Java': '#b07219',
'TypeScript': '#2b7489',
'C++': '#f34b7d',
'C#': '#178600',
'PHP': '#4F5D95',
'Ruby': '#701516',
'CSS': '#563d7c',
'HTML': '#e34c26',
'Go': '#00ADD8',
'Rust': '#dea584',
'Swift': '#ffac45',
'Kotlin': '#F18E33'
};
return colors[language] || '#cccccc';
}
fetchGitHubRepos();
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 100) {
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = 'none';
}
});
});