diff --git a/README.markdown b/README.markdown index 2130936..dfd73c1 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ Firefox's [Vimperator](http://vimperator.org/trac/wiki/Vimperator) extension. ### Install -Copy delicious.js to your ~/.vimperator/plugins directory. +Copy delicious.js to your ~/.vimperator/plugin directory. ### Usage Use by going to some site you want to bookmark and do :delicious followed by diff --git a/plugin/delicious.js b/plugin/delicious.js new file mode 100644 index 0000000..445cb9e --- /dev/null +++ b/plugin/delicious.js @@ -0,0 +1,77 @@ +// Vimperator Plugin: 'Delicious' +// Last Change: 25-Aug-2009 +// License: MIT +// Maintainer: Travis Jeffery +// Usage: Use :delicious "description in quotes (optional)" command +// Usage: if successfully posted you will see "done" echoed +// Modified by: Egon Hyszczak +// Changes made: Added private bookmarks (pvt) and Twitter functionality (for:@twitter) + +commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", + function(args) { + var title = buffer.title; + var url = "https://api.del.icio.us/v1/posts/add?"; + url += "&url=" + encodeURIComponent(buffer.URL); + url += "&description=" + encodeURIComponent(title); + var tags; + var statusString = ''; + var extended; + + var re = new RegExp(/"([^"]+)"/); + var ext = args.string.match(re); + if (ext) { + extended = encodedURIComponent(ext[1]); + url += "&extended=" + extended; + tags = args.string.substr(ext[0].length); + } else { + tags = args.string; + } + + //If the 'pvt' tag is used lock the bookmark from public access + if(tags.match("pvt")) { + //Replace pvt with empty string + tags = tags.replace("pvt", ""); + url += "&shared=no"; + statusString += '[PRIVATE] '; + } else { + url += "&shared=yes"; + } + + //Remove superfluous whitespace + var whitespace = new RegExp(/\s{2,}/); + tags = tags.replace(whitespace, " "); + tags = tags.trim(); + + url += "&tags=" + encodeURIComponent(tags); + + //Twitter + if(tags.match("for:@twitter")) { + //Use extended message if given + if(ext) { + url += "&share_msg=" + extended; + } else { + if(title.length >= 110) { + title = title.substr(0,110).trim(); + title += "..."; + url += "&share_msg=" + encodeURIComponent(title); + } else { + url += "&share_msg=" + encodeURIComponent(title); + } + } + url += "&recipients=" + encodeURIComponent("@twitter"); + } + + var xhr = new XMLHttpRequest(); + xhr.open("POST", url, false); + xhr.send(null); + var xml = (new DOMParser()).parseFromString(xhr.responseText, "text/xml"); + var status = xml.getElementsByTagName('result')[0].getAttribute('code'); + + if(status == "done") { + statusString += "Added bookmark for " + buffer.URL + " [" + tags + "]"; + liberator.echo(statusString); + } else { + liberator.echo(status); + } + } +); diff --git a/plugins/delicious.js b/plugins/delicious.js deleted file mode 100644 index aab3ba0..0000000 --- a/plugins/delicious.js +++ /dev/null @@ -1,30 +0,0 @@ -// Vimperator Plugin: 'Delicious' -// Last Change: 25-Aug-2009 -// License: MIT -// Maintainer: Travis Jeffery -// Usage: Use :delicious "description in quotes (optional)" command -// Usage: if successfully posted you will see "done" echoed - -commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", - function(args) { - var url = "https://api.del.icio.us/v1/posts/add?"; - url += "&url=" + encodeURIComponent(buffer.URL); - url += "&description=" + encodeURIComponent(buffer.title); - var re = new RegExp(/"([^"]+)"/); - var ext = args.string.match(re); - if (ext) { - url += "&extended=" + encodeURIComponent(ext[1]); - url += "&tags=" + encodeURIComponent(args.string.substr(ext[0].length)); - } else { - url += "&tags=" + encodeURIComponent(args.string); - } - - var xhr = new XMLHttpRequest(); - xhr.open("POST", url, false); - xhr.send(null); - var xml = (new DOMParser()).parseFromString(xhr.responseText, "text/xml"); - var status = xml.getElementsByTagName('result')[0].getAttribute('code'); - - liberator.echo(status); - } -);