From 3bdc11a9b2c78f2be8c11d28befce7328b6e5424 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Fri, 30 Dec 2022 13:58:20 -0600 Subject: Improve RSS preview --- content_scripts/scraper.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 content_scripts/scraper.js (limited to 'content_scripts/scraper.js') diff --git a/content_scripts/scraper.js b/content_scripts/scraper.js new file mode 100644 index 0000000..51043c3 --- /dev/null +++ b/content_scripts/scraper.js @@ -0,0 +1,35 @@ +let types = { + 'application/rss+xml': "rss", + 'application/atom+xml': "atom", + 'application/rdf+xml': "rdf", + 'application/rss': "rss", + 'application/atom': "atom", + 'application/rdf': "rdf", + 'text/rss+xml': "rss", + 'text/atom+xml': "atom", + 'text/rdf+xml': "rdf", + 'text/rss': "rss", + 'text/atom': "atom", + 'text/rdf': "rdf" +} + +// Scrape feed links from DOM +function find_feeds_in_page() { + let links = document.querySelectorAll('link[type]'); + let feeds = []; + for (let i = 0; i < links.length; i++) { + if (links[i].hasAttribute('type') && links[i].getAttribute('type') in types) { + let title = links[i].getAttribute('title') + let href = links[i].getAttribute('href') + let feed_url = new URL(href, window.location.href).href + let type = types[links[i].getAttribute('type')] + let feed = { + name: `native: ${title || type}`, + type: type, + url: feed_url, + }; + feeds.push(feed); + } + } + return feeds +} -- cgit v1.2.3