Use query selector to better detect feed links

Check that all the required attributes are set. The rel attribute is a white-space separated list of values. Lookup 'alternate' in such a list instead of attempting a direct string match.
This commit is contained in:
Daniel Aleksandersen 2018-09-04 12:54:10 +02:00 committed by GitHub
parent b78406073c
commit 12a735007d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 7 deletions

View File

@ -42,18 +42,14 @@ function scanForSyndicationFeeds() {
// variables to empty instead of null.
thisPageLinkObjects = []
thisPageLinks = document.getElementsByTagName("link");
thisPageLinks = document.querySelectorAll("link[href][rel~='alternate'][type]");
for (thisLinkIndex = 0; thisLinkIndex < thisPageLinks.length; thisLinkIndex++)
{
var thisLink = thisPageLinks[thisLinkIndex];
var thisLinkRel = thisLink.getAttribute("rel");
if (thisLinkRel == "alternate")
if (isValidFeedLink(thisLink))
{
if (isValidFeedLink(thisLink))
{
thisPageLinkObjects.push(objectFromLink(thisLink));
}
thisPageLinkObjects.push(objectFromLink(thisLink));
}
}
}