52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
// main.js
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const themeToggle = document.getElementById('theme-toggle');
|
|
const currentTheme = localStorage.getItem('theme');
|
|
|
|
if (currentTheme === 'dark') {
|
|
document.body.classList.add('dark-mode');
|
|
themeToggle.innerHTML = '<i class="bi bi-sun-fill"></i>';
|
|
} else {
|
|
themeToggle.innerHTML = '<i class="bi bi-moon-fill"></i>';
|
|
}
|
|
|
|
themeToggle.addEventListener('click', () => {
|
|
document.body.classList.toggle('dark-mode');
|
|
let theme = 'light';
|
|
if (document.body.classList.contains('dark-mode')) {
|
|
theme = 'dark';
|
|
themeToggle.innerHTML = '<i class="bi bi-sun-fill"></i>';
|
|
} else {
|
|
themeToggle.innerHTML = '<i class="bi bi-moon-fill"></i>';
|
|
}
|
|
localStorage.setItem('theme', theme);
|
|
});
|
|
|
|
const animatedElements = document.querySelectorAll('.floating-card');
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('is-visible');
|
|
observer.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, { threshold: 0.1 });
|
|
|
|
animatedElements.forEach(el => {
|
|
observer.observe(el);
|
|
});
|
|
});
|
|
|
|
function openChatWidget() {
|
|
// This function attempts to open the chat widget.
|
|
// The AnyChat script might create a global object to control the widget.
|
|
if (typeof AnyChat !== 'undefined' && AnyChat.open) {
|
|
AnyChat.open();
|
|
} else {
|
|
console.log('Chat widget function not found. The widget might open automatically or requires a different function call.');
|
|
// As a fallback, we can try to find the launcher button and click it.
|
|
const chatLauncher = document.getElementById('anychat-launcher'); // This ID is a guess
|
|
if(chatLauncher) chatLauncher.click();
|
|
}
|
|
}
|