-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.js
48 lines (43 loc) · 1.49 KB
/
extract.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
function walk() {
var parent = arguments[0];
var indent = arguments[1];
var result = "";
var children = parent.childNodes;
var folderName = "";
var folded = "";
for (var i = 0; i < children.length; i++) {
var object = children.item(i);
if (object.nodeName == "HR") {
result += indent + "<separator/>\n";
}
if (object.nodeName == "H3") {
folderName = object.innerHTML;
folded = object.folded;
if (object.folded == undefined)
folded = "false";
else
folded = "true";
}
if (object.nodeName == "A") {
result += indent + "<bookmark href=\"" + encodeURI(object.href).replace(/&/g, '&') + "\">\n";
result += indent + indent + "<title>" + object.innerHTML + "</title>\n";
result += indent + "</bookmark>\n";
}
var currentIndent = indent;
if (object.nodeName == "DL") {
result += indent + "<folder folded=\"" + folded + "\">\n";
indent += " ";
result += indent + "<title>" + folderName + "</title>\n";
}
result += walk(object, indent);
if (object.nodeName == "DL") {
result += currentIndent + "</folder>\n";
}
}
return result;
}
var xbel = walk(document, " ");
if (xbel != "") {
xbel = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE xbel>\n<xbel version=\"1.0\">\n" + xbel + "</xbel>\n";
}
xbel;