Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions plugin/delicious.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Vimperator Plugin: 'Delicious'
// Last Change: 25-Aug-2009
// License: MIT
// Maintainer: Travis Jeffery <travisjeffery@gmail.com>
// Usage: Use :delicious "description in quotes (optional)" <tags delimited by spaces> command
// Usage: if successfully posted you will see "done" echoed
// Modified by: Egon Hyszczak <gone404@gmail.com>
// 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);
}
}
);
30 changes: 0 additions & 30 deletions plugins/delicious.js

This file was deleted.