Created
July 17, 2009 09:54
-
-
Save hamen/148982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is just a customization of original Twitter Ubiquity command by Mozilla | |
// I just replaced some strings. For credits refer to mozilla.com | |
const IDENTICA_STATUS_MAXLEN = 140; | |
CmdUtils.CreateCommand({ | |
names: ["identi.ca", "share using identi.ca"], | |
arguments: [ | |
{role: "object", label: 'status', nountype: noun_arb_text}, | |
{role: "alias", nountype: noun_type_twitter_user} | |
], | |
icon: "http://identi.ca/favicon.ico", | |
description: | |
"Sets your Identi.ca status to a message of at most 160 characters.", | |
help: ("You'll need a <a href=\"http://identi.ca\">Identica account</a>," + | |
" obviously. If you're not already logged in" + | |
" you'll be asked to log in."), | |
preview: function(previewBlock, args) { | |
var statusText = (args.object ? args.object.text : ''); | |
var usernameText = ""; | |
if (args.alias) { | |
usernameText = args.alias.text; | |
} else if (args.as) { | |
usernameText = args.as.text; | |
} | |
var previewTemplate = ( | |
"<div class='identica'>"+_("Updates your Identi.ca status ${username} to:")+"<br/>" + | |
"<b class='status'>${status}</b><br/><br/>" + | |
_("Characters remaining: <b>${chars}</b>") + | |
"<p><small>"+"</small></p></div>"); | |
var truncateTemplate = ( | |
"<strong>"+_("The last <b>${truncate}</b> characters will be truncated!")+"</strong>"); | |
var previewData = { | |
status: <>{statusText}</>.toXMLString(), | |
username: usernameText && _("(For user <b>${usernameText}</b>)"), | |
chars: IDENTICA_STATUS_MAXLEN - statusText.length | |
}; | |
var previewHTML = CmdUtils.renderTemplate( | |
CmdUtils.renderTemplate(previewTemplate, previewData), | |
{usernameText:usernameText}); | |
if (previewData.chars < 0) { | |
var truncateData = { | |
truncate: 0 - previewData.chars | |
}; | |
previewHTML += CmdUtils.renderTemplate(truncateTemplate, truncateData); | |
} | |
previewBlock.innerHTML = previewHTML; | |
}, | |
execute: function(args) { | |
var statusText = args.object.text; | |
if(statusText.length < 1) { | |
this._show(_("requires a status to be entered")); | |
return; | |
} | |
var updateUrl = "http://identi.ca/api/statuses/update.json"; | |
var updateParams = { | |
source: "ubiquity", | |
status: statusText | |
//dont cut the input since sometimes, the user selects a big url, | |
//and the total lenght is more than 140, but tinyurl takes care of that | |
}; | |
var me = this; | |
function sendMessage() { | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
me._show(_("error - status not updated")); | |
}, | |
success: function() { | |
me._show(/^d /.test(statusText) | |
? _("direct message sent") | |
: _("status updated")); | |
}, | |
username: login.username, | |
password: login.password | |
}); | |
} | |
var login; | |
var alias = args.alias; | |
if (alias && alias.text && alias.data) { | |
login = alias.data; | |
sendMessage(); | |
} else { | |
login = {username: null, | |
password: null}; | |
if (alias && alias.text) | |
login.username = alias.text; | |
sendMessage(); | |
} | |
}, | |
_show: function(txt){ | |
displayMessage({icon: this.icon, title: this.name, text: txt}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment