comparison popup/feed-selection.js @ 0:bc5cc170163c

Initial revision
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Wed, 03 Oct 2018 23:40:57 +0200
parents
children c8fa2430eab2
comparison
equal deleted inserted replaced
-1:000000000000 0:bc5cc170163c
1 /*
2 * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9 'use strict';
10
11 async function buildFeedSelection() {
12 let tabs = await browser.tabs.query({active: true, currentWindow: true});
13 let feeds = await browser.runtime.sendMessage(tabs[0].id);
14
15 let feedListElement = document.querySelector('.panel-section-list');
16 feedListElement.addEventListener('click', ev => {
17 // find selected list item element and open the feed in a new tab
18 for (let element = ev.target; element !== ev.currentTarget;
19 element = element.parentElement) {
20 if (element.classList.contains('panel-list-item')) {
21 browser.tabs.create({url: element.dataset.href});
22 break;
23 }
24 }
25 ev.preventDefault();
26 });
27
28 let templateElement = document.querySelector('#feed-item-template');
29 for (let feed of feeds) {
30 let feedNode = document.importNode(templateElement.content, true);
31 feedNode.querySelector('.panel-list-item').dataset.href = feed.href;
32
33 let prefix = (feed.type === 'application/atom+xml') ? 'Atom Feed' :
34 'RSS Feed';
35
36 let imgNode = feedNode.querySelector('.icon > img');
37 imgNode.src = browser.runtime.getURL('icons/feed-preview.svg');
38 imgNode.alt = prefix;
39
40 feedNode.querySelector('.text').textContent =
41 `${prefix}: ${feed.title}`;
42 feedListElement.appendChild(feedNode);
43 }
44 }
45
46 buildFeedSelection();