Skip to content

Instantly share code, notes, and snippets.

@arahaya
Created April 30, 2012 22:22
Show Gist options
  • Save arahaya/2563220 to your computer and use it in GitHub Desktop.
Save arahaya/2563220 to your computer and use it in GitHub Desktop.
[JavaScript] Extract feed urls from HTML document
function findFeeds() {
var FEED_CONTENT_TYPES = {
"application/rss+xml": 1,
"application/atom+xml": 1,
"application/rdf+xml": 1,
"text/xml": 1,
"application/x.atom+xml": 1,
"application/x-atom+xml": 1
};
function each(a, c) {
for (var i = 0, l = a.length; i < l; i++) {
c(a[i]);
}
}
function parse(doc) {
var feeds = [];
each(doc.getElementsByTagName('head'), function (head) {
each(head.getElementsByTagName('link'), function (link) {
if (link.rel === 'alternate' && FEED_CONTENT_TYPES[link.type] && link.href) {
feeds.push({
href: link.href,
title: link.title
});
}
})
});
return feeds;
}
return parse(document);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment