annotate options/options.js @ 62:b1d22243ef1f version-12

Release version 12
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Tue, 17 Nov 2020 15:31:04 +0100
parents 3c97046c2348
children 46c0595f2dcc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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);
57
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
32 // FIXME remove once the Firefox ESR release supports SubmitEvent
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
33 if (typeof SubmitEvent === 'undefined') {
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
34 for (let element of [
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
35 feedReadersForm.elements['move-up'],
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
36 feedReadersForm.elements['move-down'],
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
37 feedReadersForm.elements['remove']
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
38 ]) {
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
39 element.addEventListener('click', ev => {
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
40 ev.preventDefault();
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
41 let submitEvent = new Event('submit', {
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
42 'bubbles':true,
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
43 'cancelable':true
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
44 });
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
45 submitEvent.submitter = ev.target;
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
46 feedReadersForm.dispatchEvent(submitEvent)
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
47 });
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
48 }
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
49 }
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
50
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
51 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
52 addFeedReaderForm.elements['add'].textContent =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
53 browser.i18n.getMessage('feedReaderAddButton');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
54 let titleElement = addFeedReaderForm.elements['title'];
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
55 titleElement.labels[0].textContent =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
56 browser.i18n.getMessage('feedReaderTitleLabel');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
57 titleElement.placeholder =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
58 browser.i18n.getMessage('feedReaderTitlePlaceholder');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
59 let urlTemplateElement =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
60 addFeedReaderForm.elements['url-template'];
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
61 urlTemplateElement.labels[0].textContent =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
62 browser.i18n.getMessage('feedReaderUrlTemplateLabel');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
63 urlTemplateElement.placeholder =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
64 browser.i18n.getMessage('feedReaderUrlTemplatePlaceholder');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
65 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
66 browser.i18n.getMessage('feedReaderUrlTemplateCaption');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
67 addFeedReaderForm.addEventListener('focusout', this);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
68
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
69 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
70 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
71 browser.i18n.getMessage('feedPreviewExpandItemLabel');
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
72 feedPreviewForm.addEventListener('change', this);
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
73
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
74 document.addEventListener('submit', this);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
75
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
76 this.initOptions();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
77 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
78
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
79 async initOptions() {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
80 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
81 if (Array.isArray(feedReaders)) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
82 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
83 this.updateFeedReaders(feedReaders);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
84 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
85
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
86 let {feedPreview: feedPreviewOptions} =
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
87 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
88 if (typeof feedPreviewOptions !== 'undefined' &&
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
89 feedPreviewOptions === Object(feedPreviewOptions)) {
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
90 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
91 feedPreviewOptions);
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
92 this.updateFeedPreviewOptions({
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
93 expandEntries: !!feedPreviewOptions.expandEntries
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
94 });
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
95 }
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
96
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
97 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
98 }
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 validateURLTemplate(text) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
101 let url;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
102 try {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
103 url = new URL(text);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
104 } catch(e) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
105 if (e instanceof TypeError) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
106 return browser.i18n.getMessage('invalidURLError');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
107 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
108 throw e;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
109 }
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 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
112 return browser.i18n.getMessage('invalidProtocolError');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
113 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
114
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
115 if (!(url.pathname.includes('%s') || url.search.includes('%s'))) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
116 return browser.i18n.getMessage('missingPlaceholderError');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
117 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
118
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
119 return '';
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
120 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
121
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
122 updateFeedReaders(feedReaders) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
123 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
124 let feedReaderItemElements =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
125 feedReadersForm.querySelectorAll('.feed-reader-item');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
126 for (let feedReaderItemElement of feedReaderItemElements) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
127 feedReaderItemElement.remove();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
128 }
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 let feedReaderItemTemplateElement =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
131 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
132 let feedReaderSelectionElement =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
133 feedReadersForm.querySelector('#feed-reader-selection')
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
134 for (let feedReader of feedReaders) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
135 let feedReaderItemNode =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
136 document.importNode(feedReaderItemTemplateElement.content,
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
137 true);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
138 let feedReaderInputElement =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
139 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
140 feedReaderInputElement.dataset.title = feedReader.title;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
141 feedReaderInputElement.value = feedReader.urlTemplate;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
142 feedReaderItemNode.querySelector('.feed-reader-title')
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
143 .textContent = feedReader.title;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
144 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
145 .textContent = feedReader.urlTemplate;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
146 feedReaderSelectionElement.append(feedReaderItemNode);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
147 }
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 feedReadersForm.elements['buttons'].disabled = true;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
150 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
151
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
152 updateFeedPreviewOptions(feedPreviewOptions) {
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
153 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
154 feedPreviewOptions.expandEntries;
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
155 }
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
156
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
157 getFeedReaders() {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
158 let feedReaderInput =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
159 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
160 if (feedReaderInput instanceof RadioNodeList) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
161 return Array.from(feedReaderInput);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
162 } else if (typeof feedReaderInput === 'undefined') {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
163 return [];
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 return Array.from([feedReaderInput]);
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 selectFeedReader() {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
169 console.debug('selected:', this.selectedFeedReader);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
170 if (this.selectedFeedReader < 0) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
171 return;
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 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
175 let feedReaderElements = this.getFeedReaders();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
176 feedReaderElements[this.selectedFeedReader].checked = true;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
177 // 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
178 // 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
179 let activeElement = document.activeElement;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
180 feedReaderElements[this.selectedFeedReader].focus();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
181 activeElement.focus();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
182
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
183 feedReadersForm.elements['buttons'].disabled = false;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
184 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
185
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
186 serializeFeedReaders() {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
187 return this.getFeedReaders().map(element => ({
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
188 title: element.dataset.title,
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
189 urlTemplate: element.value
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
190 }));
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
191 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
192
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
193 onStorageChanged(changes, areaName) {
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
194 if (areaName !== 'sync') {
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
195 return;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
196 }
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.feedReaders !== 'undefined') {
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
199 let feedReaders;
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
200 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
201 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
202 feedReaders = changes.feedReaders.newValue;
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
203 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
204 } else {
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
205 // 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
206 feedReaders = [];
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
207 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
208 }
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
209 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
210 // 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
211 this.selectedFeedReader = -1;
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
212 }
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
213 this.updateFeedReaders(feedReaders);
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
214 this.selectFeedReader();
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
215 }
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
216 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
217 let feedPreviewOptions;
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
218 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
219 if (typeof newValue !== 'undefined' &&
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
220 newValue === Object(newValue)) {
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
221 feedPreviewOptions = {expandEntries: !!newValue.expandEntries};
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
222 } else {
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
223 // 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
224 // value
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
225 feedPreviewOptions = {expandEntries: false};
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
226 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
227 }
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
228 this.updateFeedPreviewOptions(feedPreviewOptions);
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
229 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
230 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
231
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
232 handleEvent(ev) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
233 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
234 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
235 // 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
236 console.debug(ev);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
237 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
238 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
239
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
240 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
241 } 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
242 // 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
243 ev.preventDefault();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
244
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
245 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
246 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
247 if (this.selectedFeedReader - 1 < 0) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
248 // 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
249 return;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
250 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
251 [feedReaders[this.selectedFeedReader - 1],
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
252 feedReaders[this.selectedFeedReader]] =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
253 [feedReaders[this.selectedFeedReader],
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
254 feedReaders[this.selectedFeedReader - 1]];
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
255 this.selectedFeedReader--;
57
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
256 } 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
257 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
258 // 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
259 return;
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
260 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
261 [feedReaders[this.selectedFeedReader + 1],
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
262 feedReaders[this.selectedFeedReader]] =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
263 [feedReaders[this.selectedFeedReader],
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
264 feedReaders[this.selectedFeedReader + 1]];
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
265 this.selectedFeedReader++;
57
3c97046c2348 Fix non-responsive buttons for managing feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
266 } 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
267 feedReaders.splice(this.selectedFeedReader, 1);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
268 this.selectedFeedReader--;
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 browser.storage.sync.set({feedReaders});
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
271 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
272 } else if (ev.type === 'focusout' &&
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
273 ev.target.name === 'url-template') {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
274 // url template was changed
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
275 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
276 ev.target.setCustomValidity(validity);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
277 } else if (ev.type === 'submit' &&
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
278 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
279 // feed reader added
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
280 ev.preventDefault();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
281
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
282 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
283 let isValid = this.validateURLTemplate(urlTemplate);
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
284 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
285 if (!ev.target.reportValidity()) {
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
286 return;
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 let feedReaders = this.serializeFeedReaders();
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
290 feedReaders.push({
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
291 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
292 urlTemplate: normalizeURL(urlTemplate)
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
293 });
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
294 browser.storage.sync.set({feedReaders});
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
295 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
296
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
297 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
298 } 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
299 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
300 browser.storage.sync.set({
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
301 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
302 });
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
303 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
304 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
305 }
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
306
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
307 var page = new OptionsPage();