Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const newsContainer = document.getElementById('news-container');
+ const searchInput = document.getElementById('search');
+ const filterChips = document.querySelectorAll('.chip');
+ const themeToggle = document.querySelector('.theme-toggle');
+
+ let currentFilter = 'all';
+ let newsData = [];
+
+ // Fetch and display news
+ async function fetchNews() {
+ // Simulated news data - in production, this would fetch from an API
+ newsData = [
+ {
+ title: 'New Solar Technology Breakthrough',
+ category: 'renewables',
+ description: 'Scientists develop high-efficiency solar panels...',
+ image: 'solar-panel.jpg'
+ },
+ {
+ title: 'AI Model Predicts Climate Patterns',
+ category: 'ai',
+ description: 'Advanced AI system helps forecast weather...',
+ image: 'ai-climate.jpg'
+ },
+ // Add more news items here
+ ];
+
+ renderNews();
+ }
+
+ function renderNews() {
+ const filteredNews = newsData.filter(item => {
+ const matchesFilter = currentFilter === 'all' || item.category === currentFilter;
+ const matchesSearch = item.title.toLowerCase().includes(searchInput.value.toLowerCase());
+ return matchesFilter && matchesSearch;
+ });
+
+ newsContainer.innerHTML = filteredNews.map(item => `
+
+
+ `).join('');
+ }
+
+ // Event Listeners
+ filterChips.forEach(chip => {
+ chip.addEventListener('click', () => {
+ filterChips.forEach(c => c.classList.remove('active'));
+ chip.classList.add('active');
+ currentFilter = chip.dataset.filter;
+ renderNews();
+ });
+ });
+
+ searchInput.addEventListener('input', renderNews);
+
+ themeToggle.addEventListener('click', () => {
+ document.documentElement.setAttribute('data-theme',
+ document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark'
+ );
+ });
+
+ // Initialize
+ fetchNews();
+ });