-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
146 lines (124 loc) · 5.32 KB
/
script.js
File metadata and controls
146 lines (124 loc) · 5.32 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
document.addEventListener('DOMContentLoaded', () => {
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
const researchIcon = document.getElementById('research-icon');
const youtubeIcon = document.getElementById('youtube-icon');
const blogIcon = document.getElementById('blog-icon');
const mainHeading = document.querySelector(".hero h1"); // Get heading element
const mainHeading1 = document.querySelector(".hero p"); // Get heading element
const searchInput = document.getElementById("search");
const sendIcon = document.getElementById("send-icon");
// Gradient backgrounds for themes
const lightGradient = "linear-gradient(to right, #E0F7FA, #F1F8FF, #F7F7F7)";
const darkGradient = "linear-gradient(to right, #0F2027, #203A43, #2C5364)";
// Initialize theme from localStorage
const savedTheme = localStorage.getItem('theme');
const isDarkMode = savedTheme === 'dark';
body.classList.toggle('dark-mode', isDarkMode);
setIcons(!isDarkMode);
updateShadow(!isDarkMode);
updateSendIcon();
updateBackground();
themeToggle.addEventListener('click', () => {
const isDark = body.classList.toggle('dark-mode');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
setIcons(!isDark);
updateShadow(!isDark);
updateSendIcon();
updateBackground();
});
// Click animations
document.querySelectorAll('.brand .nav-links a, .youtube-logo, .research-icon, .blog-icon').forEach(item => {
item.addEventListener('click', function () {
this.classList.add('click-animation');
setTimeout(() => {
this.classList.remove('click-animation');
}, 400);
});
});
// Redirect when pressing Enter
searchInput.addEventListener("keypress", function (event) {
if (event.key === "Enter" && searchInput.value.trim() !== "") {
event.preventDefault();
window.location.href = `chat.html?query=${encodeURIComponent(searchInput.value)}`;
}
});
// Redirect when clicking Send Icon
sendIcon.addEventListener("click", function () {
if (searchInput.value.trim() !== "") {
window.location.href = `chat.html?query=${encodeURIComponent(searchInput.value)}`;
}
});
});
// Function to set icons based on theme
function setIcons(isLight) {
const themeToggle = document.getElementById('theme-toggle');
const researchIcon = document.getElementById('research-icon');
const youtubeIcon = document.getElementById('youtube-icon');
const blogIcon = document.getElementById('blog-icon');
const suffix = isLight ? "_lt.png" : "_dk.png";
const basePath = "icon/";
themeToggle.src = `${basePath}${isLight ? "light" : "dark"}.png`;
researchIcon.src = `${basePath}rch${suffix}`;
youtubeIcon.src = `${basePath}yt${suffix}`;
blogIcon.src = `${basePath}blog${suffix}`;
}
// Function to update shadow effect for the main heading
function updateShadow(isLight) {
const mainHeading = document.querySelector(".hero h1");
const mainHeading1 = document.querySelector(".hero p");
if (isLight) {
mainHeading.style.textShadow = "4px 4px 10px rgba(50, 50, 50, 0.6)";
mainHeading1.style.textShadow = "4px 4px 10px rgba(50, 50, 50, 0.6)";
} else {
mainHeading.style.textShadow = "4px 4px 15px rgba(255, 255, 255, 0.6)";
mainHeading1.style.textShadow = "4px 4px 15px rgba(255, 255, 255, 0.6)";
}
}
// Function to update the send icon based on theme
function updateSendIcon() {
const sendIcon = document.getElementById("send-icon");
const isDarkMode = document.body.classList.contains("dark-mode");
sendIcon.src = isDarkMode ? "icon/send_dk.png" : "icon/send_lt.png";
}
// Function to update the background based on theme
function updateBackground() {
const isDarkMode = document.body.classList.contains("dark-mode");
document.body.style.background = isDarkMode
? "linear-gradient(to right,rgb(66, 66, 66),rgb(49, 69, 75),rgb(36, 66, 79))"
: "linear-gradient(to right,rgb(145, 223, 234), #F1F8FF)";
}
// Parallax effect
document.addEventListener('mousemove', (e) => {
const parallaxElements = document.querySelectorAll('.parallax');
parallaxElements.forEach(element => {
const speed = 0.02;
const x = (window.innerWidth - e.pageX * speed) / 100;
const y = (window.innerHeight - e.pageY * speed) / 100;
element.style.transform = `translate(${x}px, ${y}px)`;
});
});
// Scroll animation
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = 1;
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.tech-card').forEach((card) => {
card.style.opacity = 0;
card.style.transform = 'translateY(50px)';
card.style.transition = 'all 0.6s cubic-bezier(0.4, 0, 0.2, 1)';
observer.observe(card);
});
// Navbar scroll effect
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.background = 'rgba(10, 10, 10, 0.95)';
} else {
navbar.style.background = 'rgba(10, 10, 10, 0.9)';
}
});