Skip to content

Instantly share code, notes, and snippets.

@travisjeffery
Created November 12, 2008 10:00
Show Gist options
  • Save travisjeffery/24126 to your computer and use it in GitHub Desktop.
Save travisjeffery/24126 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "twitter",
icon: "http://twitter.com/favicon.ico",
author: {
name: "Travis Jeffery",
email: "eatsleepgolf@gmail.com"
},
license: "GPL",
description: "Post to Twitter.",
help: "Select the command press space and type in your twitter status.",
takes: {
"twitter": noun_arb_text
},
preview: function(pblock, twitter) {
document = context.focusedWindow.document;
pblock.innerHTML = "Twitter Status: " + twitter.text;
},
execute: function(pblock, twitter) {
if (twitter.text.length > 140) {
pblock.innerHTML = "Twitter Statuses must be >= 140 characters."
} else {
var document = context.focusedWindow.document;
var params = {
status: twitter.text
};
var url = "http://twitter.com/statuses/update.xml?";
var http = new XMLHttpRequest();
for (key in params) {
url += "&" + key + "=" + params[key];
}
http.open("POST", url, true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment