This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.js
125 lines (88 loc) · 2.85 KB
/
page.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function so21896363() {
/*
/* Posted Code Starts Here
*/
var fileHandler = function () {
var _entry = null;
this.open = function(cb){
chrome.fileSystem.chooseEntry({ type: 'openDirectory' },
function(dirEntry) {
if (!dirEntry || !dirEntry.isDirectory) {
cb && cb(null);
return;
}
_entry = dirEntry;
listDir(_entry, cb);
});
};
this.save = function(filename, source) {
chrome.fileSystem.getWritableEntry(_entry, function(entry) {
entry.getFile(filename, {create:true}, function(entry) {
entry.createWriter(function(writer) {
writer.onwrite = function() {
writer.onwrite = null;
writer.truncate(writer.position);
};
writer.write(new Blob([source], {type: 'text/javascript'}));
});
});
});
};
this.saveAs = function(filename, source) {
chrome.fileSystem.chooseEntry({type:'openDirectory'},
function(entry) {
chrome.fileSystem.getWritableEntry(entry, function(entry) {
entry.getFile(filename, {create:true}, function(entry) {
entry.createWriter(function(writer) {
writer.onwrite = function() {
writer.onwrite = null;
writer.truncate(writer.position);
};
writer.write(new Blob([source], {type: 'text/javascript'}));
});
});
});
});
};
var listDir = function(dirent, cb, listing) {
if (listing === undefined) {
listing = [];
}
var reader = dirent.createReader();
var read_some = reader.readEntries.bind(reader,
function(ents) {
if (ents.length === 0) {
return cb && cb(listing);
}
var process_some = function (ents, i) {
for (; i < ents.length; i++) {
listing.push(ents[i]);
if (ents[i].isDirectory) {
return listDir(ents[i], process_some.bind(null, ents, i + 1), listing);
}
}
read_some();
};
process_some(ents, 0);
}, function() {
console.error('error reading directory');
});
read_some();
};
};
/*
* Posted Code Ends Here
*/
/*
* Added Code Starts Here
*/
var fh = new fileHandler();
fh.open(function(listing) {
console.log('opened', listing.map(function(e){return e.fullPath}).join('\n'));
fh.save('existing_dir/maybe_new_file','Some small data');
});
/*
* Added Code Ends Here
*/
}
so21896363();