152 lines
5.7 KiB
HTML
152 lines
5.7 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 */
|
|
|
|
}
|
|
@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.text();
|
|
throw new Error('Network response was not ok.');
|
|
})
|
|
.then(xmlText => {
|
|
console.log('Raw XML from proxy:', xmlText);
|
|
const parser = new DOMParser();
|
|
const xmlDoc = parser.parseFromString(xmlText, "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) {
|
|
const tickerContent = document.getElementById('ticker-content');
|
|
tickerContent.textContent = headlines.join(" | ");
|
|
|
|
// Calculate dynamic animation duration
|
|
const pixelsPerSecond = 50; // Adjust this value to change the perceived speed
|
|
const contentWidth = tickerContent.scrollWidth;
|
|
const animationDuration = contentWidth / pixelsPerSecond;
|
|
|
|
// Apply and restart animation
|
|
tickerContent.style.animationDuration = `${animationDuration}s`;
|
|
tickerContent.style.animation = 'none'; // Reset animation
|
|
void tickerContent.offsetWidth; // Trigger reflow
|
|
tickerContent.style.animation = 'ticker-scroll ${animationDuration}s linear infinite';
|
|
|
|
} 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>
|