-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
111 lines (96 loc) · 2.95 KB
/
script.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
107
108
109
110
111
var OPML = [];
function parseOPML(e){
var opml = e.target.result;
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(opml,"text/xml");
allOutlines = xmlDoc.getElementsByTagName("body")[0].childNodes;
OPML = interpreteOPML(allOutlines);
showOPML();
}
function interpreteOPML(Outlines){
var tempOPML = [];
for (var i = 0; i < Outlines.length; i++){
if (Outlines[i].nodeType !== 3){
tempOPML.push({text: Outlines[i].getAttribute("text"),children: interpreteOPML(Outlines[i].childNodes) });
}
}
return tempOPML;
}
function createItems(myObject){
var list = document.createElement("ul");
for (var i = 0; i < myObject.length; i++){
var item = document.createElement("li");
//item.classList.add("hide");
var text = document.createTextNode(myObject[i].text);
item.appendChild(text);
list.appendChild(item);
list.appendChild(createItems(myObject[i].children));
}
return list;
}
function showOPML(){
var list = createItems(OPML);
document.body.appendChild(list);
// $("body > ul > li").addClass("top").removeClass("hide");
// $("li").click(function(){
// $(this).next().contents().find("li").addClass("hide");
// $(this).next().children("li").removeClass("hide");
// });
}
function handleFiles(files){
f = files[0];
myreader = new FileReader();
myreader.onload = function(e) {
parseOPML(e);
};
myreader.readAsText(f);
remove_dropzone();
}
function remove_dropzone(){
var dropzone = document.getElementById("dropzone");
dropzone.parentNode.removeChild(dropzone);
var orElem = document.getElementById("or");
orElem.parentNode.removeChild(orElem);
var buttonElem = document.getElementById("fileSelect");
buttonElem.parentNode.removeChild(buttonElem);
var fileElem = document.getElementById("fileElem");
fileElem.parentNode.removeChild(fileElem);
}
function drop(e){
e.preventDefault();
var dropzone = document.getElementById("dropzone");
document.getElementById("dropzone").classList.remove("active");
var dt = e.dataTransfer;
var files = dt.files;
handleFiles(files);
return false;
}
function dragenter(e) {
document.getElementById("dropzone").classList.add("active");
e.preventDefault();
}
function dragexit(e){
document.getElementById("dropzone").classList.remove("active");
e.preventDefault();
}
function run(e){
//Init Dropzone
var dropzone = document.getElementById("dropzone");
dropzone.addEventListener("dragenter", dragenter, false);
dropzone.addEventListener("dragexit", dragexit, false);
dropzone.addEventListener("drop", drop, false);
//Init File Input
document.getElementById("fileSelect").addEventListener("click", function (e) {
var fileElem = document.getElementById("fileElem");
if (fileElem) {
//send Click to input field
fileElem.click();
}
e.preventDefault(); // prevent navigation to "#"
}, false);
var fileElem = document.getElementById("fileElem");
fileElem.addEventListener("change", function (e){
handleFiles(this.files);
}, false);
}
document.addEventListener("DOMContentLoaded",run);