-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathconvertbookmarks.html
77 lines (65 loc) · 2.39 KB
/
convertbookmarks.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<meta name="keywords" content="uuid收藏夹,书签,Bookmark" />
<meta name="description" content="一个基于Git托管去中心化的收藏夹" />
<base target="_blank" />
<title>转换浏览器导出的HTML书签</title>
<link rel="icon" href="favicon.ico">
</head>
<body>
<input type="file" id="txtFile" style="margin-bottom:5px" />
<div>
<div id="editor">Loading ...</div>
</div>
<link href="https://npmcdn.com/[email protected]/dist/netnrmd.css" rel="stylesheet" />
<script src="https://npmcdn.com/[email protected]/dist/netnrmd.bundle.js"></script>
<script>
let nmd = netnrmd.init('#editor', {
resize: function (ch) {
this.height(ch - 50);
}
});
document.querySelector('#txtFile').addEventListener('change', function () {
let file = this.files[0];
if (file) {
let reader = new FileReader();
reader.onload = function (e) {
let mds = [];
let bm = netnrmd.createDom('div', null, e.target.result);
mds.push("# " + bm.querySelector('h1').innerHTML);
treeEach(bm, mds);
nmd.setmd(mds.join('\r\n'));
};
reader.readAsText(file);
}
});
function treeEach(bm, mds) {
for (let i = 0; i < bm.children.length; i++) {
let n = bm.children[i];
switch (n.nodeName) {
case "H3":
mds.push('');
mds.push("### " + n.innerHTML);
break;
case "DL":
case "P":
treeEach(n, mds);
break;
case "DT": {
if (n.children.length == 1) {
let na = n.querySelector('a');
mds.push('- [' + na.innerHTML.replace(/`/g, '\\`') + '](' + na.href + ')');
} else {
treeEach(n, mds);
}
}
break;
}
}
}
</script>
</body>
</html>