feeds.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. function initFeedTab()
  6. {
  7. const feedTypes = {
  8. "application/rss+xml": gBundle.getString("feedRss"),
  9. "application/atom+xml": gBundle.getString("feedAtom"),
  10. "text/xml": gBundle.getString("feedXML"),
  11. "application/xml": gBundle.getString("feedXML"),
  12. "application/rdf+xml": gBundle.getString("feedXML")
  13. };
  14. // get the feeds
  15. var linkNodes = gDocument.getElementsByTagName("link");
  16. var length = linkNodes.length;
  17. for (var i = 0; i < length; i++) {
  18. var link = linkNodes[i];
  19. if (!link.href)
  20. continue;
  21. var rel = link.rel && link.rel.toLowerCase();
  22. var rels = {};
  23. if (rel) {
  24. for each (let relVal in rel.split(/\s+/))
  25. rels[relVal] = true;
  26. }
  27. if (rels.feed || (link.type && rels.alternate && !rels.stylesheet)) {
  28. var type = isValidFeed(link, gDocument.nodePrincipal, "feed" in rels);
  29. if (type) {
  30. type = feedTypes[type] || feedTypes["application/rss+xml"];
  31. addRow(link.title, type, link.href);
  32. }
  33. }
  34. }
  35. var feedListbox = document.getElementById("feedListbox");
  36. document.getElementById("feedTab").hidden = feedListbox.getRowCount() == 0;
  37. }
  38. function onSubscribeFeed()
  39. {
  40. var listbox = document.getElementById("feedListbox");
  41. openUILinkIn(listbox.selectedItem.getAttribute("feedURL"), "current",
  42. { ignoreAlt: true });
  43. }
  44. function addRow(name, type, url)
  45. {
  46. var item = document.createElement("richlistitem");
  47. item.setAttribute("feed", "true");
  48. item.setAttribute("name", name);
  49. item.setAttribute("type", type);
  50. item.setAttribute("feedURL", url);
  51. document.getElementById("feedListbox").appendChild(item);
  52. }