-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
434 lines (374 loc) · 16.8 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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
// Scroll indicator
window.addEventListener('scroll', () => {
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (winScroll / height) * 100;
document.getElementById('scrollIndicator').style.width = scrolled + '%';
});
// Tab switching
function showContent(contentType) {
const tabs = document.querySelectorAll('.tab');
const sections = document.querySelectorAll('.content-section');
tabs.forEach(tab => tab.classList.remove('active'));
sections.forEach(section => section.classList.remove('active'));
event.target.classList.add('active');
document.getElementById(`${contentType}-content`).classList.add('active');
if (contentType === 'blog') {
loadBlogPosts();
} else if (contentType === 'youtube') {
loadYouTubeVideos();
} else if (contentType === 'contact') {
// Optionally, you can open the contact form popup when the tab is clicked
document.querySelector('.contact-form-popup').style.display = 'block';
}
}
// GitHub API integration
const githubUsername = 'mdabir1203';
const githubApiUrl = 'https://api.github.com/graphql';
async function fetchGithubProjects() {
const query = `
{
user(login: "${githubUsername}") {
pinnedItems(first: 6, types: REPOSITORY) {
nodes {
... on Repository {
name
description
url
stargazerCount
}
}
}
}
}
`;
try {
// Check rate limit status
const rateLimitResponse = await fetch('https://api.github.com/rate_limit', {
headers: {
'Authorization': 'Bearer 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'
}
});
const rateLimitData = await rateLimitResponse.json();
const remainingRequests = rateLimitData.rate.remaining;
if (remainingRequests === 0) {
const resetTime = rateLimitData.rate.reset * 1000; // Convert to milliseconds
const waitTime = resetTime - Date.now();
console.warn(`Rate limit exceeded. Waiting for ${waitTime / 1000} seconds.`);
await new Promise(resolve => setTimeout(resolve, waitTime)); // Wait until the limit resets
}
const response = await fetch(githubApiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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'
},
body: JSON.stringify({ query })
});
const data = await response.json();
console.log('Full API Response:', data);
return data.data.user.pinnedItems.nodes;
} catch (error) {
console.error('Error fetching GitHub projects:', error);
return [];
}
}
// Function to create project card element
function createProjectCard(project) {
const projectElement = document.createElement('div');
projectElement.className = 'project-card';
projectElement.innerHTML = `
<h3 class="project-title">${project.name}</h3>
<p class="project-description">${project.description || 'No description available'}</p>
<div class="project-footer">
<span class="project-stars"> ${project.stargazerCount}</span>
<a href="${project.url}" class="project-link" target="_blank">View on GitHub →</a>
</div>
`;
return projectElement;
}
// Load and render GitHub projects
async function loadGithubProjects() {
const projectsContainer = document.getElementById('projects-content');
projectsContainer.innerHTML = ''; // Clear existing content
const projects = await fetchGithubProjects();
if (projects.length === 0) {
projectsContainer.innerHTML = '<p class="no-projects"';
return;
}
projects.forEach(project => {
const projectElement = createProjectCard(project);
projectsContainer.appendChild(projectElement);
});
}
// Initial load of GitHub projects
loadGithubProjects();
// Medium blog integration
async function fetchMediumPosts() {
const mediumUsername = '@md.abir1203';
const rssUrl = `https://api.rss2json.com/v1/api.json?rss_url=https://medium.com/feed/${mediumUsername}`;
try {
const response = await fetch(rssUrl);
const data = await response.json();
return data.items || [];
} catch (error) {
console.error('Error fetching Medium posts:', error);
return [];
}
}
function createBlogCard(post) {
const date = new Date(post.pubDate).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
const blogElement = document.createElement('div');
blogElement.className = 'blog-card';
blogElement.innerHTML = `
<h3 class="blog-title">${post.title}</h3>
<div class="blog-date">${date}</div>
<p class="blog-excerpt">${post.description.slice(0, 150)}...</p>
<a href="${post.link}" class="blog-link" target="_blank">Read More →</a>
`;
return blogElement;
}
async function loadBlogPosts() {
const blogContainer = document.getElementById('blog-content');
blogContainer.innerHTML = '';
const posts = await fetchMediumPosts();
if (posts.length === 0) {
blogContainer.innerHTML = '<p class="no-posts">No blog posts available</p>';
return;
}
posts.forEach(post => {
const blogElement = createBlogCard(post);
blogContainer.appendChild(blogElement);
});
}
// YouTube integration
const channelId = 'UCPM3MAgkXUOFSfysJuAvthQ'; // Replace with your YouTube channel ID
const apiKey = 'AIzaSyCsm-cKe5f_7t8ZnuNW4MKrlRFO0Y6DLR0'; // Replace with your YouTube API key
async function fetchYouTubeVideos() {
const apiUrl = `https://www.googleapis.com/youtube/v3/search?key=${apiKey}&channelId=${channelId}&part=snippet,id&order=date&maxResults=6`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
return data.items || [];
} catch (error) {
console.error('Error fetching YouTube videos:', error);
return [];
}
}
function createYouTubeCard(video) {
const videoId = video.id.videoId;
const snippet = video.snippet;
const date = new Date(snippet.publishedAt).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
const youtubeElement = document.createElement('div');
youtubeElement.className = 'youtube-card';
youtubeElement.innerHTML = `
<a href="https://www.youtube.com/watch?v=${videoId}" target="_blank">
<div class="youtube-thumbnail">
<img src="${snippet.thumbnails.high.url}" alt="${snippet.title}">
</div>
<div class="youtube-info">
<h3 class="youtube-title">${snippet.title}</h3>
<div class="youtube-date">${date}</div>
</div>
</a>
`;
return youtubeElement;
}
async function loadYouTubeVideos() {
const youtubeContainer = document.getElementById('youtube-content');
youtubeContainer.innerHTML = '';
const videos = await fetchYouTubeVideos();
if (videos.length === 0) {
youtubeContainer.innerHTML = '<p class="no-videos">No videos available</p>';
return;
}
videos.forEach(video => {
const youtubeElement = createYouTubeCard(video);
youtubeContainer.appendChild(youtubeElement);
});
}
async function fetchGitHubData() {
const apiUrl = 'https://api.github.com/users/mdabir1203/repos'; // Replace with your GitHub username
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
// Process the data as needed
displayRepositories(data);
} catch (error) {
console.error('Error fetching GitHub data:', error);
// Show the fallback message and GitHub button when the API call fails
document.getElementById('github-fallback').style.display = 'block';
}
}
// Call the function to fetch GitHub data
fetchGitHubData();
// Close the GitHub fallback message
document.getElementById('closeGithubFallback').onclick = function() {
document.getElementById('github-fallback').style.display = 'none';
}
// Handle form submission
document.getElementById('contactForm').onsubmit = function(event) {
event.preventDefault(); // Prevent the default form submission
// Get form values
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
// Send the email using EmailJS
emailjs.send("service_cex9hkr", "service_cex9hkr", {
name: name,
email: email,
message: message
})
.then(function(response) {
console.log('SUCCESS!', response.status, response.text);
alert('Message sent successfully!');
document.querySelector('.contact-form-popup').style.display = 'none'; // Close the popup
document.getElementById('contactForm').reset(); // Reset the form
}, function(error) {
console.log('FAILED...', error);
alert('Failed to send message. Please try again later.');
});
}
// Show cookie consent banner
window.onload = function() {
if (!localStorage.getItem('cookiesAccepted')) {
document.getElementById('cookieConsent').style.display = 'block';
}
};
// Handle cookie acceptance
document.getElementById('acceptCookies').onclick = function() {
localStorage.setItem('cookiesAccepted', 'true');
document.getElementById('cookieConsent').style.display = 'none';
// Initialize Google Analytics or other tracking scripts here
};
// Handle cookie rejection
document.getElementById('rejectCookies').onclick = function() {
localStorage.setItem('cookiesAccepted', 'false');
document.getElementById('cookieConsent').style.display = 'none';
};
// Handle cookie settings (this can be expanded to show specific options)
document.getElementById('cookieSettings').onclick = function() {
alert('Here you can provide more information about cookie categories and allow users to select their preferences.');
// Implement a modal or additional UI for cookie preferences
};
function bookMeeting() {
// Replace with your Calendly link
window.open('https://calendly.com/md-abir1203', '_blank');
}
// chat.js
const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
async function sendMessage() {
const message = userInput.value;
if (!message) return;
appendMessage('user', message);
userInput.value = '';
try {
const response = await fetch('/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ prompt: message })
});
const data = await response.json();
appendMessage('bot', data.response);
} catch (error) {
console.error('Error:', error);
appendMessage('bot', 'Sorry, I encountered an error.');
}
}
function appendMessage(sender, text) {
const messageDiv = document.createElement('div');
messageDiv.className = `message ${sender}-message`;
messageDiv.textContent = DOMPurify.sanitize(text);
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
const canvas = document.getElementById('explosionCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let particles = [];
function createParticles(x, y) {
const particleCount = 100;
for (let i = 0; i < particleCount; i++) {
particles.push(new Particle(x, y));
}
}
class Particle {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = Math.random() * 5 + 1; // Random size
this.speedX = Math.random() * 6 - 3; // Random horizontal speed
this.speedY = Math.random() * 6 - 3; // Random vertical speed
this.color = 'rgba(' + Math.floor(Math.random() * 255) + ',' +
Math.floor(Math.random() * 255) + ',' +
Math.floor(Math.random() * 255) + ', 1)'; // Random color
this.life = 100; // Particle life
}
update() {
this.x += this.speedX;
this.y += this.speedY;
this.life -= 2; // Decrease life
}
draw() {
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fill();
}
}
function hireMe() {
const hireMeButton = document.getElementById('hireMeButton');
hireMeButton.style.display = 'none';
// Optionally, you can add more actions here, such as showing a form or redirecting to another page
}
// Tab switching
function showContent(contentType) {
const tabs = document.querySelectorAll('.tab');
const sections = document.querySelectorAll('.content-section');
tabs.forEach(tab => tab.classList.remove('active'));
sections.forEach(section => section.classList.remove('active'));
event.target.classList.add('active');
document.getElementById(`${contentType}-content`).classList.add('active');
if (contentType === 'blog') {
loadBlogPosts();
} else if (contentType === 'youtube') {
loadYouTubeVideos();
} else if (contentType === 'contact') {
// Optionally, you can open the contact form popup when the tab is clicked
document.querySelector('.contact-form-popup').style.display = 'block';
}
}
// Sanitize user input
document.getElementById('contactForm').addEventListener('submit', function(event) {
event.preventDefault();
const name = DOMPurify.sanitize(document.getElementById('name').value);
const email = DOMPurify.sanitize(document.getElementById('email').value);
// Proceed with form submission using sanitized values
});
document.addEventListener('mouseout', function(e) {
if (e.clientY < 10) { // Check if the mouse is near the top edge of the window
// Show your popup here
document.getElementById('myPopup').style.display = 'block';
}
});
document.getElementById('myPopup').addEventListener('click', function(e) {
if (e.target === this) { // Check if the click is on the popup itself
this.style.display = 'none';
}
});