I have this webpage for converting text to chordpro. Today the content is modified in the text area; forcing me to open a text editor and then paste the text area content there, but I'd rather open a save file dialogue so that the contents can be saved to disk directly. I've tried to figure out how to make use of HTML5 Filesaver and I think I'm almost there, but I can't figure out how to provide the file system (fs)? Chrome keeps telling me fs is undefined (which it is as I haven't provided it).
Am I approaching this the right way and is there anything more than the file system that I need to provide for this to work?
This is how far I've gotten. HTML input is:
<button type="button" onclick=saveTextArea();>Convert</button>
and the Javascript is:
function saveTextArea(fs) {
"use strict";
convertToChordpro(); // Converts text area value to chordpro format
var textArea = document.getElementById('textArea');
var artist = document.getElementById('artist').value;
var title = document.getElementById('title').value;
var fileName = (artist && title) ? artist + "-" + title + ".txt" : "artist-title.txt";
fs.root.getFile(fileName, {create: true}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwrite = function(e) {
console.log('Write completed.');
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
var bb = new BlobBuilder();
bb.append(textArea.value);
fileWriter.write(bb.getBlob('text/plain'));
}, onError);
}, onError);
}
function onError() {}
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(TEMPORARY, 1024*1024, saveTextArea, onError);