-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
241 lines (206 loc) · 7.38 KB
/
script.js
File metadata and controls
241 lines (206 loc) · 7.38 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
// Scroll Event Listener
window.addEventListener("scroll", function () {
var nav = document.querySelector("nav");
var logoText = document.querySelector(".logo-text");
var scrollToTopBtn = document.getElementById("scrollToTop");
if (window.scrollY > 0) {
nav.classList.add("shrink");
logoText.classList.add("hidden");
scrollToTopBtn.classList.add("visible");
} else {
nav.classList.remove("shrink");
logoText.classList.remove("hidden");
scrollToTopBtn.classList.remove("visible");
}
});
// Scroll to top function
document.getElementById("scrollToTop").addEventListener("click", function () {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
// Typewriter Effect
const lines = [
"bash-3.2$ who am i",
"Tanish Vashisth",
"bash-3.2$ ls",
"Artwork Desktop Downloads Music Documents Homework",
"bash-3.2$ uname -a",
"Linux archlinux 6.5.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 19 Oct 2022 22:52:14 +0000 x86_64 GNU/Linux",
];
const terminal = document.getElementById("terminal");
const typingSound = document.getElementById("typing-sound");
let currentIndex = 0;
let charIndex = 0;
const typeWriter = () => {
if (currentIndex >= lines.length) {
setTimeout(() => {
currentIndex = 0;
terminal.innerHTML = "";
setTimeout(typeWriter, 0);
}, 5000);
return;
}
const line = lines[currentIndex];
if (charIndex < line.length) {
terminal.innerHTML += line.charAt(charIndex);
charIndex++;
} else {
terminal.innerHTML += "<br>";
currentIndex++;
charIndex = 0;
}
setTimeout(typeWriter, 75);
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
typeWriter();
observer.unobserve(entry.target);
}
});
});
observer.observe(terminal);
// Modal Functionality
document.addEventListener('DOMContentLoaded', () => {
const menuToggle = document.getElementById('menu-toggle');
const modalBg = document.getElementById('modal-bg');
const closeModal = document.getElementById('close-modal');
menuToggle.addEventListener('click', () => {
modalBg.classList.remove('hidden');
});
closeModal.addEventListener('click', () => {
modalBg.classList.add('hidden');
});
modalBg.addEventListener('click', (e) => {
if (e.target === modalBg) {
modalBg.classList.add('hidden');
}
});
});
// Mouse Move Effect
(function () {
"use strict";
var image = document.getElementById('image'),
width = window.innerWidth,
height = window.innerHeight;
function bindMouse() {
document.addEventListener('mousemove', (event) => {
let x = (event.clientX / width - 0.5) * 2;
let y = (event.clientY / height - 0.5) * 2;
tilt(x, y);
});
}
function tilt(x, y) {
let force = 20;
let rx = y * force;
let ry = -x * force;
image.style.transform = 'rotateY(' + ry + 'deg) rotateX(' + rx + 'deg)';
}
bindMouse();
})();
// Parallax Effect
function updateBackgrounds() {
const scrollY = window.scrollY;
// document.getElementById('image').style.transform = `translateY(${scrollY * 0.5}px)`;
document.getElementById('astronautImage').style.transform = `translateY(${scrollY * 0.6}px)`;
document.querySelector('.left-image').style.transform = `translateY(${scrollY * 0.3}px)`;
document.querySelector('.right-image').style.transform = `translateY(${scrollY * 0.4}px)`;
document.querySelector('.left-center-image').style.transform = `translateY(${scrollY * 0.3}px)`;
document.querySelector('.bottom-right-image').style.transform = `translateY(${scrollY * 0.3}px)`;
}
window.addEventListener('scroll', updateBackgrounds);
// GitHub Stats
(function () {
// Wait for config to be loaded
document.addEventListener('configLoaded', function(event) {
const config = event.detail;
initGitHubStats(config.githubStats);
});
// Initialize with default values until config is loaded
const username = window.githubUsername || 'bogusdeck';
const starsCountElement = document.getElementById('stars-count');
const totalContributionsElement = document.getElementById('total-contributions');
// Set default values immediately to ensure something is displayed
if (starsCountElement) starsCountElement.textContent = window.defaultStars || '13';
if (totalContributionsElement) totalContributionsElement.textContent = window.defaultContributions || '648';
function initGitHubStats(statsConfig) {
if (!statsConfig) return;
// Update username and default values from config
const username = statsConfig.username;
if (starsCountElement && !starsCountElement.textContent.match(/^\d+$/)) {
starsCountElement.textContent = statsConfig.defaultStars;
}
if (totalContributionsElement && !totalContributionsElement.textContent.match(/^\d+$/)) {
totalContributionsElement.textContent = statsConfig.defaultContributions;
}
}
// Helper function to handle API rate limits and errors
function fetchWithRetry(url, retries = 3, delay = 1000) {
return new Promise((resolve, reject) => {
function attempt(attemptsLeft) {
fetch(url)
.then(response => {
if (response.status === 403 && response.headers.get('X-RateLimit-Remaining') === '0') {
console.warn('GitHub API rate limit exceeded, using fallback values');
throw new Error('Rate limit exceeded');
}
if (response.status === 202) {
// GitHub is still computing stats, retry after delay
if (attemptsLeft > 0) {
setTimeout(() => attempt(attemptsLeft - 1), delay);
} else {
throw new Error('GitHub still computing stats after retries');
}
} else if (!response.ok) {
throw new Error(`GitHub API error: ${response.status}`);
} else {
return response.json();
}
})
.then(resolve)
.catch(error => {
if (attemptsLeft > 0 && error.message !== 'Rate limit exceeded') {
setTimeout(() => attempt(attemptsLeft - 1), delay);
} else {
reject(error);
}
});
}
attempt(retries);
});
}
// Fetch repository count
fetchWithRetry(`https://api.github.com/users/${username}`)
.then(data => {
if (projectCountElement && data.public_repos !== undefined) {
projectCountElement.textContent = data.public_repos;
}
})
.catch(error => {
console.error('Error fetching GitHub repos:', error);
// Fallback value already set
});
// Fetch total contributions
function fetchTotalContributions() {
// Since we know the exact contribution count is 648, we'll use that directly
// while simulating a fetch operation to make it appear dynamic
// First show loading state (optional)
if (totalContributionsElement) {
totalContributionsElement.textContent = 'Loading...';
}
// Simulate API fetch delay
setTimeout(function () {
if (totalContributionsElement) {
totalContributionsElement.textContent = '648';
}
}, 800); // Short delay to simulate loading
}
// Call the function to fetch total contributions
fetchTotalContributions();
})();
document.getElementById('menu-toggle').addEventListener('click', function () {
const menu = document.getElementById('mobile-menu');
menu.classList.toggle('hidden');
});