Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Theme toggling
+ const themeToggle = document.querySelector('.theme-toggle');
+ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
+
+ function setTheme(isDark) {
+ document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
+ themeToggle.textContent = isDark ? '☀️' : '🌙';
+ }
+
+ setTheme(prefersDark.matches);
+
+ themeToggle.addEventListener('click', () => {
+ const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
+ setTheme(!isDark);
+ });
+
+ // Mock market data
+ function updateMarketData() {
+ const markets = ['sp500', 'nasdaq', 'djia', 'btc'];
+ markets.forEach(market => {
+ const card = document.getElementById(market);
+ const value = card.querySelector('.value');
+ const change = card.querySelector('.change');
+
+ // Generate random values
+ const currentValue = (Math.random() * 1000).toFixed(2);
+ const changePercent = (Math.random() * 4 - 2).toFixed(2);
+
+ value.textContent = `$${currentValue}`;
+ change.textContent = `${changePercent}%`;
+ change.className = `change ${changePercent >= 0 ? 'positive' : 'negative'}`;
+ });
+ }
+
+ // Initial update and interval
+ updateMarketData();
+ setInterval(updateMarketData, 60000);
+
+ // Simple chart
+ const ctx = document.getElementById('marketChart').getContext('2d');
+
+ function drawChart() {
+ const width = ctx.canvas.width;
+ const height = ctx.canvas.height;
+
+ ctx.clearRect(0, 0, width, height);
+ ctx.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--primary');
+ ctx.lineWidth = 2;
+
+ ctx.beginPath();
+ ctx.moveTo(0, height/2);
+
+ for(let x = 0; x < width; x++) {
+ const y = height/2 + Math.sin(x/30) * 50 + Math.random() * 20;
+ ctx.lineTo(x, y);
+ }
+
+ ctx.stroke();
+ }
+
+ // Responsive chart
+ function resizeChart() {
+ const container = document.querySelector('.chart-container');
+ ctx.canvas.width = container.offsetWidth - 32;
+ ctx.canvas.height = container.offsetHeight - 32;
+ drawChart();
+ }
+
+ window.addEventListener('resize', resizeChart);
+ resizeChart();
+ });