/* Style each news item as a centered heading */
.news-item {
text-align: stretch;
font-size: 25px;
margin: 15px 0; /* Add spacing between news items */
}
/* Add underlines for the news items */
.news-item a {
text-decoration: bold;
}
/* Style the video container */
.video-container {
margin: 15px 0; /* Add spacing above and below the video */
}
`; // Function to fetch and display news titles async function fetchNews() { try { const response = await fetch(rssFeedUrl); const data = await response.text(); // Parse the RSS feed using DOMParser const parser = new DOMParser(); const xmlDoc = parser.parseFromString(data, 'text/xml'); // Extract the channel information const channel = xmlDoc.querySelector('channel'); const websiteTitle = channel.querySelector('title').textContent; const websiteLink = channel.querySelector('link').textContent; // Extract news items const items = xmlDoc.querySelectorAll('item'); const newsList = document.getElementById('news-list'); // Counter to track news items let count = 0; items.forEach((item) => { count++; // Create a div for each news item (styled as headings) const newsItem = document.createElement('div'); newsItem.classList.add('news-item'); // Create an anchor for the website title const websiteTitleAnchor = document.createElement('a'); websiteTitleAnchor.href = websiteLink; websiteTitleAnchor.textContent = websiteTitle; // Create an anchor for the news title const title = item.querySelector('title').textContent; const link = item.querySelector('link').textContent; const titleAnchor = document.createElement('a'); titleAnchor.href = link; titleAnchor.textContent = title; // Create spans for author and date const author = item.querySelector('dc\\:creator, creator').textContent; const pubDate = new Date(item.querySelector('pubDate').textContent); const authorElem = document.createElement('span'); authorElem.textContent = author; const dateElem = document.createElement('span'); dateElem.textContent = pubDate.toDateString(); // Assemble the news item content newsItem.appendChild(titleAnchor); newsItem.appendChild(document.createElement('br')); // Add a line break newsItem.appendChild(websiteTitleAnchor); newsItem.appendChild(document.createTextNode(' ')); newsItem.appendChild(authorElem); newsItem.appendChild(document.createTextNode(' ')); newsItem.appendChild(dateElem); // Append the news item to the container newsList.appendChild(newsItem); // Display the video after every 3 news items if (count % 2 === 0) { const videoContainer = document.createElement('div'); videoContainer.innerHTML = videoHTML; newsList.appendChild(videoContainer); } }); } catch (error) { console.error('Error fetching and displaying news:', error); } } // Call the function to display news fetchNews();