Skip to content

Instantly share code, notes, and snippets.

@cheeming
Created February 26, 2009 04:14
Show Gist options
  • Save cheeming/70649 to your computer and use it in GitHub Desktop.
Save cheeming/70649 to your computer and use it in GitHub Desktop.
Ubiquity script for posting to Identi.ca, there is a small improvement for my own use case: it will display some twitter user names so its easier to reply to when you're at http://www.twitter.com/home
// based on the work done by Corey at http://groups.google.com/group/ubiquity-firefox/browse_thread/thread/14fcb5653c33a673/a046a069f0236938#a046a069f0236938
const IDENTICA_STATUS_MAXLEN = 140;
CmdUtils.CreateCommand({
name: "mytwit",
icon: "http://identi.ca/favicon.ico",
takes: {status: noun_arb_text},
modifiers: {},
preview: function(previewBlock, statusText) {
var previewTemplate = "Updates your Identi.ca status to: <br /><b>${status}</b><br /><br />Characters remaining: <b>${chars}</b><br />Reply to: <b>${reply_to}</b><br />Reply to candidates: <b>${reply_to_candidates}</b>";
var truncateTemplate = "<br />The last <b>${truncate}</b> characters will be truncated!";
var reply_to = "";
var status_list = statusText.text.split(/\s/);
for (var i=status_list.length-1; i>=0; i--) {
if (status_list[i].substr(0, 1) == "@") {
reply_to = status_list[i];
break;
}
}
var candidate_list = jQuery("a[class='screen-name']", CmdUtils.getDocument().body);
var candidate_set = {};
if (reply_to.length > 0) {
for (var i=0; i<candidate_list.length; i++) {
if (candidate_list[i].text.substr(0, reply_to.length-1) == reply_to.substr(1)) {
candidate_set[candidate_list[i].text] = "";
}
}
}
var reply_to_candidates = "";
for (var i in candidate_set) {
reply_to_candidates += i + " ";
}
var previewData = {
status: statusText.text,
chars: IDENTICA_STATUS_MAXLEN - statusText.text.length,
reply_to: reply_to,
reply_to_candidates: reply_to_candidates
};
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
if(previewData.chars < 0) {
var truncateData = {
truncate: 0 - previewData.chars
};
previewHTML += CmdUtils.renderTemplate(truncateTemplate, truncateData);
}
previewBlock.innerHTML = previewHTML;
},
execute: function(statusText) {
if(statusText.text.length < 1) {
displayMessage("Identi.ca requires a status to be entered");
return;
}
var updateUrl = "http://identi.ca/api/statuses/update.json";
var updateParams = {
source: "ubiquity",
status: statusText.text
};
jQuery.ajax({
type: "POST",
url: updateUrl,
data: updateParams,
dataType: "json",
error: function() {
displayMessage("Identi.ca error - status not updated");
},
success: function() {
displayMessage("Identi.ca status updated");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment