diff options
Diffstat (limited to 'twitter.js')
-rw-r--r-- | twitter.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/twitter.js b/twitter.js new file mode 100644 index 0000000..c8db18d --- /dev/null +++ b/twitter.js @@ -0,0 +1,38 @@ +// Vimperator plugin: 'Update Twitter'
+// Last Change: 17-Mar-2008. Jan 2008
+// License: Creative Commons
+// Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid
+//
+// update twitter status script for vimperator0.6.*
+
+(function(){
+ var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
+ function sayTwitter(username,password,stat){
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST","http://twitter.com/statuses/update.json",false,username,password);
+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+ xhr.send("status=" + encodeURIComponent(stat));
+ }
+ vimperator.commands.addUserCommand(['twitter'], 'Change twitter status',
+ function(arg,special){
+ var password;
+ var username;
+ try {
+ var logins = passwordManager.findLogins({}, 'http://twitter.com', 'https://twitter.com', null);
+ if(logins.length)
+ [username, password] = [logins[0].username, logins[0].password];
+ else
+ vimperator.echoerr("Twitter: account not found");
+ }
+ catch(ex) {
+ }
+
+ if(special){
+ arg = arg.replace(/%URL%/g, vimperator.buffer.URL)
+ .replace(/%TITLE%/g ,vimperator.buffer.title);
+ }
+
+ sayTwitter(username,password,arg);
+ },{ }
+ );
+})();
|