let list_files = function (filetype, callback) {
var d = navigator.getDeviceStorage("sdcard");
var cursor = d.enumerate();
cursor.onsuccess = function () {
if (!this.result) {
console.log("finished");
}
if (cursor.result.name !== null) {
var file = cursor.result;
let n = file.name.split(".");
let file_type = n[n.length - 1];
if (file_type == filetype) {
callback(file.name);
}
this.continue();
}
};
cursor.onerror = function () {
console.warn("No file found: " + this.error);
};
};`
//callback
` let list_ics = function () {
let file_list = [];
let cb = function (result) {
file_list.push(result);
let fn = result.split("/");
fn = fn[fn.length - 1];
document
.querySelector("div#options div#import-text")
.insertAdjacentHTML(
"afterend",
'<button class="item dynamic" data-function="import" data-filename="' +
result +
'">' +
fn +
"</button>"
);
};
list_files("ics", cb);
};`