Twit! ブックマークレットの Google Chrome 対策

Twit! ブックマークレット(見ているページを Twitter に投稿)が Google Chrome文字化けするということを id:koizuka さんから聞いて修正。
というか Safari でも化けてたので WebKit 対策ということになる。

Twit!ブックマークレットのリンクが書けないので、登録後に?までを削除してください)

javascript:(function(){if(m=prompt('','Reading')){w=window.open('','_blank','width=0,height=0');f=w.document.createElement('form');f.setAttribute('action','http://twitter.com/statuses/update.xml');f.setAttribute('method','POST');f.setAttribute('accept-charset','utf-8');i=w.document.createElement('input');i.setAttribute('type','hidden');i.setAttribute('name','status');i.setAttribute('value',m+'%20'+document.title+'%20'+location.href);f.appendChild(i);w.document.documentElement.appendChild(f);f.submit();w.onunload=function(){w.close();}}}())

付け足したのは form 要素の accept-charset="utf-8"。
Chrome では認証ウィンドウが子ウィンドウ内に表示されるので width と height の値を変えた方がいいかも。
IE8 で試すといつの間にか動くようになってた。IE が空リファラを送るようになったのか、Twitter の仕様変更かは未確認。ただし window.onunload でウィンドウが閉じない。


ついでに、元エントリのページChrome で化けてた。EUC-JP だと起こるらしい。http://www.wingnotes.net/linux_server/google_chrome_xoops_euc-jp_charaset.html を参照してヘッダに「<!-- 龠 -->」と入れて解決。なんじゃそりゃ。EUC-JP な FC2 もどうかと思うが。