日本赤十字社へのリンク

日本赤十字社へのリンク→ http://www.jrc.or.jp/ もっとも中抜きが少ない...ハズ

2010年10月11日月曜日

Bookmarklet: HTMLのタグ入力支援

HTMLのタグ入力を支援するiPad/iPhoneのSafari用bookmarklet.

  • ダイアログから「★★★」と入力すると「<★★★></★★★>」 に変換して文中に挿入し,カーソル位置をタグの間に移動
javascript:insTag=window.prompt('Tag','');insert='%3C'+insTag+'%3E%3C%2F'+insTag+'%3E';body=document.activeElement.value;at=document.activeElement.selectionStart;tmp=body.substr(0,at);document.activeElement.value=tmp+insert+body.substr(at,body.length);cursor=Math.floor(insert.length/2)+at;document.activeElement.setSelectionRange(cursor,cursor);


  • 番号なしリスト(unordered list・箇条書き)「<ul><li></li></ul>
javascript:insert='%3Cul%3E%3Cli%3E%3C%2Fli%3E%3C%2Ful%3E';body=document.activeElement.value;at=document.activeElement.selectionStart;tmp=body.substr(0,at);document.activeElement.value=tmp+insert+body.substr(at,body.length);cursor=Math.floor(insert.length/2-1)+at;document.activeElement.setSelectionRange(cursor,cursor);


  • 番号付きリスト(ordered list)「<ol><li></li></ol>
javascript:insert='%3Col%3E%3Cli%3E%3C%2Fli%3E%3C%2Fol%3E';body=document.activeElement.value;at=document.activeElement.selectionStart;tmp=body.substr(0,at);document.activeElement.value=tmp+insert+body.substr(at,body.length);cursor=Math.floor(insert.length/2-1)+at;document.activeElement.setSelectionRange(cursor,cursor);


  • リストの行追加「<li></li>
javascript:insert='%3Cli%3E%3C%2Fli%3E';body=document.activeElement.value;at=document.activeElement.selectionStart;tmp=body.substr(0,at);document.activeElement.value=tmp+insert+body.substr(at,body.length);cursor=Math.floor(insert.length/2)+at;document.activeElement.setSelectionRange(cursor,cursor);


【登録手順】→ 半分話: Bookmarklet: 選択部分でGoogle検索(新規ウィンドウ)

不良役員のアフターファイブさんのエントリ「JavaScript でテキスト制御」のほとんどパクリです.
他にもいろんなサイトを参考にさせていただきました.
この場を借りてお礼申し上げます.

# ブラウザのテキスト入力欄に直でタグ打ちしてブログを投稿している原始的な自分のために作成

【関連エントリ】
半分話: iPad雑感
半分話: Bookmarklet: Googleリーダー検索/登録
半分話: Bookmarklet: メディアマーカー登録
半分話: Bookmarklet: 選択部分をURIエンコード/デコード
半分話: Bookmarklet: 選択部分をメール本文に