Skip to content

Instantly share code, notes, and snippets.

@gialloporpora
Created November 29, 2009 02:30
Show Gist options
  • Save gialloporpora/244766 to your computer and use it in GitHub Desktop.
Save gialloporpora/244766 to your computer and use it in GitHub Desktop.
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["example"],
description: "A short description of your command.",
help: "How to use your command.",
author: {
name: "Your Name",
email: "[email protected]",
homepage: "http://labs.mozilla.com/",
},
license: "GPL",
homepage: "http://ubiquity.mozilla.com/",
icon: "http://www.mozilla.com/favicon.ico",
arguments: [{role: "object", nountype: noun_arb_text, label: "text"}],
execute: function execute(args) {
displayMessage("You input: " + args.object.text, this);
},
preview: function preview(pblock, args) {
pblock.innerHTML = "Your input is " + args.object.html.bold() + ".";
},
});
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["example"],
description: "A short description of your command.",
help: "How to use your command.",
author: {
name: "Your Name",
email: "[email protected]",
homepage: "http://labs.mozilla.com/",
},
license: "GPL",
homepage: "http://ubiquity.mozilla.com/",
icon: "http://www.mozilla.com/favicon.ico",
arguments: [{role: "object", nountype: noun_arb_text, label: "text"}],
execute: function execute(args) {
displayMessage("You input: " + args.object.text, this);
},
preview: function preview(pblock, args) {
pblock.innerHTML = "Your input is " + args.object.html.bold() + ".";
},
});
const TWITTER_STATUS_MAXLEN = 140;
// providers "using twitter", "using digg", etc.
CmdUtils.CreateCommand({
names: ["mozillaca", "share using mozillaca"],
description:
"Sets your mozillaca status to a message of at most 140 characters.",
help: ("You'll need a <a href=\"http://mozillaca.com\">mozillaca.com account</a>," +
" obviously. If you're not already logged in" +
" you'll be asked to log in."),
icon: "http://mozillaca.com/favicon.ico",
arguments: [{role: "object", label: "status", nountype: noun_arb_text},
{role: "alias", nountype: noun_type_twitter_user}],
preview: function twitter_preview(previewBlock, args) {
var statusText = args.object.text;
var usernameText = args.alias.text;
var previewTemplate = (
"<div class='twitter'>"+
_("Updates your Mozillaca status ${username} to:") + "<br/>" +
"<b class='status'>${status}</b><br/><br/>" +
_("Characters remaining: <b>${chars}</b>") +
"<p><small>" +
_("tip: tweet @mozillaubiquity for help") +
"</small></p></div>");
var previewData = {
status: args.object.html,
username: usernameText && _("(For user <b>${usernameText}</b>)",
{usernameText: args.alias.html}),
chars: TWITTER_STATUS_MAXLEN - statusText.length,
};
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
if (previewData.chars < 0)
previewHTML += (
"<strong>" +
_("The last <b>${truncate}</b> characters will be truncated!",
{truncate: -previewData.chars}) +
"</strong>");
previewBlock.innerHTML = previewHTML;
},
execute: function twitter_execute(args) {
var statusText = args.object.text;
if (!statusText.length) {
this._show(_("requires a status to be entered"));
return;
}
var me = this;
var login = args.alias.data || {};
jQuery.ajax({
type: "POST",
url: "https://mozillaca.com/api/statuses/update.json",
data: {
//dont cut the input since sometimes, the user selects a big url,
//and the total lenght is more than 140, but bit.ly takes care of that
status: statusText,
source: "ubiquity",
},
dataType: "json",
error: function twitter_error() {
me._show(_("error - status not updated"));
},
success: function twitter_success() {
me._show(/^d /.test(statusText)
? _("direct message sent")
: _("status updated"));
},
username: login.username,
password: login.password,
});
},
_show: function twitter__show(txt) {
displayMessage(txt, this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment