// Version 1.2 // Uses code from: // http://www.captain.at/programming/xul // https://developer.mozilla.org/en/Writing_textual_data // http://maloki.net/projects/pingfm-ubiquity notesConf = { addLocation:function(location){ if (!Application.prefs.has("notes.location")) { Application.prefs.setValue("notes.location", location); } else { var new_key = Application.prefs.get("notes.location"); new_key.value = location; return new_key.value; } }, addEncoding:function(encoding){ if (!Application.prefs.has("notes.encoding")) { Application.prefs.setValue("notes.encoding", encoding); } else { var new_key = Application.prefs.get("notes.encoding"); new_key.value = encoding; return new_key.value; } }, getLocation:function(){ location = Application.prefs.get("notes.location"); if(location){ location=location.value return location; } else { location="C:\\Notes\\"; return "C:\\Notes\\"; } }, getEncoding:function(){ encoding = Application.prefs.get("notes.encoding"); if(encoding){ return encoding.value; } else { charset="UTF-8"; return "UTF-8"; } }, }; var location = notesConf.getLocation(); var charset = notesConf.getEncoding(); // Can be any character encoding name that Mozilla supports function save(WhatToSave,WhereToSave) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( WhereToSave ); if ( file.exists() == false ) { file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream ); outputStream.init( file, 0x04 | 0x08 | 0x10, 420, 0 ); var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"] .createInstance(Components.interfaces.nsIConverterOutputStream); os.init(outputStream, charset, 0, 0x0000); os.writeString( WhatToSave + "\r\n\r\n"); os.close(); outputStream.close(); } //note CmdUtils.CreateCommand({ name: "note", icon: "http://mike.thedt.net/ubiquity/note/Notes-16x16.png", homepage: "http://mike.thedt.net/", author: { name: "Stonos", email: "stonos@gmail.com"}, license: "MPL", description: "Saves inputted text", help: "Select the text you want to save and execute note", takes: {"input": noun_arb_text}, preview: function( pblock, input ) { var template = "Saves ${selected} to ${location}${title}.txt"; pblock.innerHTML = CmdUtils.renderTemplate(template, {"selected": input.html,"location": notesConf.getLocation(), "title": StripIllegalChars(CmdUtils.getDocument().title)}); }, execute: function(input) { save(input.text,location+StripIllegalChars(CmdUtils.getDocument().title)+".txt"); displayMessage("Saved note!"); } }); //notes-encoding CmdUtils.CreateCommand({ name: "notes-encoding", icon: "http://mike.thedt.net/ubiquity/note/Notes-16x16.png", homepage: "http://mike.thedt.net/", author: { name: "Stonos", email: "stonos@gmail.com"}, license: "MPL", description: "Changes the default encoding for saving notes", help: "Can be any character encoding name that Mozilla supports", takes: {"input": noun_arb_text}, preview: function( pblock, input ) { var template = "Changes encoding from ${oldEnc} to ${newEnc}"; pblock.innerHTML = CmdUtils.renderTemplate(template, {"oldEnc": charset, "newEnc": input.text}); }, execute: function(input) { notesConf.addEncoding(input.text); charset=input.text; } }); //notes-location CmdUtils.CreateCommand({ name: "notes-location", icon: "http://mike.thedt.net/ubiquity/note/Notes-16x16.png", homepage: "http://mike.thedt.net/", author: { name: "Stonos", email: "stonos@gmail.com"}, license: "MPL", description: "Changes the default location for saving notes", help: "Use double backslashes on the location!", takes: {"input": noun_arb_text}, preview: function( pblock, input ) { var template = "Changes location from ${oldLoc} to ${newLoc}"; pblock.innerHTML = CmdUtils.renderTemplate(template, {"oldLoc": location, "newLoc": input.text}); }, execute: function(input) { notesConf.addLocation(input.text); location=input.text; } }); //notes-view CmdUtils.CreateCommand({ name: "notes-view", icon: "http://mike.thedt.net/ubiquity/note/Notes-16x16.png", homepage: "http://mike.thedt.net/", author: { name: "Stonos", email: "stonos@gmail.com"}, license: "MPL", description: "View taken notes for this website.", help: "Type notes-view.", preview: "View notes for this website", execute: function(input) { Utils.openUrlInBrowser(location+StripIllegalChars(CmdUtils.getDocument().title)+".txt"); } }); function StripIllegalChars(str) { return str.replace(/[\\/:\*?<>\|]/gi, ""); }