今見ているページをTwitterに投稿するブックマークレットを作る方法
今見ているページをTwitterに投稿するブックマークレットを作る方法です。
Twitterへの投稿はURLは以下でできるので、[文字列]部分をJavaScriptでタイトルやURLを埋め込むブックマークレットを作れば良い訳です。
http://twitter.com/home?status=[文字列]
1)タイトルとURLを投稿する場合:
「タイトル URL」
javascript:window.location='http://twitter.com/home?status='+encodeURIComponent(document.title+' '+location.href);
2)選択したテキストを引用して投稿する場合:
「'引用文' タイトル URL」
javascript:d=document;if(d.selection)s=d.selection.createRange().text;else%20if(d.getSelection)s=d.getSelection();else%20if(window.getSelection)s=window.getSelection();else%20s='';t=d.title;h=location.href;location.href='http://twitter.com/home?status='+encodeURIComponent(''+s+' '+t+' '+h);