feat: Add reset button and improve error handling for RSSticker

This commit is contained in:
2025-10-31 11:06:15 +01:00
parent 084401bb3a
commit d2020e57ed
2 changed files with 45 additions and 4 deletions

View File

@@ -0,0 +1,23 @@
from flask import Flask, request, Response
import requests
app = Flask(__name__)
@app.route('/proxy')
def proxy():
url = request.args.get('url')
if not url:
return "Missing URL parameter", 400
try:
response = requests.get(url)
headers = {
'Access-Control-Allow-Origin': '*',
'Content-Type': response.headers['Content-Type']
}
return Response(response.content, response.status_code, headers)
except requests.exceptions.RequestException as e:
return str(e), 500
if __name__ == '__main__':
app.run(port=8001)

View File

@@ -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);
}
});
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) {