comparison js/background.js @ 29:688d75e554e0

Add option to expand feed entries by default
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Mon, 21 Jan 2019 15:15:59 +0100
parents a59d322e5826
children 6bd8a649186d
comparison
equal deleted inserted replaced
28:104a1faebd43 29:688d75e554e0
55 ]; 55 ];
56 var tabsFeeds = new Map(); 56 var tabsFeeds = new Map();
57 var tabsFeedPreviews = new Map(); 57 var tabsFeedPreviews = new Map();
58 var fetchingFeedPreview = fetch('web_resources/feed-preview.xhtml') 58 var fetchingFeedPreview = fetch('web_resources/feed-preview.xhtml')
59 .then(response => response.text()); 59 .then(response => response.text());
60 var feedPreviewOptions = {
61 expandEntries: false
62 };
60 63
61 function parseContentType(header) { 64 function parseContentType(header) {
62 let contentType = { 65 let contentType = {
63 mediaType: '', 66 mediaType: '',
64 charset: 'utf-8' 67 charset: 'utf-8'
101 tabsFeedPreviews.set(tabId, url); 104 tabsFeedPreviews.set(tabId, url);
102 105
103 // render the preview document 106 // render the preview document
104 let feedPreviewDocument = new DOMParser() 107 let feedPreviewDocument = new DOMParser()
105 .parseFromString(await fetchingFeedPreview, 'text/html'); 108 .parseFromString(await fetchingFeedPreview, 'text/html');
106 renderFeedPreview(feedPreviewDocument, feed); 109 renderFeedPreview(feedPreviewDocument, feed,
110 feedPreviewOptions.expandEntries);
107 111
108 return new XMLSerializer().serializeToString(feedPreviewDocument); 112 return new XMLSerializer().serializeToString(feedPreviewDocument);
109 } 113 }
110 114
111 browser.webRequest.onHeadersReceived.addListener(details => { 115 browser.webRequest.onHeadersReceived.addListener(details => {
224 } 228 }
225 console.log('set feedReaders to', feedReaders); 229 console.log('set feedReaders to', feedReaders);
226 browser.storage.sync.set({feedReaders}); 230 browser.storage.sync.set({feedReaders});
227 } 231 }
228 }); 232 });
233
234 browser.storage.sync.get('feedPreview').then(({feedPreview}) => {
235 if (typeof feedPreview !== 'undefined' &&
236 feedPreview === Object(feedPreview)) {
237 feedPreviewOptions.expandEntries = !!feedPreview.expandEntries;
238 }
239 });
240 browser.storage.onChanged.addListener((changes, areaName) => {
241 if (areaName !== 'sync' || typeof changes.feedPreview === 'undefined') {
242 return;
243 }
244
245 let newValue = changes.feedPreview.newValue;
246 if (typeof newValue !== 'undefined' && newValue === Object(newValue)) {
247 feedPreviewOptions.expandEntries = !!newValue.expandEntries;
248 }
249 });