-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdesktop.js
32 lines (30 loc) · 1.03 KB
/
desktop.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
function desktopSave(fail, success, text){
saveFileToDesktop("justwritedammit.jwd", "application/octet-stream", utf8_to_b64(text));
success();
}
function saveFileToDesktop(filename, type, bin64){
var href = fmt("data:$1;filename=$2;base64,$3", type, filename, bin64);
var link = a({
download: filename,
href: href
}, "save");
hide(link);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function desktopLoad(fail, success){
var load = function(){
Array.prototype.forEach.call(storageFile.files, function (f){
var reader = new FileReader();
reader.addEventListener("load", function (evt){
parseFileData(evt.target.result, fail, success);
});
reader.addEventListener("error", fail);
reader.readAsText(f);
});
storageFile.removeEventListener("change", load, false);
};
storageFile.addEventListener("change", load, false);
storageFile.click();
}