Skip to content

Instantly share code, notes, and snippets.

@cilquirm
Created January 21, 2009 20:02
Show Gist options
  • Save cilquirm/50154 to your computer and use it in GitHub Desktop.
Save cilquirm/50154 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "delicious",
homepage: "http://ryan.codecrate.com/",
author: { name: "Ryan Sonnek", email: "[email protected]"},
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;
}
})
/* This is a template command */
CmdUtils.CreateCommand({
name: "example",
icon: "http://example.com/example.png",
homepage: "http://example.com/",
author: { name: "Your Name", email: "[email protected]"},
license: "GPL",
description: "A short description of your command",
help: "how to use your command",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
var template = "Hello ${name}";
pblock.innerHTML = CmdUtils.renderTemplate(template, {"name": "World!"});
},
execute: function(input) {
CmdUtils.setSelection("You selected: "+input.html);
}
});
/* This is a template command */
CmdUtils.CreateCommand({
name: "example",
icon: "http://example.com/example.png",
homepage: "http://example.com/",
author: { name: "Your Name", email: "[email protected]"},
license: "GPL",
description: "A short description of your command",
help: "how to use your command",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
var template = "Hello ${name}";
pblock.innerHTML = CmdUtils.renderTemplate(template, {"name": "World!"});
},
execute: function(input) {
CmdUtils.setSelection("You selected: "+input.html);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment