Files
Overlays/rss_ticker_overlay/rss_ticker.html

139 lines
4.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RSS Ticker Overlay</title>
<style>
body {
font-family: sans-serif;
color: white;
background-color: rgba(0, 0, 0, 0.5);
padding: 10px;
border-radius: 5px;
overflow: hidden; /* Hide scrollbar */
}
#ticker-container {
white-space: nowrap;
overflow: hidden;
box-sizing: border-box;
width: 100%;
}
#ticker-content {
display: inline-block;
padding-left: 100%; /* Start off-screen */
animation: ticker-scroll 30s linear infinite;
}
@keyframes ticker-scroll {
0% { transform: translate3d(0, 0, 0); }
100% { transform: translate3d(-100%, 0, 0); }
}
#rss-input-container {
background-color: rgba(0, 0, 0, 0.7);
border: 1px solid white;
padding: 10px;
margin-top: 20px;
z-index: 100;
}
#rss-url-input {
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
width: 70%;
}
#update-rss-button {
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
</style>
</head>
<body>
<div id="ticker-container">
<span id="ticker-content">Loading RSS feed...</span>
</div>
<div id="rss-input-container">
<input type="text" id="rss-url-input" placeholder="Enter RSS Feed URL">
<button id="update-rss-button">Update RSS</button>
<button id="reset-rss-button">Reset</button>
</div>
<script>
const defaultRssUrl = "https://www.nasa.gov/news-release/feed/"; // Default NASA news feed
function fetchRssFeed(rssUrl) {
console.log('Fetching RSS feed:', rssUrl);
const corsProxy = "http://localhost:8001/proxy?url=";
const url = `${corsProxy}${encodeURIComponent(rssUrl)}`;
fetch(url)
.then(response => {
console.log('Proxy response:', response);
if (response.ok) return response.json();
throw new Error('Network response was not ok.');
})
.then(data => {
console.log('Raw data from proxy:', data);
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(data.contents, "text/xml");
console.log('Parsed XML Doc:', xmlDoc);
const items = xmlDoc.querySelectorAll("item");
let headlines = [];
items.forEach(item => {
const titleElement = item.querySelector("title");
if (titleElement) {
headlines.push(titleElement.textContent);
}
});
if (headlines.length > 0) {
document.getElementById('ticker-content').textContent = headlines.join(" | ");
} else {
document.getElementById('ticker-content').textContent = "No headlines found in feed.";
}
})
.catch(error => {
console.error('Error fetching RSS feed:', error);
document.getElementById('ticker-content').textContent = "Error loading RSS feed.";
});
}
function saveRssUrl(rssUrl) {
localStorage.setItem('rss_feed_url', rssUrl);
}
function loadRssUrl() {
return localStorage.getItem('rss_feed_url');
}
document.getElementById('update-rss-button').addEventListener('click', () => {
const rssUrl = document.getElementById('rss-url-input').value;
if (rssUrl) {
saveRssUrl(rssUrl);
fetchRssFeed(rssUrl);
document.getElementById('rss-input-container').style.display = 'none';
}
});
document.getElementById('reset-rss-button').addEventListener('click', () => {
localStorage.removeItem('rss_feed_url');
document.getElementById('rss-input-container').style.display = 'block';
document.getElementById('rss-url-input').value = '';
document.getElementById('ticker-content').textContent = "Loading RSS feed...";
});
// Initial load
const storedRssUrl = loadRssUrl();
if (storedRssUrl) {
fetchRssFeed(storedRssUrl);
document.getElementById('rss-input-container').style.display = 'none';
} else {
fetchRssFeed(defaultRssUrl);
}
</script>
</body>
</html>