diff 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
line wrap: on
line diff
--- a/js/background.js	Mon Jan 21 08:22:52 2019 +0100
+++ b/js/background.js	Mon Jan 21 15:15:59 2019 +0100
@@ -57,6 +57,9 @@
 var tabsFeedPreviews = new Map();
 var fetchingFeedPreview = fetch('web_resources/feed-preview.xhtml')
         .then(response => response.text());
+var feedPreviewOptions = {
+    expandEntries: false
+};
 
 function parseContentType(header) {
     let contentType = {
@@ -103,7 +106,8 @@
     // render the preview document
     let feedPreviewDocument = new DOMParser()
             .parseFromString(await fetchingFeedPreview, 'text/html');
-    renderFeedPreview(feedPreviewDocument, feed);
+    renderFeedPreview(feedPreviewDocument, feed,
+            feedPreviewOptions.expandEntries);
 
     return new XMLSerializer().serializeToString(feedPreviewDocument);
 }
@@ -226,3 +230,20 @@
         browser.storage.sync.set({feedReaders});
     }
 });
+
+browser.storage.sync.get('feedPreview').then(({feedPreview}) => {
+    if (typeof feedPreview !== 'undefined' &&
+            feedPreview === Object(feedPreview)) {
+        feedPreviewOptions.expandEntries = !!feedPreview.expandEntries;
+    }
+});
+browser.storage.onChanged.addListener((changes, areaName) => {
+    if (areaName !== 'sync' || typeof changes.feedPreview === 'undefined') {
+        return;
+    }
+
+    let newValue = changes.feedPreview.newValue;
+    if (typeof newValue !== 'undefined' && newValue === Object(newValue)) {
+        feedPreviewOptions.expandEntries = !!newValue.expandEntries;
+    }
+});