文脈に応じて変化する。
TextwellでWebリンクを作成するアクション BlogQuote(マルチ・エンディング版)
DraftPadとの違いは終了処理と看破せり。サムネ付きリンクプレートを作るBlogQuote。ブログを書くとき一番多く呼び出しているかもしれない。リンクを作るだけじゃない。ネットで調べ物をするのも下...
Textwellの内蔵ブラウザを使い、ブログやサイトの紹介をするアクション。検索エンジンをYahooに替えてみました。Yahooだとリアルタイム検索のときTwitterの検索結果が上がるのです。ニュース関連の最新ネタを拾いやすい。「それならTwitterの引用形式に合わせたほうがいいだろう」と改良を重ねているうち、多機能になっちゃっいました。
BLOG=" - W&R : Jazzと読書の日々"; SEARCH="http://search.yahoo.co.jp/search?p="+T.current; // SEARCH="http://www.google.co.jp/search?q="+T.current; T.closelets([ {title: "リンクタグ作成", fn: function(arg){ url=location.href; title=document.title.replace(arg.s,""); text=getSelection().toString(); if(text){ link="<blockquote style=\"color:black;background:ghostwhite;padding:15px;border-radius:5px;border:1px solid lightgray;\">"+text+"<br><b>(via <a href=\""+url+"\" target=\"_blank\">"+title+"</a>)</b></blockquote>\n"; }else{ link="<li><a href=\""+url+"\">"+title+"</a></li>\n"; } T("replaceCurrent",{text:link})}, arg:{s:BLOG}}, {title: "サムネイル作成", fn: function(arg){ url=location.href; switch(true){ case /^http:\/\/m.youtube.com/.test(url): url=url.replace(/m\./,"").split("&desktop")[0]; id=url.split("v=")[1]; title=document.title.replace(/- YouTube/,""); icon="http://s.ytimg.com/yts/mobile/img/apple-touch-icon-57x57-precomposed-vflDNvbEb.png"; link="<iframe width=\"500\" height=\"280\" src=\"http://www.youtube.com/embed/"+id+"\" frameborder=\"0\" allowfullscreen></iframe><br><img width=\"16\" src=\""+icon+"\"><a href=\""+url+"\" target=\"_blank\">"+title+"</a>\n"; break; case /^https:\/\/mobile.twitter.com/.test(url) && /status/.test(url): url=url.replace(/mobile/,"www"); s=document.getElementsByClassName("tweet")[0]; tweet=s.getElementsByClassName("dir-ltr")[0].innerHTML; fullname=s.getElementsByClassName("full-name")[0].innerText; name=s.getElementsByClassName("screen-name")[0].innerText.substr(1); time=s.getElementsByClassName("timestamp-row")[0].innerText; link="<blockquote class='twitter-tweet'><p>"+tweet+"</p>— "+fullname+" (@"+name+") <a href='"+url+"'>"+time+"</a></blockquote><scr"+"ipt async src='http://platform.twitter.com/widgets.js' charset='utf-8'></scr"+"ipt>\n"; break; case /^http:\/\/sp.nicovideo.jp\/watch\/sm[0-9]+/.test(url): s=url.match(/sm[0-9]+/); link="<iframe src=\"http://ext.nicovideo.jp/thumb/"+s+"\"><a href=\"http://www.nicovideo.jp/watch/"+s+"\">"+document.title+"</a></iframe>\n"; break; default: title=document.title.replace(arg.s,""); text=getSelection().toString(); if(!text){ p=document.getElementsByTagName("p"); for(k in p) text+=p[k].innerText; } text=text.replace(/\n/g,"").replace(/undefined/g,"").substr(0,100); link="<blockquote style=\"color:black;background:ivory;padding:15px;border-radius:5px;border:1px solid lightgray;\"><a href=\""+url+"\" target=\"_blank\" style=\"color:darkblue;\"><img align=\"left\" src=\"http://capture.heartrails.com/150x120/?"+url+"\" style=\"border-radius:10px;margin:1px 15px 1px 1px;box-shadow:1px 2px 3px gray;\">"+title+"</a><a href=\"http://b.hatena.ne.jp/entry/"+url+"\" target=\"_blank\"><img src=\"http://b.hatena.ne.jp/entry/image/"+url+"\"></a><br>"+text+"...<br style=clear:both;></blockquote>\n"; } T("replaceCurrent",{text:link})}, arg:{s:BLOG}}, {title: "Safariで閲覧", fn: function(){ T(location.href)}}, {title: "ソース書き出し", fn: function(){ T("replace",{text:document.documentElement.innerHTML})} }], function(){ s=T.current; if(s){ location=(/^http/.test(s))? s:SEARCH; }else{ text="<meta name=viewport content=initial-scale=1><body style=white-space:pre;word-wrap:break-word;>"+T.text+"</body>"; document.write(text); T.title("BlogQuote"); } });
登録リンクはこちら→ http://tinyurl.com/mnlvuba
(ソース一行目にある変数BLOGは、リンク作成のときタイトルから取り省く文字列を表します。これは、ご自分のブログに合わせて設定し直してください。)
リアルタイム検索では日付のところをタップ。Twitterの元のツイートに飛びます。内蔵ブラウザを閉じ「サムネイル作成」を選択すればツイートの引用になります。
Yahooは動画検索もモバイル向き。サムネをタップすると、YouTubeに飛ばずに動画を視聴できます。探しやすい。そして、「YouTube」のリンクからm.youtube.comで開き「サムネイル作成」をすると、動画埋め込みタグを取得するようにしました。
「リンクタグ作成」も補強しました。内蔵ブラウザを閉じる前に範囲選択がされていると、その部分を引用するblockquoteタグを作ります。カッコいいセリフを見つけたとき、その引用だけで記事になる。ネタ作りに頭をひねらない、Tumblrみたいなイメージです。
その他は従来通り。空行で実行すればプレビュー。キーワードがあれば検索。URLアドレスなら開く。ブログ書きで一番使っているアクションです。よく使うから手を入れたくなる。何を引用するかはブラウザを閉じるまで分からない。リンクを辿ってYouTubeに行き着いたとき、そこを動画取得のアクションで開き直すのも何か違う。手間を減らしたい。Textwellはそうした横着について来きてくれるから、本当ありがたいです。