Skip to content

Commit d6ccbc7

Browse files
Add news ticker functionality with RSS feed
1 parent b90881c commit d6ccbc7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

assets/js/News.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const ticker = document.getElementById("ticker");
2+
3+
// FIXED RSS (The Verge)
4+
const RSS_URL = "https://www.theverge.com/rss/index.xml";
5+
6+
async function loadNews() {
7+
try {
8+
const api = `https://api.rss2json.com/v1/api.json?rss_url=${encodeURIComponent(RSS_URL)}`;
9+
10+
const res = await fetch(api);
11+
const data = await res.json();
12+
13+
if (!data.items) return;
14+
15+
const feed = data.items.slice(0, 8).map(item => {
16+
return `[${item.title.toUpperCase()}]`;
17+
}).join(" • ");
18+
19+
ticker.textContent = feed + " • " + feed;
20+
21+
} catch (err) {
22+
ticker.textContent = "NEWS OFFLINE • SYSTEM RUNNING LOCAL MODE";
23+
}
24+
}
25+
26+
loadNews();
27+
setInterval(loadNews, 600000);

0 commit comments

Comments
 (0)