feat: Add RSS Ticker Overlay
This commit is contained in:
120
rss_ticker_overlay/rss_ticker.html
Normal file
120
rss_ticker_overlay/rss_ticker.html
Normal file
@@ -0,0 +1,120 @@
|
||||
<!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>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
const defaultRssUrl = "https://www.nasa.gov/news-release/feed/"; // Default NASA news feed
|
||||
|
||||
function fetchRssFeed(rssUrl) {
|
||||
const corsProxy = "https://api.allorigins.win/get?url=";
|
||||
const url = `${corsProxy}${encodeURIComponent(rssUrl)}`;
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) return response.json();
|
||||
throw new Error('Network response was not ok.');
|
||||
})
|
||||
.then(data => {
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(data.contents, "text/xml");
|
||||
const items = xmlDoc.querySelectorAll("item");
|
||||
let headlines = [];
|
||||
items.forEach(item => {
|
||||
headlines.push(item.querySelector("title").textContent);
|
||||
});
|
||||
document.getElementById('ticker-content').textContent = headlines.join(" | ");
|
||||
})
|
||||
.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';
|
||||
}
|
||||
});
|
||||
|
||||
// Initial load
|
||||
const storedRssUrl = loadRssUrl();
|
||||
if (storedRssUrl) {
|
||||
fetchRssFeed(storedRssUrl);
|
||||
document.getElementById('rss-input-container').style.display = 'none';
|
||||
} else {
|
||||
fetchRssFeed(defaultRssUrl);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user