// // persistence // beef.execute(function() { // insert hook into index.html // // 1. locate index.html // 2. read it in // 3. add our hook // 4. write it back out to same location // 1. locate index.html // // list dirs under current dir // one should be something.app // inside that should be a www dir and in that an index.html // // write the file with new hook function write_file(text) { function fail () { console.log('write_file fail') } function gotFileWriter(writer) { writer.onwrite = function(evt) { console.log("write success"); } writer.write(text); } function gotFileEntry(fileEntry) { fileEntry.createWriter(gotFileWriter, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("../"+window.tmpfilename+"/www/index.html", null, gotFileEntry, fail); } window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } // find
and insert our hook. function replace_text(text) { re = new RegExp("", "g"); hook_url = '<%== @hook_url %>'; new_text = text.replace(re, "") write_file(new_text); } function read_index(app_name) { function fail () { console.log('read_index fail') } function readFile(file) { var reader = new FileReader(); reader.onloadend = function(evt) { //console.log("Read as text"); console.log(evt.target.result); replace_text(evt.target.result); }; reader.readAsText(file); } function gotFileEntry(fileEntry) { fileEntry.file(readFile, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("../"+app_name+"/www/index.html", null, gotFileEntry, fail); } window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function locate() { function result(entries) { console.log('result'); var i; for (i=0; i