Skip to content

Instantly share code, notes, and snippets.

@pypeng
Created October 29, 2008 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pypeng/20656 to your computer and use it in GitHub Desktop.
Save pypeng/20656 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "r-douban",
homepage: "http://www.douban.com/people/aka/",
author: { name: "Yu Peng", email: "pengyu.py@gmail.com"},
contributors: ["Yu Peng"],
license: "MPL",
description: "Recommend the current site to douban",
help: "posts the current tab url to douban with the comment input by the user.",
_params: function(comment,mods) {
var document = context.focusedWindow.document;
var params = {
uid: document.location,
title: (mods.entitled.text || document.title),
type: 'I',
comment: comment.text,
};
return params;
},
takes: {"comment": noun_arb_text},
modifiers: {entitled: noun_arb_text},
preview: function(pblock, comment, mods) {
var document = context.focusedWindow.document;
html = "title: " + (mods.entitled.text || document.title) + "<br />";
html += "comment: " + comment.text;
pblock.innerHTML = html;
},
execute: function(comment, mods) {
jQuery.ajax({
type: "POST",
dataType: "xml",
url: "http://www.douban.com/recommend/",
data: this._params(comment, mods),
});
}
})
CmdUtils.CreateCommand({
name: "s-douban",
homepage: "http://www.douban.com/people/aka/",
author: { name: "Yu Peng", email: "pengyu.py@gmail.com"},
contributors: ["Yu Peng"],
license: "MPL",
description: "I say to douban",
help: "posts saying to douban",
takes: {"say": noun_arb_text},
preview: function(pblock, say) {
html = "saying: " + say.text;
pblock.innerHTML = html;
},
execute: function(say) {
jQuery.ajax({
type: "POST",
dataType: "xml",
url: "http://www.douban.com/contacts/",
data: {'mb_text':say.text},
});
}
})
function chain(commands, nameCommand){
var commands = commands.split(",");
CmdUtils.CreateCommand({
name: nameCommand,
takes: {argument : noun_arb_text},
execute: function(directObject){
//displayMessage(directObject.text);
for(var i = 0; i<commands.length ;i++){
var command = jQuery.trim(commands[i]);
command = command.replace("[input]", directObject.text);
displayMessage(command);
var context = {
screenX: 0,
screenY: 0,
lastCmdResult: null
};
context.focusedWindow = window.document.commandDispatcher.focusedWindow;
context.focusedElement = null;//window.document.commandDispatcher.focusedElement;
window.gUbiquity.__cmdManager.updateInput(command,context);
window.gUbiquity.__cmdManager.execute(context);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment