comparison 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
comparison
equal deleted inserted replaced
10:ff5e5e3eba32 11:a4590add4901
9 'use strict'; 9 'use strict';
10 10
11 import * as feedParser from './feed-parser.js'; 11 import * as feedParser from './feed-parser.js';
12 import {renderFeedPreview} from './feed-preview.js'; 12 import {renderFeedPreview} from './feed-preview.js';
13 13
14 const FEED_READERS_PRESET = [
15 {
16 title: 'Feedly',
17 urlTemplate: 'https://feedly.com/#subscription/feed/%s'
18 },
19 {
20 title: 'FlowReader',
21 urlTemplate: 'https://www.flowreader.com/subscribe?url=%s'
22 },
23 {
24 title: 'InoReader',
25 urlTemplate: 'https://www.inoreader.com/feed/%s'
26 },
27 {
28 title: 'Kouio',
29 urlTemplate: 'https://kouio.com/subscribe?url=%s'
30 },
31 {
32 title: 'My Yahoo',
33 urlTemplate: 'https://add.my.yahoo.com/rss?url=%s'
34 },
35 {
36 title: 'Netvibes',
37 urlTemplate: 'https://www.netvibes.com/subscribe.php?url=%s'
38 },
39 {
40 title: 'NewsBlur',
41 urlTemplate: 'https://www.newsblur.com/?url=%s'
42 },
43 {
44 title: 'The Old Reader',
45 urlTemplate: 'https://theoldreader.com/feeds/subscribe?url=%s'
46 }
47 ];
14 const FEED_MAGIC = [ 48 const FEED_MAGIC = [
15 '<rss', 49 '<rss',
16 '<feed', 50 '<feed',
17 ...Object.values(feedParser.XMLNS) 51 ...Object.values(feedParser.XMLNS)
18 ]; 52 ];
170 204
171 browser.tabs.onRemoved.addListener((tabId, removeInfo) => { 205 browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
172 tabsFeeds.delete(tabId); 206 tabsFeeds.delete(tabId);
173 tabsFeedPreviews.delete(tabId); 207 tabsFeedPreviews.delete(tabId);
174 }); 208 });
209
210 browser.runtime.onInstalled.addListener(async details => {
211 if (details.reason === 'install' ||
212 (details.reason === 'update' && details.previousVersion < 2)) {
213 let {feedReaders = []} = await browser.storage.sync.get('feedReaders');
214 let feedReadersSet =
215 new Set(feedReaders.map(feedReader => feedReader.urlTemplate));
216 for (let feedReader of FEED_READERS_PRESET) {
217 if (!feedReadersSet.has(feedReader.urlTemplate)) {
218 feedReaders.push(feedReader);
219 }
220 }
221 console.log('set feedReaders to', feedReaders);
222 browser.storage.sync.set({feedReaders});
223 }
224 });