This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
import.js
107 lines (87 loc) · 2.65 KB
/
import.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var bgPage = chrome.extension.getBackgroundPage();
$(document).ready(function()
{
$('#import').click(function(){Import();});
$('#cancel').click(function(){window.close();});
});
// starts import
function Import()
{
if(document.getElementById("opml").value == "")
{
alert("Nothing to import");
return;
}
if(bgPage.options.feedsource == 1)
{
chrome.bookmarks.get(bgPage.options.feedfolderid, ImportBookmarks);
}
else
{
ImportFeeds();
}
}
// imports opml -> bookmarks
function ImportBookmarks(startNode)
{
var nodes = null;
var importCount = 0;
var opml = new DOMParser().parseFromString(document.getElementById("opml").value, 'text/xml');
if(!startNode || startNode.length == 0)
{
alert("Could not import because your bookmark folder is not found.");
return;
}
nodes = opml.getElementsByTagName("outline");
for(var i = 0;i < nodes.length;i++)
{
if(nodes[i].getAttribute("type") == "rss")
{
chrome.bookmarks.create({parentId: startNode[0].id, "title" : nodes[i].getAttribute("text"), "url" : nodes[i].getAttribute("xmlUrl")}, null);
importCount ++;
}
}
if(nodes.length == 0)
{
alert("No outline nodes of type 'rss' were found to import.");
return;
}
alert("Imported " + importCount + " feeds.");
window.close();
}
// imports opml -> feed list
function ImportFeeds()
{
var nodes = null;
var importCount = 0;
var maxOrder = 0;
var opml = new DOMParser().parseFromString(document.getElementById("opml").value, 'text/xml');
nodes = opml.getElementsByTagName("outline");
// get max order
for(var i = 0;i < bgPage.feeds.length; i++)
{
if(bgPage.feeds[i].order > maxOrder)
{
maxOrder = bgPage.feeds[i].order;
}
}
for(var i = 0;i < nodes.length; i++)
{
if(nodes[i].getAttribute("type") == "rss")
{
maxOrder ++;
bgPage.feeds.push(bgPage.CreateNewFeed(nodes[i].getAttribute("text"), nodes[i].getAttribute("xmlUrl"), bgPage.options.maxitems, maxOrder));
importCount ++;
}
}
if(nodes.length == 0)
{
alert("No outline nodes of type 'rss' were found to import.");
return;
}
localStorage["feeds"] = JSON.stringify(bgPage.feeds);
alert("Imported " + importCount + " feeds.");
bgPage.UpdateSniffer();
bgPage.ReloadViewer();
window.close();
}