Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
455 lines (372 loc) · 15.8 KB
/
Copy pathscript.js
File metadata and controls
455 lines (372 loc) · 15.8 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
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
const faqs = document.querySelectorAll(".faqbox")
faqs.forEach((faq) => {
faq.addEventListener("click", () => {
faq.classList.toggle("open")
})
})
const toggle = document.getElementById("theme-toggle");
const toggleBtn = document.getElementById("theme-toggle");
document.addEventListener('DOMContentLoaded', function () {
console.log('DOM loaded, looking for theme toggle...');
const themeIcon = document.getElementById('theme-toggle');
console.log('Theme icon element:', themeIcon);
if (!themeIcon) {
console.error('Theme toggle element not found!');
return;
}
// Force visibility through JavaScript too
themeIcon.style.display = 'block';
themeIcon.style.visibility = 'visible';
themeIcon.style.opacity = '1';
themeIcon.style.width = '24px';
themeIcon.style.height = '24px';
themeIcon.style.zIndex = '10000';
const darkModeIcon = 'darkmode.jpg';
const lightModeIcon = 'lightmode.jpg';
const savedTheme = localStorage.getItem('netflix-theme') || 'dark';
console.log('Saved theme:', savedTheme);
function updateTheme(isLightMode) {
console.log('Updating theme, light mode:', isLightMode);
if (isLightMode) {
themeIcon.src = lightModeIcon;
document.documentElement.classList.add('light-theme');
} else {
themeIcon.src = darkModeIcon;
document.documentElement.classList.remove('light-theme');
}
// Force visibility again after icon change
themeIcon.style.display = 'block';
themeIcon.style.visibility = 'visible';
themeIcon.style.opacity = '1';
}
// Initialize theme
updateTheme(savedTheme === 'light');
// Click event
themeIcon.addEventListener('click', function () {
console.log('Theme icon clicked');
const isLightMode = document.documentElement.classList.contains('light-theme');
if (isLightMode) {
updateTheme(false);
localStorage.setItem('netflix-theme', 'dark');
} else {
updateTheme(true);
localStorage.setItem('netflix-theme', 'light');
}
});
console.log('Theme toggle setup complete');
});
const backToTopBtn = document.getElementById("backToTopBtn")
const circularProgress = document.querySelector(".circular-progress .circle-progress")
const circumference = 2 * Math.PI * 15.9155 // Circumference of the circle (radius 15.9155)
// Set initial dasharray for the circle progress
circularProgress.style.strokeDasharray = `${circumference} ${circumference}`
circularProgress.style.strokeDashoffset = circumference // Start fully hidden
window.addEventListener("scroll", () => {
// Calculate scroll percentage for the circular progress
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
const clientHeight = document.documentElement.clientHeight || document.body.clientHeight
const scrollPercentage = (scrollTop / (scrollHeight - clientHeight)) * 100
// Update the circular progress
const offset = circumference - (scrollPercentage / 100) * circumference
circularProgress.style.strokeDashoffset = offset
// Show/hide back to top button
if (scrollTop > 300) {
backToTopBtn.style.display = "flex"
} else {
backToTopBtn.style.display = "none"
}
const navbar = document.getElementById("navbar")
if (window.scrollY > 50) {
navbar.classList.add("scrolled")
} else {
navbar.classList.remove("scrolled")
}
})
function scrollToTop() {
window.scrollTo({ top: 0, behavior: "smooth" })
}
function handleFormSubmit() {
const emailInputs = document.querySelectorAll('input[type="email"]')
let email = ""
emailInputs.forEach((input) => {
if (input.value) email = input.value
})
if (!email) {
alert("Hey there! 👋 Please enter your email address to get started!")
return
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (!emailRegex.test(email)) {
alert("Oops! 😅 Please enter a valid email address (like: you@example.com)")
return
}
alert(`Awesome! 🎉 Welcome aboard! We'll send updates to ${email}`)
emailInputs.forEach((input) => (input.value = ""))
}
const observerOptions = {
threshold: 0.1,
rootMargin: "0px 0px -100px 0px",
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("animated")
}
})
}, observerOptions)
document.querySelectorAll(".animate-on-scroll").forEach((el) => {
observer.observe(el)
})
document.addEventListener("DOMContentLoaded", () => {
const emailInputs = document.querySelectorAll('input[type="email"]')
emailInputs.forEach((input) => {
input.addEventListener("blur", function () {
const email = this.value
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (email && !emailRegex.test(email)) {
this.classList.add("error")
setTimeout(() => {
this.classList.remove("error")
}, 3000)
}
})
input.addEventListener("input", function () {
this.classList.remove("error")
})
})
})
console.log("🍿 Welcome to Netflix Clone! Made with ❤️ ")
// ========== HAMBURGER MENU FUNCTIONALITY ==========
document.addEventListener('DOMContentLoaded', function() {
const hamburgerMenu = document.getElementById('hamburger-menu');
const mobileNavOverlay = document.getElementById('mobile-nav-overlay');
const body = document.body;
if (hamburgerMenu && mobileNavOverlay) {
// Toggle mobile menu
hamburgerMenu.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
const isActive = hamburgerMenu.classList.contains('active');
if (isActive) {
closeMobileMenu();
} else {
openMobileMenu();
}
});
// Close menu when clicking on overlay
mobileNavOverlay.addEventListener('click', function(e) {
if (e.target === mobileNavOverlay) {
closeMobileMenu();
}
});
// Close menu when clicking on mobile nav links
const mobileNavLinks = document.querySelectorAll('.mobile-nav-links a');
mobileNavLinks.forEach(link => {
link.addEventListener('click', function() {
closeMobileMenu();
});
});
// Close menu with ESC key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && mobileNavOverlay.classList.contains('active')) {
closeMobileMenu();
}
});
// Handle window resize
window.addEventListener('resize', function() {
if (window.innerWidth > 768 && mobileNavOverlay.classList.contains('active')) {
closeMobileMenu();
}
});
function openMobileMenu() {
hamburgerMenu.classList.add('active');
mobileNavOverlay.classList.add('active');
body.style.overflow = 'hidden';
// Add aria attributes for accessibility
hamburgerMenu.setAttribute('aria-expanded', 'true');
mobileNavOverlay.setAttribute('aria-hidden', 'false');
// Focus management
const firstLink = mobileNavOverlay.querySelector('.mobile-nav-links a');
if (firstLink) {
setTimeout(() => firstLink.focus(), 300);
}
}
function closeMobileMenu() {
hamburgerMenu.classList.remove('active');
mobileNavOverlay.classList.remove('active');
body.style.overflow = 'auto';
// Add aria attributes for accessibility
hamburgerMenu.setAttribute('aria-expanded', 'false');
mobileNavOverlay.setAttribute('aria-hidden', 'true');
// Return focus to hamburger button
hamburgerMenu.focus();
}
// Initialize aria attributes
hamburgerMenu.setAttribute('aria-expanded', 'false');
mobileNavOverlay.setAttribute('aria-hidden', 'true');
}
// Mobile language toggle functionality
const mobileLangToggle = document.getElementById('mobile-lang-toggle');
if (mobileLangToggle) {
mobileLangToggle.addEventListener('click', function() {
const currentLang = this.dataset.lang || 'en';
if (currentLang === 'en') {
this.innerHTML = '<i class="fas fa-globe"></i> हिन्दी';
this.dataset.lang = 'hi';
} else {
this.innerHTML = '<i class="fas fa-globe"></i> English';
this.dataset.lang = 'en';
}
});
}
});
// ========== ENHANCED TOUCH SUPPORT ==========
// Add touch event support for better mobile experience
document.addEventListener('DOMContentLoaded', function() {
// Add touch feedback to buttons
const buttons = document.querySelectorAll('.btn, .btn-red, .btn-red-sm, .faq-header');
buttons.forEach(button => {
button.addEventListener('touchstart', function() {
this.style.transform = 'scale(0.98)';
}, { passive: true });
button.addEventListener('touchend', function() {
this.style.transform = '';
}, { passive: true });
});
// Prevent zoom on double tap for form inputs
const inputs = document.querySelectorAll('input[type="email"]');
inputs.forEach(input => {
input.addEventListener('touchend', function(e) {
e.preventDefault();
this.focus();
}, { passive: false });
});
});
// Loading Animation with Netflix Intro
document.addEventListener('DOMContentLoaded', function () {
const loadingScreen = document.getElementById('loadingScreen');
const body = document.body;
if (loadingScreen) {
// Prevent scrolling during loading
body.style.overflow = 'hidden';
// Listen for message from iframe when animation completes
window.addEventListener('message', function (event) {
if (event.data === 'netflix-animation-complete') {
// Fade out loading screen
loadingScreen.classList.add('fade-out');
body.style.overflow = 'auto';
// Remove loading screen after fade
setTimeout(() => {
if (loadingScreen && loadingScreen.parentNode) {
loadingScreen.remove();
}
}, 800);
}
});
// Fallback timeout in case message doesn't come through
setTimeout(() => {
if (loadingScreen && loadingScreen.parentNode) {
loadingScreen.classList.add('fade-out');
body.style.overflow = 'auto';
setTimeout(() => {
if (loadingScreen && loadingScreen.parentNode) {
loadingScreen.remove();
}
}, 800);
}
}, 5500); // 5.5 seconds fallback
}
});
document.addEventListener("DOMContentLoaded", function () {
const currentUser = localStorage.getItem("netflixCurrentUser");
const homeLink = document.querySelector('a[href="home.html"]');
if (!currentUser && homeLink) {
homeLink.addEventListener("click", function (e) {
e.preventDefault();
alert("Please sign in to access Home.");
window.location.href = "index.html";
});
}
});
function setLanguage(lang) {
const elements = document.querySelectorAll('[data-i18n]');
elements.forEach(el => {
const key = el.getAttribute('data-i18n');
if (translations[lang] && translations[lang][key]) {
el.textContent = translations[lang][key];
}
});
}
// Optional: Set default language to English on page load
document.addEventListener('DOMContentLoaded', () => setLanguage('en'));
// Toggle button listener
document.querySelector("#lang-toggle").addEventListener("click", function () {
const currentLang = this.getAttribute("data-lang");
const newLang = currentLang === "en" ? "hi" : "en";
setLanguage(newLang);
this.setAttribute("data-lang", newLang);
this.innerHTML = newLang === "en" ? `<i class="fas fa-globe"></i> English` : `<i class="fas fa-globe"></i> हिन्दी`;
});
// Language data
const translations = {
en: {
"faq_heading": "Frequently Asked Questions",
"faq_q1": "What is Netflix?",
"faq_a1": "Netflix is a streaming service that offers award-winning TV shows, movies, anime, documentaries, and more.",
"faq_q2": "How much does Netflix cost?",
"faq_a2": "Netflix plans range from ₹149 to ₹649 per month. You can watch on your phone, tablet, TV, laptop, and more.",
"faq_q3": "What can I watch on Netflix?",
"faq_a3": "You can watch movies, TV shows, anime, Netflix originals, and much more on Netflix.",
"faq_q4": "Where can I watch?",
"faq_a4": "You can watch Netflix on any internet-connected device — mobile, laptop, TV, or computer.",
"faq_q5": "Is Netflix good for kids?",
"faq_a5": "The Netflix Kids experience provides parental controls while offering family-friendly content for children.",
"faq_cta": "Ready to watch? Enter your email to create or restart your membership."
},
hi: {
faq_heading: "अक्सर पूछे जाने वाले प्रश्न",
faq_q1: "नेटफ्लिक्स क्या है?",
faq_a1: "नेटफ्लिक्स एक स्ट्रीमिंग सेवा है जो पुरस्कार विजेता टीवी शो, फिल्में, एनीमे, वृत्तचित्र और बहुत कुछ प्रदान करती है।",
faq_heading: "अक्सर पूछे जाने वाले सवाल",
faq_q1: "Netflix क्या है?",
faq_a1: "Netflix एक स्ट्रीमिंग सेवा है जो टीवी शो, फिल्में, एनीमे, डोक्यूमेंट्री और बहुत कुछ प्रदान करती है।",
faq_q2: "Netflix की कीमत कितनी है?",
faq_a2: "Netflix की योजनाएं ₹149 से ₹649 प्रति माह तक हैं। आप अपने फ़ोन, टैबलेट, टीवी, लैपटॉप आदि पर देख सकते हैं।",
faq_q3: "मैं Netflix पर क्या देख सकता हूँ?",
faq_a3: "Netflix पर आपको फिल्में, टीवी शो, एनीमे, नेटफ्लिक्स ओरिजिनल्स और बहुत कुछ देखने को मिलेगा।",
faq_q4: "मैं कहां देख सकता हूँ?",
faq_a4: "आप किसी भी इंटरनेट से जुड़े डिवाइस पर Netflix देख सकते हैं — मोबाइल, लैपटॉप, टीवी, या कंप्यूटर पर।",
faq_q5: "क्या Netflix बच्चों के लिए अच्छा है?",
faq_a5: "Netflix Kids अनुभव माता-पिता को नियंत्रण देते हुए बच्चों को परिवार के अनुकूल सामग्री प्रदान करता है।",
faq_cta: "देखना शुरू करें? अपनी ईमेल दर्ज करें और सदस्यता शुरू करें।"
}
};
let currentLang = 'en';
function switchLanguage() {
// Toggle between 'en' and 'hi'
currentLang = currentLang === 'en' ? 'hi' : 'en';
// Get correct language content
const langData = translations[currentLang];
// Update all translatable elements
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.getAttribute('data-i18n');
if (langData[key]) {
el.textContent = langData[key];
}
});
// Update button text
const btn = document.getElementById('lang-btn');
btn.textContent = currentLang === 'en' ? '🌐 हिंदी' : '🌐 English';
}
//FAQ plus icon toggle to cross when ans opens
document.querySelectorAll('.faq-header').forEach(header => {
header.addEventListener('click', () => {
const icon = header.querySelector('.faq-plus-icon');
const answer = header.nextElementSibling;
// toggle icon
icon.textContent = icon.textContent === '+' ? '×' : '+';
// toggle answer visibility
answer.classList.toggle('show');
});
});