Skip to content

Instantly share code, notes, and snippets.

@958
Created January 22, 2009 02:31
Show Gist options
  • Save 958/50384 to your computer and use it in GitHub Desktop.
Save 958/50384 to your computer and use it in GitHub Desktop.
[Sleipnir]Twitter Post Action
(function(){
// --- user customize start ---
var showMessage = true; // show result message
var fromAddressBar = true; // true:address bar, false:prompt
// --- user customize end ---
var TwitPost = function(){this.initialize.apply(this, arguments);};
TwitPost.prototype = {
initialize:function(status){
this.post(status);
},
post:function(s){
var status = encodeURIComponent(s);
var data = 'status=' + status;
var url = 'http://twitter.com/statuses/update.json';
var http = sleipnir.CreateObject('Microsoft.XMLHTTP');
http.open('POST', url, false);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.send(data);
if (http.status == 200) {
if (showMessage) alert('twittered!');
} else if (http.status == 401) {
if (showMessage) alert('401 Authorization Required');
} else {
if (showMessage) alert(http.statusText);
}
}
};
var status = '';
// if (_window.LDRize) {
// var RegExpression = {
// twitter:/https?:\/\/twitter\.com\/(\w*)\/status\/\d*/
// ,trim:/^\s*(.*)\s*$/
// }
// var ret = [];
// var pins = _window.LDRize.getPinList();
// if (pins.length == 0)
// pins = [_window.LDRize.getCurrentParagraph()];
// for (var i = 0; i < pins.length; i++) {
// var a = _window.LDRize.getParagraphLink(pins[i]);
// if (a && a.match(RegExpression.twitter))
// ret.push('@' + RegExp.$1 + ' ');
// }
// _window.LDRize.clearPin();
// status = ret.join('');
// }
if (fromAddressBar && sleipnir.API)
status = sleipnir.API.AddressBarString;
else
status = prompt('What are you doing?', status);
if (status != null && status != 'null' && status != '' && status != location.href)
new TwitPost(status);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment