TwitterにPOSTするJS
<html> <head> <title>どうでもいい</title> <script type="text/javascript"> //ぽっぽついったー0.2 // // 使い方の例 // // var Poppo=new Twitter(id,status); // Poppo.post(status); // Poppo.close(); // // *1 上の宣言におけるid/statusは任意です。 // idは複数のtwitterインスタンスを制御(DOM上のFORMなど)します。 // 自動で乱数が割り当てられますが、明示することも可能です。 // statusは、post()実行時に送られる文字列をセットします。 // *2 post()実行時にstatusを明記すれば、POSTされる文字列のオーバーライドができます。 // なお、インスタンス生成時とpost時のどちらにもstatusが無いと、POSTに失敗します。 // *3 close()は最後にDOMを掃除するために使います。これ無しで使いっぱなしでもたぶん大丈夫です。 // // by @dolpen (http://3rd.geocities.jp/tdnskbn/) // //ここからライブラリ var Twitter = function(id,status){ this.id=(id)?id:Math.floor(Math.random()*32768).toString(); this.status=(status)?status:''; this.init(); }; Twitter.prototype = { apiname: 'http://twitter.com/statuses/update.xml', id:'', field:null, form:null, text:null, dmwin:null, init:function() { this.field = document.body; this.form = document.createElement('form'); this.form.action = this.apiname; this.form.method = 'POST'; this.form.target = this.id; this.form.style.display='none'; this.text = document.createElement('input'); this.text.name='status'; this.text.type='text'; this.text.value=''; this.dmwin = document.createElement('iframe'); this.dmwin.name=this.id; this.dmwin.style.display='none'; this.form.appendChild(this.text); this.field.appendChild(this.dmwin); this.field.appendChild(this.form); }, post : function(str) { this.status=str?str:this.status; this.text.value=this.status; this.form.submit(); }, close:function(){ this.field.removeChild(this.dmwin); this.field.removeChild(this.form); } }; //ここまでライブラリ var Poppo; window.onload=function(){ Poppo=new Twitter(); Poppo.post('ぽっぽ!'); }; window.onunload=function(){ Poppo.close(); }; </script> </head> <body> <div id="dummy"></dummy> </body> </html>
何をいまさら感が否めないけどねぇ。