// GNews API key and keywords const apiKey = 'ba80327ee808107950ed733e783b2c3a'; const keywords = 'ESKD,ESRD,Kidney Disease,Renal Disease,Kidney Transplant,Dialysis'; const apiUrl = `https://gnews.io/api/v4/search?q=${encodeURIComponent(keywords)}&lang=en&from=${getPastDate()}&token=${apiKey}&max=10`; // Helper function to get the date 7 days ago in yyyy-mm-dd format function getPastDate() { const date = new Date(); date.setDate(date.getDate() - 7); return date.toISOString().split('T')[0]; } // Fetch data from GNews API fetch(apiUrl) .then(response => { if (!response.ok) { throw new Error(`Network response was not ok: ${response.statusText}`); } return response.json(); }) .then(data => { if (data.articles && data.articles.length > 0) { displayNews(data.articles); } else { throw new Error("No articles found in response data"); } }) .catch(error => { console.error('Error fetching data:', error); document.getElementById('news-container').innerHTML = '
Unable to load news articles at this time.
'; }); // Display news articles function displayNews(articles) { const newsContainer = document.getElementById('news-container'); newsContainer.innerHTML = ''; // Clear any existing content articles.forEach(article => { const articleElement = document.createElement('div'); articleElement.style.marginBottom = '10px'; // Use innerText for plain text and anchor element for the link articleElement.innerHTML = `${new Date(article.publishedAt).toLocaleDateString()} - ${article.title}
`; newsContainer.appendChild(articleElement); }); }