// Global configuration const config = { apiBaseUrl: "https://mr-v-api.example.com", enableTracking: true, defaultTheme: "dark" }; // Initialize tooltips document.addEventListener('DOMContentLoaded', function() { // Initialize any tooltips or popovers if (typeof tippy !== 'undefined') { tippy('[data-tippy-content]', { arrow: true, animation: 'scale', theme: 'red', }); } // Track page view if (config.enableTracking) { trackPageView(); } }); // Track page view for analytics function trackPageView() { console.log("Tracking page view..."); // In a real implementation, this would send data to analytics service } // Handle theme switching function toggleTheme() { const html = document.documentElement; if (html.classList.contains('dark')) { html.classList.remove('dark'); localStorage.setItem('theme', 'light'); } else { html.classList.add('dark'); localStorage.setItem('theme', 'dark'); } } // Check for saved theme preference function checkTheme() { const savedTheme = localStorage.getItem('theme') || config.defaultTheme; if (savedTheme === 'dark') { document.documentElement.classList.add('dark'); } else { document.documentElement.classList.remove('dark'); } } // Initialize theme on page load checkTheme(); // Utility function for API calls async function makeApiRequest(endpoint, data = {}) { try { const response = await fetch(`${config.apiBaseUrl}${endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data) }); return await response.json(); } catch (error) { console.error('API request failed:', error); return { success: false, error: error.message }; } } // Export functions for use in other components export { makeApiRequest, toggleTheme };