function timestamp() { var utc = new Date(); var loc = new Date(utc - utc.getTimezoneOffset() * 60 * 1000); return loc.toISOString().replace("T", " ").replace(/\..*/, "").replace(/:/g, "."); } function editnote() { var file = std.open("data/note.md", "w"); file.puts(currentnote.content); file.close(); os.exec(["cp", "data/note.md", "data/backup.md"]); os.exec(settings.editor.concat("data/note.md")); var newcontent = std.loadFile("data/note.md"); if (currentnote.content != newcontent) { os.exec(["diff", "--color", "data/backup.md", "data/note.md"]); currentnote.content = newcontent; notes.splice(notes.indexOf(currentnote), 1); notes.unshift(currentnote); file = std.open("data/data2.json", "w"); file.puts(JSON.stringify(notes)); file.close(); os.exec([settings.gpg, "--encrypt", "--yes", "--trust-model", "always", "--output", "data/data2.acs", "--armor", "-r", settings.gpguser, "data/data2.json"]); var newdata = std.loadFile("data/data2.acs"); console.log("sending data file to server..."); var postdata = "action=push&password=" + settings.password + "&data=" + encodeURIComponent(newdata); file = std.open("data/postdata", "w"); file.puts(postdata); file.close(); os.exec(["curl", "-X", "POST", "-d", "@data/postdata", settings.url + "/handler.php"]); console.log("...done."); } else { console.log("no change."); } } // Init var settings = JSON.parse(std.loadFile("settings.json")); var command = scriptArgs.length <= 1 ? "list" : scriptArgs[1]; var currentnote = null; // Run part if (command == "help" || command == "-h" || command == "--help") { var appcmd = "./qjs q.js"; print(`list notes: ${appcmd} [list]`); print(`edit a note: ${appcmd} [open|edit]