Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const searchInput = document.getElementById('searchInput');
+ const resultsContainer = document.getElementById('resultsContainer');
+ const graphContainer = document.getElementById('graphContainer');
+
+ // Sample data for demo purposes
+ const sampleArticles = [
+ {
+ title: "Global Climate Summit Reaches New Agreement",
+ source: "World News",
+ date: "2023-11-15",
+ summary: "World leaders have agreed on new emissions targets at the latest climate summit.",
+ topics: ["climate", "politics", "environment"]
+ },
+ {
+ title: "Scientists Warn of Accelerating Climate Change",
+ source: "Science Daily",
+ date: "2023-11-10",
+ summary: "New research shows climate change impacts are happening faster than predicted.",
+ topics: ["climate", "science", "environment"]
+ },
+ {
+ title: "Renewable Energy Investments Reach Record High",
+ source: "Business Times",
+ date: "2023-11-05",
+ summary: "Global investments in renewable energy sources have doubled in the past year.",
+ topics: ["energy", "business", "climate"]
+ }
+ ];
+
+ // Demo search functionality
+ searchInput.addEventListener('input', function(e) {
+ const query = e.target.value.toLowerCase();
+
+ if (query.length > 2) {
+ const filtered = sampleArticles.filter(article =>
+ article.title.toLowerCase().includes(query) ||
+ article.topics.some(topic => topic.includes(query))
+
+ displayResults(filtered);
+ visualizeConnections(filtered);
+ } else {
+ resultsContainer.innerHTML = '
Enter at least 3 characters to search
';
+ graphContainer.innerHTML = '';
+ }
+ });
+
+ function displayResults(articles) {
+ if (articles.length === 0) {
+ resultsContainer.innerHTML = '
No articles found. Try a different search term.
';
+ return;
+ }
+
+ let html = '
';
+ articles.forEach(article => {
+ html += `
+
+
${article.title}
+
+ ${article.source}
+ ${article.date}
+
+
+ ${article.topics.map(topic => `${topic}`).join('')}
+
+
+ `;
+ });
+ html += '
';
+
+ resultsContainer.innerHTML = html;
+ }
+
+ function visualizeConnections(articles) {
+ if (articles.length === 0) return;
+
+ // Simple visualization for demo
+ let html = '
';
+ html += '
Topic Connections
';+ html += '
';
+
+ // Collect all unique topics
+ const allTopics = [...new Set(articles.flatMap(article => article.topics))];
+
+ // Create nodes
+ allTopics.forEach(topic => {
+ const relatedArticles = articles.filter(a => a.topics.includes(topic)).length;
+ const size = Math.min(100, 30 + (relatedArticles * 20));
+
+ html += `
+ `;
+ });
+
+ html += '
';
+ graphContainer.innerHTML = html;
+ }
+
+ // Initialize with some sample data
+ resultsContainer.innerHTML = '
Enter a search term to find connected articles
';
+ });