diff js/background.js @ 11:a4590add4901

Add preset with common web-based feed readers
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Sat, 08 Dec 2018 12:01:32 +0100
parents ff5e5e3eba32
children 376a0e415bba
line wrap: on
line diff
--- a/js/background.js	Fri Dec 07 23:00:41 2018 +0100
+++ b/js/background.js	Sat Dec 08 12:01:32 2018 +0100
@@ -11,6 +11,40 @@
 import * as feedParser from './feed-parser.js';
 import {renderFeedPreview} from './feed-preview.js';
 
+const FEED_READERS_PRESET = [
+    {
+        title: 'Feedly',
+        urlTemplate: 'https://feedly.com/#subscription/feed/%s'
+    },
+    {
+        title: 'FlowReader',
+        urlTemplate: 'https://www.flowreader.com/subscribe?url=%s'
+    },
+    {
+        title: 'InoReader',
+        urlTemplate: 'https://www.inoreader.com/feed/%s'
+    },
+    {
+        title: 'Kouio',
+        urlTemplate: 'https://kouio.com/subscribe?url=%s'
+    },
+    {
+        title: 'My Yahoo',
+        urlTemplate: 'https://add.my.yahoo.com/rss?url=%s'
+    },
+    {
+        title: 'Netvibes',
+        urlTemplate: 'https://www.netvibes.com/subscribe.php?url=%s'
+    },
+    {
+        title: 'NewsBlur',
+        urlTemplate: 'https://www.newsblur.com/?url=%s'
+    },
+    {
+        title: 'The Old Reader',
+        urlTemplate: 'https://theoldreader.com/feeds/subscribe?url=%s'
+    }
+];
 const FEED_MAGIC = [
     '<rss',
     '<feed',
@@ -172,3 +206,19 @@
     tabsFeeds.delete(tabId);
     tabsFeedPreviews.delete(tabId);
 });
+
+browser.runtime.onInstalled.addListener(async details => {
+    if (details.reason === 'install' ||
+            (details.reason === 'update' && details.previousVersion < 2)) {
+        let {feedReaders = []} = await browser.storage.sync.get('feedReaders');
+        let feedReadersSet =
+                new Set(feedReaders.map(feedReader => feedReader.urlTemplate));
+        for (let feedReader of FEED_READERS_PRESET) {
+            if (!feedReadersSet.has(feedReader.urlTemplate)) {
+                feedReaders.push(feedReader);
+            }
+        }
+        console.log('set feedReaders to', feedReaders);
+        browser.storage.sync.set({feedReaders});
+    }
+});