-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
304 lines (255 loc) · 11.2 KB
/
script.js
File metadata and controls
304 lines (255 loc) · 11.2 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
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
document.addEventListener('DOMContentLoaded', function() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}));
});
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.background = 'rgba(15, 15, 15, 0.98)';
} else {
navbar.style.background = 'rgba(15, 15, 15, 0.95)';
}
});
async function fetchGitHubStats() {
try {
const repoResponse = await fetch('https://api.github.com/repos/Auri-OS/AuriOS');
const repoData = await repoResponse.json();
const languagesResponse = await fetch('https://api.github.com/repos/Auri-OS/AuriOS/languages');
const languagesData = await languagesResponse.json();
const totalBytes = Object.values(languagesData).reduce((sum, bytes) => sum + bytes, 0);
const shellPercentage = Math.round((languagesData.Shell || 0) / totalBytes * 100);
const assemblyPercentage = Math.round((languagesData.Assembly || 0) / totalBytes * 100);
const cPercentage = Math.round((languagesData.C || 0) / totalBytes * 100);
const stats = document.querySelectorAll('.stat-number');
stats[0].setAttribute('data-target', shellPercentage);
stats[1].setAttribute('data-target', assemblyPercentage);
stats[2].setAttribute('data-target', cPercentage);
stats[3].setAttribute('data-target', repoData.stargazers_count);
} catch (error) {
console.error('Error fetching GitHub stats:', error);
}
}
function animateCounters() {
const counters = document.querySelectorAll('.stat-number');
let animating = false;
counters.forEach(counter => {
const target = parseInt(counter.getAttribute('data-target'));
const current = parseInt(counter.textContent);
if (current < target) {
animating = true;
const increment = Math.max(1, target / 50);
const newValue = Math.min(current + Math.ceil(increment), target);
counter.textContent = newValue;
}
});
if (animating) {
requestAnimationFrame(() => {
setTimeout(animateCounters, 50);
});
}
}
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
if (entry.target.classList.contains('stats') && !entry.target.dataset.animated) {
entry.target.dataset.animated = 'true';
fetchGitHubStats().then(() => {
setTimeout(animateCounters, 500);
});
}
}
});
}, observerOptions);
document.addEventListener('DOMContentLoaded', () => {
const elementsToAnimate = document.querySelectorAll('.about-card, .feature-card, .contact-link, .stats');
elementsToAnimate.forEach(el => {
if (!el.classList.contains('stats')) {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
}
observer.observe(el);
});
});
function typeWriter(element, text, speed = 100) {
let i = 0;
element.innerHTML = '';
function type() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
document.querySelectorAll('.btn').forEach(btn => {
btn.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.cssText = `
width: ${size}px;
height: ${size}px;
left: ${x}px;
top: ${y}px;
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.3);
transform: scale(0);
animation: ripple 0.6s linear;
pointer-events: none;
`;
this.style.position = 'relative';
this.style.overflow = 'hidden';
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
const style = document.createElement('style');
style.textContent = `
@keyframes ripple {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);
function detectTheme() {
const hour = new Date().getHours();
const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (isDarkMode || hour < 6 || hour > 20) {
document.body.classList.add('dark-theme');
}
}
function lazyLoadImages() {
const images = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
images.forEach(img => imageObserver.observe(img));
}
function debounce(func, wait, immediate) {
let timeout;
return function executedFunction(...args) {
const later = () => {
timeout = null;
if (!immediate) func(...args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func(...args);
};
}
const optimizedScrollHandler = debounce(() => {
const scrolled = window.pageYOffset;
const navbar = document.querySelector('.navbar');
if (scrolled > 50) {
navbar.style.background = 'rgba(15, 15, 15, 0.98)';
} else {
navbar.style.background = 'rgba(15, 15, 15, 0.95)';
}
}, 10);
window.addEventListener('scroll', optimizedScrollHandler);
let konamiCode = [];
const konamiSequence = [
'ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown',
'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight',
'KeyB', 'KeyA'
];
document.addEventListener('keydown', (e) => {
konamiCode.push(e.code);
if (konamiCode.length > konamiSequence.length) {
konamiCode.shift();
}
if (JSON.stringify(konamiCode) === JSON.stringify(konamiSequence)) {
document.body.style.filter = 'hue-rotate(180deg)';
setTimeout(() => {
document.body.style.filter = 'none';
}, 3000);
const message = document.createElement('div');
message.textContent = '🎮 Hollow Knight would be proud! 🎮';
message.style.cssText = `
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: linear-gradient(135deg, #3F5EFB 0%, #5619B3 100%);
color: white;
padding: 1rem 2rem;
border-radius: 10px;
font-weight: bold;
z-index: 10000;
animation: fadeInUp 0.5s ease;
`;
document.body.appendChild(message);
setTimeout(() => {
message.remove();
}, 3000);
konamiCode = [];
}
});
document.addEventListener('DOMContentLoaded', () => {
detectTheme();
lazyLoadImages();
const heroElements = document.querySelectorAll('.hero-title, .hero-subtitle, .hero-description, .hero-buttons');
heroElements.forEach((el, index) => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = `opacity 0.8s ease ${index * 0.2}s, transform 0.8s ease ${index * 0.2}s`;
setTimeout(() => {
el.style.opacity = '1';
el.style.transform = 'translateY(0)';
}, 500 + (index * 200));
});
});
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
// navigator.serviceWorker.register('/sw.js')
// .then((registration) => {
// console.log('SW registered: ', registration);
// })
// .catch((registrationError) => {
// console.log('SW registration failed: ', registrationError);
// });
});
}