From 12a735007dbd796db9464028c5b53eec8f6cef22 Mon Sep 17 00:00:00 2001 From: Daniel Aleksandersen Date: Tue, 4 Sep 2018 12:54:10 +0200 Subject: [PATCH] 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. --- Safari Extension/netnewswire-subscribe-to-feed.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Safari Extension/netnewswire-subscribe-to-feed.js b/Safari Extension/netnewswire-subscribe-to-feed.js index 576c4c49b..17fef5595 100644 --- a/Safari Extension/netnewswire-subscribe-to-feed.js +++ b/Safari Extension/netnewswire-subscribe-to-feed.js @@ -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)); } } }