addons/firefox-addons/feed-preview

changeset 31:76e23b361e92

Allow feed reader addons to subscribe to the currently viewed feed

Add a link element to the feed preview that points to the currently viewed feed
in order to allow feed reader addons to subscribe to it.
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Tue Jan 22 14:40:06 2019 +0100 (16 months ago)
parents b9dc94ce2eeb
children 4492db3b277e
files content_scripts/feed-probe.js js/feed-parser.js js/feed-preview.js web_resources/feed-preview.xhtml
line diff
     1.1 --- a/content_scripts/feed-probe.js	Tue Jan 22 10:43:24 2019 +0100
     1.2 +++ b/content_scripts/feed-probe.js	Tue Jan 22 14:40:06 2019 +0100
     1.3 @@ -17,6 +17,12 @@
     1.4              '[type="application/rss+xml"])');
     1.5  
     1.6      for (let element of elements) {
     1.7 +        if (element.href === document.URL) {
     1.8 +            // do not indicate the availability of a feed if the current
     1.9 +            // document is already a feed preview
    1.10 +            continue;
    1.11 +        }
    1.12 +
    1.13          if (!element.href.match(/^https?:\/\//)) {
    1.14              continue;
    1.15          }
     2.1 --- a/js/feed-parser.js	Tue Jan 22 10:43:24 2019 +0100
     2.2 +++ b/js/feed-parser.js	Tue Jan 22 14:40:06 2019 +0100
     2.3 @@ -184,9 +184,10 @@
     2.4  }
     2.5  
     2.6  class Feed {
     2.7 -    constructor(url, {title = browser.i18n.getMessage('defaultFeedTitle'),
     2.8 +    constructor(url, type, {title = browser.i18n.getMessage('defaultFeedTitle'),
     2.9              subtitle = '', logo, entries = []} = {}) {
    2.10          this.url = url;
    2.11 +        this.type = type;
    2.12          this.title = title;
    2.13          this.subtitle = subtitle;
    2.14          this.logo = logo;
    2.15 @@ -431,7 +432,8 @@
    2.16              entries.push(this.parseAtom03Entry(entryElement));
    2.17          }
    2.18  
    2.19 -        return new Feed(this.url, {title, subtitle, logo, entries});
    2.20 +        return new Feed(this.url, 'application/atom+xml',
    2.21 +                {title, subtitle, logo, entries});
    2.22      }
    2.23  
    2.24      parseAtomLogo(logoElement) {
    2.25 @@ -595,7 +597,8 @@
    2.26              entries.push(this.parseAtomEntry(entryElement));
    2.27          }
    2.28  
    2.29 -        return new Feed(this.url, {title, subtitle, logo, entries});
    2.30 +        return new Feed(this.url, 'application/atom+xml',
    2.31 +                {title, subtitle, logo, entries});
    2.32      }
    2.33  
    2.34      parseRSS1Logo(imageElement, nsPrefix) {
    2.35 @@ -677,7 +680,8 @@
    2.36              }
    2.37          }
    2.38  
    2.39 -        return new Feed(this.url, {title, subtitle, logo, entries});
    2.40 +        return new Feed(this.url, 'application/rss+xml',
    2.41 +                {title, subtitle, logo, entries});
    2.42      }
    2.43  
    2.44      parseRSS2Logo(imageElement) {
    2.45 @@ -805,7 +809,8 @@
    2.46              }
    2.47          }
    2.48  
    2.49 -        return new Feed(this.url, {title, subtitle, logo, entries});
    2.50 +        return new Feed(this.url, 'application/rss+xml',
    2.51 +                {title, subtitle, logo, entries});
    2.52      }
    2.53  
    2.54      parseFromString(xmlString, url) {
     3.1 --- a/js/feed-preview.js	Tue Jan 22 10:43:24 2019 +0100
     3.2 +++ b/js/feed-preview.js	Tue Jan 22 14:40:06 2019 +0100
     3.3 @@ -21,6 +21,12 @@
     3.4      feedPreviewDocument.querySelector('#default-stylesheet').href =
     3.5              browser.runtime.getURL('web_resources/style/feed-preview.css');
     3.6  
     3.7 +    // link to the currently viewed feed in order to allow feed reader addons
     3.8 +    // to subscribe to it
     3.9 +    let feedLinkElement = feedPreviewDocument.querySelector('#feed-link');
    3.10 +    feedLinkElement.href = feed.url;
    3.11 +    feedLinkElement.type = feed.type;
    3.12 +
    3.13      feedPreviewDocument.querySelector('title').textContent = feed.title;
    3.14  
    3.15      feedPreviewDocument.querySelector('label[for="feed-reader-selection"]')
     4.1 --- a/web_resources/feed-preview.xhtml	Tue Jan 22 10:43:24 2019 +0100
     4.2 +++ b/web_resources/feed-preview.xhtml	Tue Jan 22 14:40:06 2019 +0100
     4.3 @@ -12,6 +12,7 @@
     4.4  -->
     4.5      <meta name="viewport" content="width=device-width, initial-scale=1"/>
     4.6      <link id="default-stylesheet" rel="stylesheet" href=""/>
     4.7 +    <link id="feed-link" rel="alternate" type="" href=""/>
     4.8      <title></title>
     4.9    </head>
    4.10    <body>