-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.js
66 lines (62 loc) · 1.86 KB
/
files.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
function readjson(path){
if (window.File && window.FileReader && window.FileList && window.Blob) {
if(path){
var r = new FileReader();
r.onload = function(e){
var contents=JSON.parse(r.result);
if(!books.find(function(i){return contents.bookname == i.bookname})){
var bk=new book(contents.bookname);
for (var i of contents.areas){
bk.area(i.subname,i.name);
for (var j of i.markups){
bk.personadd(j.person);
if(!!j.taken){
j.taken=new date(j.taken);
}
if(!!j.returned){
j.returned=new date(j.returned);
}
bk.area(i.subname,i.name,j);
bk.addtype(i.subname,i.name,i.type);
}
}
books.push(bk);
drawsettings();
}else{
alert('Another book \"'+contents.bookname+'\" exists.')
}
}
r.readAsText(path);
}else{
alert('No path declared.')
}
}else{
alert('The File APIs are not fully supported by your browser.');
}
}
function writejson(text,filename,type){
if (window.Blob) {
if(confirm("Never ever put any names online in any form! \n DO NOT SEND any files containing any names \n VIA EMAIL or any other online services! \n If you still wish to do so, use anonymized versions and encrypt them! \n Take good care of the file's security and delete it if not needed.")){
var bl = new Blob([strbreak(text)],{type:'text/plain'});
var element=document.createElement("a");
element.id="removethis";
element.download = filename+(new date).date2str()+type;
element.href = window.URL.createObjectURL(bl);
$('body').append(element);
element.click();
$('#removethis').remove();
}
}else{
alert('No HTML5 Blob support :( ')
}
}
function strbreak(text){
var i = 1;
while (i<text.length){
if (text[i-1]+text[i]=="}," || text[i-1]+text[i]==":["){
text=text.slice(0,i+1)+"\r\n"+text.slice(i+1,text.length);
}
i++;
}
return text;
}