feat: Add reset button and improve error handling for RSSticker
This commit is contained in:
23
rss_ticker_overlay/cors_proxy.py
Normal file
23
rss_ticker_overlay/cors_proxy.py
Normal 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)
|
||||||
@@ -59,30 +59,41 @@
|
|||||||
<div id="rss-input-container">
|
<div id="rss-input-container">
|
||||||
<input type="text" id="rss-url-input" placeholder="Enter RSS Feed URL">
|
<input type="text" id="rss-url-input" placeholder="Enter RSS Feed URL">
|
||||||
<button id="update-rss-button">Update RSS</button>
|
<button id="update-rss-button">Update RSS</button>
|
||||||
|
<button id="reset-rss-button">Reset</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
<script>
|
<script>
|
||||||
const defaultRssUrl = "https://www.nasa.gov/news-release/feed/"; // Default NASA news feed
|
const defaultRssUrl = "https://www.nasa.gov/news-release/feed/"; // Default NASA news feed
|
||||||
|
|
||||||
function fetchRssFeed(rssUrl) {
|
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)}`;
|
const url = `${corsProxy}${encodeURIComponent(rssUrl)}`;
|
||||||
|
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
console.log('Proxy response:', response);
|
||||||
if (response.ok) return response.json();
|
if (response.ok) return response.json();
|
||||||
throw new Error('Network response was not ok.');
|
throw new Error('Network response was not ok.');
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
console.log('Raw data from proxy:', data);
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const xmlDoc = parser.parseFromString(data.contents, "text/xml");
|
const xmlDoc = parser.parseFromString(data.contents, "text/xml");
|
||||||
|
console.log('Parsed XML Doc:', xmlDoc);
|
||||||
const items = xmlDoc.querySelectorAll("item");
|
const items = xmlDoc.querySelectorAll("item");
|
||||||
let headlines = [];
|
let headlines = [];
|
||||||
items.forEach(item => {
|
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 => {
|
.catch(error => {
|
||||||
console.error('Error fetching RSS feed:', 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
|
// Initial load
|
||||||
const storedRssUrl = loadRssUrl();
|
const storedRssUrl = loadRssUrl();
|
||||||
if (storedRssUrl) {
|
if (storedRssUrl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user