-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
282 lines (242 loc) · 8.71 KB
/
Copy pathscript.js
File metadata and controls
282 lines (242 loc) · 8.71 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
/* ========================================
GuideVault — JavaScript
The Prank: Search redirects to Google
======================================== */
// ========================================
// Particles Background
// ========================================
function createParticles() {
const container = document.getElementById('particles');
const colors = ['#667eea', '#764ba2', '#f093fb', '#4facfe', '#43e97b'];
const particleCount = 25;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
const size = Math.random() * 4 + 2;
const color = colors[Math.floor(Math.random() * colors.length)];
const left = Math.random() * 100;
const duration = Math.random() * 15 + 15;
const delay = Math.random() * 20;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
particle.style.background = color;
particle.style.left = `${left}%`;
particle.style.animationDuration = `${duration}s`;
particle.style.animationDelay = `${delay}s`;
container.appendChild(particle);
}
}
// ========================================
// Navbar Scroll Effect
// ========================================
function handleNavbarScroll() {
const navbar = document.getElementById('navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
}
// ========================================
// Mobile Menu
// ========================================
function toggleMobileMenu() {
const menu = document.getElementById('mobileMenu');
const btn = document.getElementById('mobileMenuBtn');
menu.classList.toggle('active');
btn.classList.toggle('active');
document.body.style.overflow = menu.classList.contains('active') ? 'hidden' : '';
}
// ========================================
// Search Functions (THE PRANK!)
// ========================================
function performSearch() {
const input = document.getElementById('searchInput');
const query = input.value.trim();
if (!query) {
// Shake animation if empty
input.style.animation = 'none';
input.offsetHeight; // trigger reflow
input.style.animation = 'shake 0.5s ease';
input.placeholder = 'Ketik sesuatu dulu ya... 😅';
setTimeout(() => {
input.placeholder = 'Cari guidebook lomba... (cth: GEMASTIK, PKM, Hackathon)';
}, 2000);
return;
}
showLoadingAndRedirect(query, 'searchBtn');
}
function performSearchBottom() {
const input = document.getElementById('searchInputBottom');
const query = input.value.trim();
if (!query) {
input.style.animation = 'none';
input.offsetHeight;
input.style.animation = 'shake 0.5s ease';
input.placeholder = 'Ketik sesuatu dulu ya... 😅';
setTimeout(() => {
input.placeholder = 'Ketik nama lomba atau topik guidebook...';
}, 2000);
return;
}
showLoadingAndRedirect(query, null);
}
function searchFromTag(tagElement) {
const query = tagElement.textContent.trim();
document.getElementById('searchInput').value = query;
showLoadingAndRedirect(query, 'searchBtn');
}
function searchCategory(query) {
showLoadingAndRedirect(query, null);
}
function showLoadingAndRedirect(query, btnId) {
// Add "Guidebook" to the search query for Google to make it seem legit
const searchQuery = `Guidebook ${query}`;
const googleUrl = `https://www.google.com/search?q=${encodeURIComponent(searchQuery)}`;
// Show loading state
if (btnId) {
const btn = document.getElementById(btnId);
const originalHTML = btn.innerHTML;
btn.innerHTML = `
<svg class="spinner" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
<circle cx="12" cy="12" r="10" stroke-opacity="0.3"/>
<path d="M12 2a10 10 0 0 1 10 10" stroke-linecap="round"/>
</svg>
<span>Mencari...</span>
`;
btn.style.pointerEvents = 'none';
}
// Simulate "loading" for realism, then redirect to Google
setTimeout(() => {
window.location.href = googleUrl;
}, 1200);
}
// ========================================
// Scroll to Search
// ========================================
function scrollToSearch() {
const searchBox = document.getElementById('searchBox');
searchBox.scrollIntoView({ behavior: 'smooth', block: 'center' });
setTimeout(() => {
document.getElementById('searchInput').focus();
}, 600);
}
// ========================================
// FAQ Toggle
// ========================================
function toggleFaq(element) {
const isActive = element.classList.contains('active');
// Close all FAQ items
document.querySelectorAll('.faq-item').forEach(item => {
item.classList.remove('active');
});
// Toggle the clicked one
if (!isActive) {
element.classList.add('active');
}
}
// ========================================
// Counter Animation
// ========================================
function animateCounters() {
const counters = document.querySelectorAll('.stat-number');
counters.forEach(counter => {
const target = parseInt(counter.getAttribute('data-target'));
const duration = 2000;
const step = target / (duration / 16);
let current = 0;
const timer = setInterval(() => {
current += step;
if (current >= target) {
current = target;
clearInterval(timer);
}
counter.textContent = Math.floor(current).toLocaleString('id-ID');
}, 16);
});
}
// ========================================
// Scroll Reveal
// ========================================
function setupScrollReveal() {
const revealElements = document.querySelectorAll(
'.feature-card, .category-card, .section-header, .cta-card, .faq-item, .stats-grid'
);
revealElements.forEach(el => el.classList.add('reveal'));
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.classList.add('visible');
}, index * 80);
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
revealElements.forEach(el => observer.observe(el));
}
// ========================================
// Stats Section Counter on Scroll
// ========================================
function setupStatsObserver() {
const statsSection = document.getElementById('stats');
let hasAnimated = false;
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !hasAnimated) {
hasAnimated = true;
animateCounters();
}
});
}, { threshold: 0.3 });
observer.observe(statsSection);
}
// ========================================
// Keyboard Support (Enter to search)
// ========================================
function setupKeyboardEvents() {
document.getElementById('searchInput').addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
performSearch();
}
});
document.getElementById('searchInputBottom').addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
performSearchBottom();
}
});
}
// ========================================
// Shake Animation (for empty search)
// ========================================
const style = document.createElement('style');
style.textContent = `
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
20%, 40%, 60%, 80% { transform: translateX(4px); }
}
.spinner {
animation: spin 0.8s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
`;
document.head.appendChild(style);
// ========================================
// Initialize Everything
// ========================================
document.addEventListener('DOMContentLoaded', () => {
createParticles();
handleNavbarScroll();
setupScrollReveal();
setupStatsObserver();
setupKeyboardEvents();
});