aboutsummaryrefslogtreecommitdiff
path: root/content_scripts/scraper.js
blob: 51043c3ebdc685f5092b0acc2adcdbaab0253c31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
}