1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function feedLink(url
) {
6 var feed_link
= document
.createElement('a');
8 feed_link
.addEventListener("click", onClick
);
13 chrome
.tabs
.getSelected(function(tab
) {
14 chrome
.storage
.local
.get(tab
.id
.toString(), function(result
) {
15 var feeds
= result
[tab
.id
];
16 if (feeds
.length
== 1) {
17 // Only one feed, no need for a bubble; go straight to the subscribe
19 preview(feeds
[0].href
);
21 var content
= document
.getElementById('content');
22 var heading
= document
.getElementById('heading');
24 chrome
.i18n
.getMessage("rss_subscription_action_title");
25 content
.appendChild(document
.createElement('br'));
27 var feed_list
= document
.createElement('table');
28 feed_list
.style
.width
= "400";
29 for (var i
= 0; i
< feeds
.length
; ++i
) {
30 // Create an RSS image and the anhor encapsulating it.
31 var img_link
= feedLink(feeds
[i
].href
);
32 var img
= document
.createElement('img');
33 img
.src
= "feed-icon-16x16.png";
34 img_link
.appendChild(img
);
36 // Create a text node and the anchor encapsulating it.
37 var text_link
= feedLink(feeds
[i
].href
);
38 text_link
.appendChild(document
.createTextNode(feeds
[i
].title
));
40 // Add the data to a row in the table.
41 var tr
= document
.createElement('tr');
42 tr
.className
= "feedList";
43 var td
= document
.createElement('td');
45 td
.appendChild(img_link
);
46 var td2
= document
.createElement('td');
47 td2
.appendChild(text_link
);
50 feed_list
.appendChild(tr
);
53 content
.appendChild(feed_list
);
59 function onClick(event
) {
60 var a
= event
.currentTarget
;
64 function preview(feed_url
) {
65 // See if we need to skip the preview page and subscribe directly.
67 if (window
.localStorage
&& window
.localStorage
.showPreviewPage
== "No") {
69 url
= window
.localStorage
.defaultReader
.replace("%s", escape(feed_url
));
71 // Show the preview page.
72 url
= "subscribe.html?" + encodeURIComponent(feed_url
);
74 chrome
.tabs
.create({ url
: url
});
79 document
.addEventListener('DOMContentLoaded', main
);