Mercurial > addons > firefox-addons > feed-preview
annotate options/options.js @ 66:744652abc028 version-13
Release version 13
author | Guido Berhoerster <guido+feed-preview@berhoerster.name> |
---|---|
date | Tue, 20 Apr 2021 17:12:47 +0200 |
parents | 106d78e26d3c |
children |
rev | line source |
---|---|
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
1 /* |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name> |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
3 * |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
7 */ |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
8 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
9 'use strict'; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
10 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
11 function normalizeURL(text) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
12 return new URL(text).toString(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
13 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
14 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
15 class OptionsPage { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
16 constructor() { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
17 this.selectedFeedReader = -1; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
18 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
19 document.querySelector('#feed-readers-title').textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
20 browser.i18n.getMessage('feedReadersTitle'); |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
21 document.querySelector('#feed-preview-title').textContent = |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
22 browser.i18n.getMessage('feedPreviewTitle'); |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
23 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
24 let feedReadersForm = document.forms['feed-readers']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
25 feedReadersForm.elements['move-up'].textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
26 browser.i18n.getMessage('feedReaderMoveUpButton'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
27 feedReadersForm.elements['move-down'].textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
28 browser.i18n.getMessage('feedReaderMoveDownButton'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
29 feedReadersForm.elements['remove'].textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
30 browser.i18n.getMessage('feedReaderRemoveButton'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
31 feedReadersForm.addEventListener('change', this); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
32 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
33 let addFeedReaderForm = document.forms['add-feed-reader']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
34 addFeedReaderForm.elements['add'].textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
35 browser.i18n.getMessage('feedReaderAddButton'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
36 let titleElement = addFeedReaderForm.elements['title']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
37 titleElement.labels[0].textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
38 browser.i18n.getMessage('feedReaderTitleLabel'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
39 titleElement.placeholder = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
40 browser.i18n.getMessage('feedReaderTitlePlaceholder'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
41 let urlTemplateElement = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
42 addFeedReaderForm.elements['url-template']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
43 urlTemplateElement.labels[0].textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
44 browser.i18n.getMessage('feedReaderUrlTemplateLabel'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
45 urlTemplateElement.placeholder = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
46 browser.i18n.getMessage('feedReaderUrlTemplatePlaceholder'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
47 document.querySelector('#feed-reader-url-caption').textContent = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
48 browser.i18n.getMessage('feedReaderUrlTemplateCaption'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
49 addFeedReaderForm.addEventListener('focusout', this); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
50 |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
51 let feedPreviewForm = document.forms['feed-preview']; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
52 feedPreviewForm.elements['expand-entries'].labels[0].textContent = |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
53 browser.i18n.getMessage('feedPreviewExpandItemLabel'); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
54 feedPreviewForm.addEventListener('change', this); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
55 |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
56 document.addEventListener('submit', this); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
57 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
58 this.initOptions(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
59 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
60 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
61 async initOptions() { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
62 let {feedReaders} = await browser.storage.sync.get('feedReaders'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
63 if (Array.isArray(feedReaders)) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
64 console.log('initialized feedReaders from storage', feedReaders); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
65 this.updateFeedReaders(feedReaders); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
66 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
67 |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
68 let {feedPreview: feedPreviewOptions} = |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
69 await browser.storage.sync.get('feedPreview'); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
70 if (typeof feedPreviewOptions !== 'undefined' && |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
71 feedPreviewOptions === Object(feedPreviewOptions)) { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
72 console.log('initialized feedPreviewOptions from storage', |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
73 feedPreviewOptions); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
74 this.updateFeedPreviewOptions({ |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
75 expandEntries: !!feedPreviewOptions.expandEntries |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
76 }); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
77 } |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
78 |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
79 browser.storage.onChanged.addListener(this.onStorageChanged.bind(this)); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
80 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
81 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
82 validateURLTemplate(text) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
83 let url; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
84 try { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
85 url = new URL(text); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
86 } catch(e) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
87 if (e instanceof TypeError) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
88 return browser.i18n.getMessage('invalidURLError'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
89 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
90 throw e; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
91 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
92 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
93 if (url.protocol !== 'http:' && url.protocol !== 'https:') { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
94 return browser.i18n.getMessage('invalidProtocolError'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
95 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
96 |
65
106d78e26d3c
Allow placeholder in the fragment identifier
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
64
diff
changeset
|
97 if (!(url.pathname.includes('%s') || url.search.includes('%s') || url.hash.includes('%s'))) { |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
98 return browser.i18n.getMessage('missingPlaceholderError'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
99 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
100 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
101 return ''; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
102 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
103 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
104 updateFeedReaders(feedReaders) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
105 let feedReadersForm = document.forms['feed-readers']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
106 let feedReaderItemElements = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
107 feedReadersForm.querySelectorAll('.feed-reader-item'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
108 for (let feedReaderItemElement of feedReaderItemElements) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
109 feedReaderItemElement.remove(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
110 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
111 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
112 let feedReaderItemTemplateElement = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
113 document.querySelector('#feed-reader-item-template'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
114 let feedReaderSelectionElement = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
115 feedReadersForm.querySelector('#feed-reader-selection') |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
116 for (let feedReader of feedReaders) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
117 let feedReaderItemNode = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
118 document.importNode(feedReaderItemTemplateElement.content, |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
119 true); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
120 let feedReaderInputElement = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
121 feedReaderItemNode.querySelector('input[name=feed-reader]'); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
122 feedReaderInputElement.dataset.title = feedReader.title; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
123 feedReaderInputElement.value = feedReader.urlTemplate; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
124 feedReaderItemNode.querySelector('.feed-reader-title') |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
125 .textContent = feedReader.title; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
126 feedReaderItemNode.querySelector('.feed-reader-url-template') |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
127 .textContent = feedReader.urlTemplate; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
128 feedReaderSelectionElement.append(feedReaderItemNode); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
129 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
130 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
131 feedReadersForm.elements['buttons'].disabled = true; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
132 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
133 |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
134 updateFeedPreviewOptions(feedPreviewOptions) { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
135 document.forms['feed-preview'].elements['expand-entries'].checked = |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
136 feedPreviewOptions.expandEntries; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
137 } |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
138 |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
139 getFeedReaders() { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
140 let feedReaderInput = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
141 document.forms['feed-readers'].elements['feed-reader']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
142 if (feedReaderInput instanceof RadioNodeList) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
143 return Array.from(feedReaderInput); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
144 } else if (typeof feedReaderInput === 'undefined') { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
145 return []; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
146 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
147 return Array.from([feedReaderInput]); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
148 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
149 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
150 selectFeedReader() { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
151 console.debug('selected:', this.selectedFeedReader); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
152 if (this.selectedFeedReader < 0) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
153 return; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
154 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
155 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
156 let feedReadersForm = document.forms['feed-readers']; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
157 let feedReaderElements = this.getFeedReaders(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
158 feedReaderElements[this.selectedFeedReader].checked = true; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
159 // ensure that the checked element will also be the focused one the |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
160 // next time the radio input group receives focus |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
161 let activeElement = document.activeElement; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
162 feedReaderElements[this.selectedFeedReader].focus(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
163 activeElement.focus(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
164 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
165 feedReadersForm.elements['buttons'].disabled = false; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
166 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
167 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
168 serializeFeedReaders() { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
169 return this.getFeedReaders().map(element => ({ |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
170 title: element.dataset.title, |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
171 urlTemplate: element.value |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
172 })); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
173 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
174 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
175 onStorageChanged(changes, areaName) { |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
176 if (areaName !== 'sync') { |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
177 return; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
178 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
179 |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
180 if (typeof changes.feedReaders !== 'undefined') { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
181 let feedReaders; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
182 if (typeof changes.feedReaders.newValue !== 'undefined' && |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
183 Array.isArray(changes.feedReaders.newValue)) { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
184 feedReaders = changes.feedReaders.newValue; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
185 console.log('feedReaders changed to', feedReaders); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
186 } else { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
187 // list of feed readers was removed or set to nonsensical value |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
188 feedReaders = []; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
189 console.log('feedReaders was removed'); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
190 } |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
191 if (this.selectedFeedReader >= feedReaders.length) { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
192 // save selected feed reader is no longer valid |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
193 this.selectedFeedReader = -1; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
194 } |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
195 this.updateFeedReaders(feedReaders); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
196 this.selectFeedReader(); |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
197 } |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
198 if (typeof changes.feedPreview !== 'undefined') { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
199 let feedPreviewOptions; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
200 let newValue = changes.feedPreview.newValue; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
201 if (typeof newValue !== 'undefined' && |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
202 newValue === Object(newValue)) { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
203 feedPreviewOptions = {expandEntries: !!newValue.expandEntries}; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
204 } else { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
205 // feed preview preferences were removed or set to nonsensical |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
206 // value |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
207 feedPreviewOptions = {expandEntries: false}; |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
208 console.log('feedPreview was removed'); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
209 } |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
210 this.updateFeedPreviewOptions(feedPreviewOptions); |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
211 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
212 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
213 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
214 handleEvent(ev) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
215 console.log('previously selected:', this.selectedFeedReader); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
216 if (ev.type === 'change' && ev.target.name === 'feed-reader') { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
217 // feed reader was selected by user interaction |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
218 console.debug(ev); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
219 this.selectedFeedReader = this.getFeedReaders().indexOf(ev.target); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
220 console.log('now selected:', this.selectedFeedReader); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
221 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
222 document.forms['feed-readers'].elements['buttons'].disabled = false; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
223 } else if (ev.type === 'submit' && ev.target.id === 'feed-readers') { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
224 // remove feed reader or move feed reader up or down |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
225 ev.preventDefault(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
226 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
227 let feedReaders = this.serializeFeedReaders(); |
57
3c97046c2348
Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
29
diff
changeset
|
228 if (ev.submitter.name === 'move-up') { |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
229 if (this.selectedFeedReader - 1 < 0) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
230 // the first feed reader is selected |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
231 return; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
232 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
233 [feedReaders[this.selectedFeedReader - 1], |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
234 feedReaders[this.selectedFeedReader]] = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
235 [feedReaders[this.selectedFeedReader], |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
236 feedReaders[this.selectedFeedReader - 1]]; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
237 this.selectedFeedReader--; |
57
3c97046c2348
Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
29
diff
changeset
|
238 } else if (ev.submitter.name === 'move-down') { |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
239 if (this.selectedFeedReader + 1 === feedReaders.length) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
240 // the last feed reader is selected |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
241 return; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
242 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
243 [feedReaders[this.selectedFeedReader + 1], |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
244 feedReaders[this.selectedFeedReader]] = |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
245 [feedReaders[this.selectedFeedReader], |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
246 feedReaders[this.selectedFeedReader + 1]]; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
247 this.selectedFeedReader++; |
57
3c97046c2348
Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
29
diff
changeset
|
248 } else if (ev.submitter.name === 'remove') { |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
249 feedReaders.splice(this.selectedFeedReader, 1); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
250 this.selectedFeedReader--; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
251 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
252 browser.storage.sync.set({feedReaders}); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
253 console.log('set feedReaders to ', feedReaders); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
254 } else if (ev.type === 'focusout' && |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
255 ev.target.name === 'url-template') { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
256 // url template was changed |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
257 let validity = this.validateURLTemplate(ev.target.value); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
258 ev.target.setCustomValidity(validity); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
259 } else if (ev.type === 'submit' && |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
260 ev.target.id === 'add-feed-reader') { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
261 // feed reader added |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
262 ev.preventDefault(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
263 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
264 let urlTemplate = ev.target.elements['url-template'].value; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
265 let isValid = this.validateURLTemplate(urlTemplate); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
266 ev.target.elements['url-template'].setCustomValidity(isValid); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
267 if (!ev.target.reportValidity()) { |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
268 return; |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
269 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
270 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
271 let feedReaders = this.serializeFeedReaders(); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
272 feedReaders.push({ |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
273 title: ev.target.elements['title'].value, |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
274 urlTemplate: normalizeURL(urlTemplate) |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
275 }); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
276 browser.storage.sync.set({feedReaders}); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
277 console.log('set feedReaders to', feedReaders); |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
278 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
279 document.forms['add-feed-reader'].reset(); |
29
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
280 } else if (ev.type === 'change' && ev.target.id === 'expand-entries') { |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
281 console.log('expand entries by default:', ev.target.checked); |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
282 browser.storage.sync.set({ |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
283 feedPreview: {expandEntries: ev.target.checked} |
688d75e554e0
Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
10
diff
changeset
|
284 }); |
10
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
285 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
286 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
287 } |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
288 |
ff5e5e3eba32
Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
289 var page = new OptionsPage(); |