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, 22 Jan 2019 14:40:06 +0100
parents b9dc94ce2eeb
children 4492db3b277e
files content_scripts/feed-probe.js js/feed-parser.js js/feed-preview.js web_resources/feed-preview.xhtml
diffstat 4 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/content_scripts/feed-probe.js	Tue Jan 22 10:43:24 2019 +0100
+++ b/content_scripts/feed-probe.js	Tue Jan 22 14:40:06 2019 +0100
@@ -17,6 +17,12 @@
             '[type="application/rss+xml"])');
 
     for (let element of elements) {
+        if (element.href === document.URL) {
+            // do not indicate the availability of a feed if the current
+            // document is already a feed preview
+            continue;
+        }
+
         if (!element.href.match(/^https?:\/\//)) {
             continue;
         }
--- a/js/feed-parser.js	Tue Jan 22 10:43:24 2019 +0100
+++ b/js/feed-parser.js	Tue Jan 22 14:40:06 2019 +0100
@@ -184,9 +184,10 @@
 }
 
 class Feed {
-    constructor(url, {title = browser.i18n.getMessage('defaultFeedTitle'),
+    constructor(url, type, {title = browser.i18n.getMessage('defaultFeedTitle'),
             subtitle = '', logo, entries = []} = {}) {
         this.url = url;
+        this.type = type;
         this.title = title;
         this.subtitle = subtitle;
         this.logo = logo;
@@ -431,7 +432,8 @@
             entries.push(this.parseAtom03Entry(entryElement));
         }
 
-        return new Feed(this.url, {title, subtitle, logo, entries});
+        return new Feed(this.url, 'application/atom+xml',
+                {title, subtitle, logo, entries});
     }
 
     parseAtomLogo(logoElement) {
@@ -595,7 +597,8 @@
             entries.push(this.parseAtomEntry(entryElement));
         }
 
-        return new Feed(this.url, {title, subtitle, logo, entries});
+        return new Feed(this.url, 'application/atom+xml',
+                {title, subtitle, logo, entries});
     }
 
     parseRSS1Logo(imageElement, nsPrefix) {
@@ -677,7 +680,8 @@
             }
         }
 
-        return new Feed(this.url, {title, subtitle, logo, entries});
+        return new Feed(this.url, 'application/rss+xml',
+                {title, subtitle, logo, entries});
     }
 
     parseRSS2Logo(imageElement) {
@@ -805,7 +809,8 @@
             }
         }
 
-        return new Feed(this.url, {title, subtitle, logo, entries});
+        return new Feed(this.url, 'application/rss+xml',
+                {title, subtitle, logo, entries});
     }
 
     parseFromString(xmlString, url) {
--- a/js/feed-preview.js	Tue Jan 22 10:43:24 2019 +0100
+++ b/js/feed-preview.js	Tue Jan 22 14:40:06 2019 +0100
@@ -21,6 +21,12 @@
     feedPreviewDocument.querySelector('#default-stylesheet').href =
             browser.runtime.getURL('web_resources/style/feed-preview.css');
 
+    // link to the currently viewed feed in order to allow feed reader addons
+    // to subscribe to it
+    let feedLinkElement = feedPreviewDocument.querySelector('#feed-link');
+    feedLinkElement.href = feed.url;
+    feedLinkElement.type = feed.type;
+
     feedPreviewDocument.querySelector('title').textContent = feed.title;
 
     feedPreviewDocument.querySelector('label[for="feed-reader-selection"]')
--- a/web_resources/feed-preview.xhtml	Tue Jan 22 10:43:24 2019 +0100
+++ b/web_resources/feed-preview.xhtml	Tue Jan 22 14:40:06 2019 +0100
@@ -12,6 +12,7 @@
 -->
     <meta name="viewport" content="width=device-width, initial-scale=1"/>
     <link id="default-stylesheet" rel="stylesheet" href=""/>
+    <link id="feed-link" rel="alternate" type="" href=""/>
     <title></title>
   </head>
   <body>