Skip to content

Instantly share code, notes, and snippets.

@ream88
Created December 3, 2008 12:02
Show Gist options
  • Save ream88/31511 to your computer and use it in GitHub Desktop.
Save ream88/31511 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "delicious",
homepage: "http://ryan.codecrate.com/",
author: { name: "Ryan Sonnek", email: "ryan@codecrate.com"},
contributors: ["Ryan Sonnek"],
license: "MIT",
description: "Tags the current site using delicious",
icon: "http://delicious.com/favicon.ico",
help: "Save the current url to delicious with the tags input by the user. Any selected text on the page will be recorded as the note.",
takes: {notes: noun_arb_text},
modifiers: {
tagged: noun_arb_text,
entitled: noun_arb_text
},
preview: function(pblock, notes, mods) {
var params = this.post_params(notes, mods);
html = "title: " + params.description + "<br />";
html += "tags: " + params.tags + "<br />";
html += "note: " + params.extended + "<br />";
pblock.innerHTML = html;
},
execute: function(notes, mods) {
jQuery.ajax({
type: "POST",
dataType: "xml",
url: "https://api.del.icio.us/v1/posts/add",
data: this.post_params(notes, mods),
error: function() {
displayMessage("Error saving bookmark to delicious");
},
success: function(xml) {
var result = jQuery(xml).find("result");
var code = result.attr("code");
if (code == "done") {
displayMessage("Bookmark saved to delicious!");
} else {
displayMessage("Error saving bookmark to delicious: " + code);
}
}
});
},
post_params: function(notes, mods) {
var document = context.focusedWindow.document;
var params = {
url: document.location,
description: mods.entitled.text || document.title,
extended: notes.text,
tags: mods.tagged.text
};
return params;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment