-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
378 lines (324 loc) · 12.2 KB
/
script.js
File metadata and controls
378 lines (324 loc) · 12.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
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
// Theme Toggle Logic
const html = document.documentElement;
const modeLightBtn = document.getElementById('modeLight');
const modeDarkBtn = document.getElementById('modeDark');
// Check for saved theme preference or default to dark mode
const currentTheme = localStorage.getItem('theme') || 'dark';
function setTheme(theme) {
if (theme === 'dark') {
html.classList.add('dark');
modeDarkBtn.classList.add('active');
modeLightBtn.classList.remove('active');
} else {
html.classList.remove('dark');
modeLightBtn.classList.add('active');
modeDarkBtn.classList.remove('active');
}
localStorage.setItem('theme', theme);
}
// Initial Set
setTheme(currentTheme);
// Event Listeners
modeLightBtn.addEventListener('click', () => setTheme('light'));
modeDarkBtn.addEventListener('click', () => setTheme('dark'));
// Smooth scroll for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // Account for fixed navbar
const targetPosition = target.offsetTop - offset;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Intersection Observer for fade-in animations
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)';
}
});
}, observerOptions);
// Observe feature cards
document.querySelectorAll('.feature-card').forEach((card, index) => {
card.style.opacity = '0';
card.style.transform = 'translateY(30px)';
card.style.transition = `opacity 0.6s ease ${index * 0.1}s, transform 0.6s ease ${index * 0.1}s`;
observer.observe(card);
});
// Navbar background on scroll
let lastScroll = 0;
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = 'none';
}
lastScroll = currentScroll;
});
// Parallax effect for hero background
window.addEventListener('scroll', () => {
const heroBackground = document.querySelector('.hero-background');
if (heroBackground) {
const scrolled = window.pageYOffset;
const rate = scrolled * 0.5;
heroBackground.style.transform = `translateY(${rate}px)`;
}
});
// Add hover effect to stat items
document.querySelectorAll('.stat-item').forEach(stat => {
stat.addEventListener('mouseenter', () => {
stat.style.transform = 'scale(1.05)';
stat.style.transition = 'transform 0.3s ease';
});
stat.addEventListener('mouseleave', () => {
stat.style.transform = 'scale(1)';
});
});
// Animate numbers in stats
const animateValue = (element, start, end, duration) => {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
const value = Math.floor(progress * (end - start) + start);
element.textContent = value + '+';
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
};
// Observe stats section for number animation
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statValue = entry.target.querySelector('.stat-value');
if (statValue && statValue.textContent.includes('+')) {
const targetValue = parseInt(statValue.textContent);
if (!isNaN(targetValue)) {
animateValue(statValue, 0, targetValue, 2000);
}
}
statsObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.stat-item').forEach(stat => {
statsObserver.observe(stat);
});
// Add ripple effect to buttons
document.querySelectorAll('.btn').forEach(button => {
button.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.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
// Add ripple styles dynamically
const style = document.createElement('style');
style.textContent = `
.btn {
position: relative;
overflow: hidden;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);
// Cursor trail effect (subtle)
let mouseX = 0;
let mouseY = 0;
let cursorX = 0;
let cursorY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
// Easter egg: Konami code
let konamiCode = [];
const konamiSequence = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
document.addEventListener('keydown', (e) => {
konamiCode.push(e.key);
konamiCode = konamiCode.slice(-10);
if (konamiCode.join(',') === konamiSequence.join(',')) {
// Activate special effect
document.body.style.animation = 'rainbow 2s linear infinite';
setTimeout(() => {
document.body.style.animation = '';
}, 5000);
}
});
const rainbowStyle = document.createElement('style');
rainbowStyle.textContent = `
@keyframes rainbow {
0% { filter: hue-rotate(0deg); }
100% { filter: hue-rotate(360deg); }
}
`;
document.head.appendChild(rainbowStyle);
// Log a welcome message
console.log('%cMTech Toolkit', 'font-size: 2rem; font-weight: bold; background: linear-gradient(135deg, #3b82f6 0%, #a855f7 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;');
console.log('%cWelcome to the MTech Toolkit website!', 'font-size: 1rem; color: #3b82f6;');
console.log('Built with ❤️ for Windows power users');
// Theme Customization Logic
const customizeToggle = document.getElementById('customizeToggle');
const themePanel = document.getElementById('themePanel');
const closePanel = document.getElementById('closePanel');
const primaryColorPicker = document.getElementById('primaryColorPicker');
const secondaryColorPicker = document.getElementById('secondaryColorPicker');
const singleColorModeCheckbox = document.getElementById('singleColorMode');
const resetThemeButton = document.getElementById('resetTheme');
const root = document.documentElement;
// Theme State
let themeState = {
primary: '#3b82f6',
secondary: '#ffa500',
singleMode: false
};
// Utils
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ?
`${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}`
: null;
}
function adjustColorBrightness(hex, percent) {
const num = parseInt(hex.replace('#', ''), 16);
const amt = Math.round(2.55 * percent);
const R = (num >> 16) + amt;
const G = (num >> 8 & 0x00FF) + amt;
const B = (num & 0x0000FF) + amt;
return '#' + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 + (G < 255 ? G < 1 ? 0 : G : 255) * 0x100 + (B < 255 ? B < 1 ? 0 : B : 255)).toString(16).slice(1);
}
function updateThemeColors() {
const primaryRgb = hexToRgb(themeState.primary);
const secondaryRgb = hexToRgb(themeState.secondary);
// Calculate dark variants
const primaryDark = adjustColorBrightness(themeState.primary, -20);
const secondaryDark = adjustColorBrightness(themeState.secondary, -20);
const primaryDarkRgb = hexToRgb(primaryDark);
const secondaryDarkRgb = hexToRgb(secondaryDark);
// Apply colors
root.style.setProperty('--color-primary', primaryRgb);
root.style.setProperty('--color-primary-dark', primaryDarkRgb);
root.style.setProperty('--color-secondary', secondaryRgb);
root.style.setProperty('--color-secondary-dark', secondaryDarkRgb);
// Persist
localStorage.setItem('themeCustomization', JSON.stringify(themeState));
}
// Event Listeners
customizeToggle.addEventListener('click', () => {
themePanel.classList.add('active');
});
closePanel.addEventListener('click', () => {
themePanel.classList.remove('active');
});
// Click outside to close
document.addEventListener('click', (e) => {
if (themePanel.classList.contains('active') &&
!themePanel.contains(e.target) &&
!customizeToggle.contains(e.target)) {
themePanel.classList.remove('active');
}
});
primaryColorPicker.addEventListener('input', (e) => {
themeState.primary = e.target.value;
if (themeState.singleMode) {
themeState.secondary = themeState.primary;
secondaryColorPicker.value = themeState.primary;
secondaryColorPicker.disabled = true;
}
updateThemeColors();
});
secondaryColorPicker.addEventListener('input', (e) => {
themeState.secondary = e.target.value;
if (themeState.singleMode) {
// If user manually changes secondary while in single mode, disable single mode
themeState.singleMode = false;
singleColorModeCheckbox.checked = false;
secondaryColorPicker.disabled = false;
}
updateThemeColors();
});
singleColorModeCheckbox.addEventListener('change', (e) => {
themeState.singleMode = e.target.checked;
if (themeState.singleMode) {
themeState.secondary = themeState.primary;
secondaryColorPicker.value = themeState.primary;
secondaryColorPicker.disabled = true;
} else {
secondaryColorPicker.disabled = false;
// Optional: restore default secondary or last known?
// For now, let it stay as is until user changes it or resets.
}
updateThemeColors();
});
resetThemeButton.addEventListener('click', () => {
themeState = {
primary: '#3b82f6',
secondary: '#ffa500',
singleMode: false
};
primaryColorPicker.value = themeState.primary;
secondaryColorPicker.value = themeState.secondary;
singleColorModeCheckbox.checked = false;
secondaryColorPicker.disabled = false;
updateThemeColors();
});
// Load Saved Customization
function loadSavedTheme() {
const saved = localStorage.getItem('themeCustomization');
if (saved) {
try {
const parsed = JSON.parse(saved);
themeState = { ...themeState, ...parsed }; // Merge to ensure fields exist
// Update Inputs
primaryColorPicker.value = themeState.primary;
secondaryColorPicker.value = themeState.secondary;
singleColorModeCheckbox.checked = themeState.singleMode;
if (themeState.singleMode) {
secondaryColorPicker.disabled = true;
}
updateThemeColors();
} catch (e) {
console.error('Failed to load theme customization', e);
}
}
}
// Init
loadSavedTheme();