feat: Add reset button and improve error handling for RSSticker
This commit is contained in:
@@ -59,30 +59,41 @@
|
||||
<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>
|
||||
<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=";
|
||||
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 => {
|
||||
headlines.push(item.querySelector("title").textContent);
|
||||
const titleElement = item.querySelector("title");
|
||||
if (titleElement) {
|
||||
headlines.push(titleElement.textContent);
|
||||
}
|
||||
});
|
||||
document.getElementById('ticker-content').textContent = headlines.join(" | ");
|
||||
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);
|
||||
@@ -107,6 +118,13 @@
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user