LoginSignup
2
3

More than 5 years have passed since last update.

iPhoneのSafariから定型文をツイートするブックマークレット

Posted at

iPhoneのSafariで気になったページをツイートするとき、iOSの標準機能やブックマークレットが使えますが、引用符やハッシュタグなどフォーマットを自分好みに変えたいことがありますよね。

そんなときは自分でブックマークレットを作ることで対応することができるので、その方法を紹介します。

1. ブックマークレットの元となるJavaScriptの作成

Twitterアプリを使いたい場合は、URLに twitter: スキームを使うことで起動できるところがポイントです。

WebのTwitterでツイートする場合

var text = '"' + document.title + '" ' + location.href + ' #読んだ';
location = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(text);

Twitterアプリでツイートする場合

var text = '"' + document.title + '" ' + location.href + ' #読んだ';
location = 'twitter://post?message=' + encodeURIComponent(text);

2. ブックマークレットに変換

Bookmarklet Crunchinator などのサービスを使って、1. で作ったJavaScriptをブックマークレットURLに変換します。

javascript:(function(){var text='"'+document.title+'" '+location.href+' #%E8%AA%AD%E3%82%93%E3%81%A0';location='twitter://post?message='+encodeURIComponent(text);})();

3. iPhone のブックマークに追加

最後に、2. で作ったURLをSafariのブックマークに追加します。ブックマークレットの登録方法がちょっと面倒ですが、説明も面倒なので(ry

4. 気に入ったページをブックマーク

あとはツイートしたいページで 3. のブックマークを選択すれば、カスタマイズしたメッセージが入力された状態でTwitterアプリが開きます。

補足

カスタムURLスキームを使うことで、標準アプリを含めて様々なアプリを起動できるようです。連携できそうなアプリを考えてみると、面白いかもしれません。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3