Reddit RSS Chrome extension
July 10, 2014
software
I made a Chrome extension that displayed posts from a subreddit using its RSS feed.
The extension parsed the feed's XML to extract titles, links, and timestamps, then displayed them in a popup.
Unfortunately I have not kept the source code nor any screenshot for this Chrome extension.
A Chrome extension is basically a web page with some javascript code and a manifest.json file. You can fetch data from an external server using AJAX requests.
// Function to fetch Reddit RSS feed data
async function fetchRedditData(subreddit) {
const rssUrl = `https://www.reddit.com/r/${subreddit}/.rss`;
try {
const response = await fetch(rssUrl);
const xmlData = await response.text();
// Parse XML data (you might want to use a library for more robust parsing)
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlData, "text/xml");
// Extract relevant information from the XML document
const items = xmlDoc.querySelectorAll('item');
const redditData = Array.from(items).map(item => ({
title: item.querySelector('title').textContent,
link: item.querySelector('link').textContent,
pubDate: item.querySelector('pubDate').textContent
}));
return redditData;
} catch (error) {
console.error('Error fetching Reddit data:', error);
throw error;
}
}
This was a small extension, not a general-purpose Reddit client. The sample above is illustrative. I no longer have the original source code or screenshots.