Mercurial > addons > firefox-addons > feed-preview
annotate content_scripts/feed-probe.js @ 68:fc5fca9af05f
Update Feedly URL template
Thanks to quroe for submitting the changed URL.
author | Guido Berhoerster <guido+feed-preview@berhoerster.name> |
---|---|
date | Tue, 20 Feb 2024 16:05:46 +0100 |
parents | ede87e1004f9 |
children |
rev | line source |
---|---|
0
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
1 /* |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
2 * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name> |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
3 * |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
bc5cc170163c
Initial revision
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 |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
7 */ |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
8 |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
9 'use strict'; |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
10 |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
11 function getFeeds() { |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
12 let urlsFeeds = new Map(); |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
13 let elements = document.querySelectorAll(':-moz-any(link, a)[href]' + |
25
da483ce3832d
Fix selector for rel attributes
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
0
diff
changeset
|
14 '[rel~=alternate]:-moz-any([type="application/atom+xml"], ' + |
0
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
15 '[type="application/rss+xml"])'); |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
16 |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
17 for (let element of elements) { |
31
76e23b361e92
Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
25
diff
changeset
|
18 if (element.href === document.URL) { |
76e23b361e92
Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
25
diff
changeset
|
19 // do not indicate the availability of a feed if the current |
76e23b361e92
Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
25
diff
changeset
|
20 // document is already a feed preview |
76e23b361e92
Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
25
diff
changeset
|
21 continue; |
76e23b361e92
Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
25
diff
changeset
|
22 } |
76e23b361e92
Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
25
diff
changeset
|
23 |
0
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
24 if (!element.href.match(/^https?:\/\//)) { |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
25 continue; |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
26 } |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
27 |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
28 urlsFeeds.set(element.href, { |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
29 href: element.href, |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
30 title: element.title || browser.i18n.getMessage('defaultFeedTitle'), |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
31 type: element.type |
54
ede87e1004f9
Fix issues with feed detection
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
31
diff
changeset
|
32 }); |
0
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
33 } |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
34 |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
35 return Array.from(urlsFeeds.values()); |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
36 } |
bc5cc170163c
Initial revision
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff
changeset
|
37 |
54
ede87e1004f9
Fix issues with feed detection
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
31
diff
changeset
|
38 browser.runtime.onMessage.addListener((request, sender, sendResponse) => { |
ede87e1004f9
Fix issues with feed detection
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
31
diff
changeset
|
39 // background page querying available feeds |
ede87e1004f9
Fix issues with feed detection
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
31
diff
changeset
|
40 sendResponse(getFeeds()); |
ede87e1004f9
Fix issues with feed detection
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
31
diff
changeset
|
41 }); |