ニコニコ動画(9)用 iframeタグ取得支援 bookmarklet

ニコニコ動画(9) が始まった訳ですけれど、 blog に動画情報を埋め込む iframeタグ が動画ページ下部から別ページになってしまい、拾いに行って貼り付けるまでが面倒になったので、 bookmarklet を書いてみた。


bookmarkletの実行は自己責任で。

使い方

ニコニコ動画の動画再生ページで実行し、Ctrl+Cを押すだけ。
IEではクリップボードへのコピーも行う。
その他、URLに/www.nicovideo.jp/watch/が含まれているページでも動作を試みる。
ニコニコ動画ログイン。
IE8, FireFox3.5, Opeara9, Chrome3.0 で動作確認。

bookmarklet

IE, FireFox 両用

javascript:(function(){var src;var insert;var frame;var match_str='/www.nicovideo.jp/watch/';var src_base='http://www.nicovideo.jp/embed/';var pos=location.href.lastIndexOf(match_str);if(pos>-1){src=location.href.substring(pos+match_str.length);}else{alert('%E5%8B%95%E7%94%BBURL%E5%8F%96%E5%BE%97%E5%A4%B1%E6%95%97');return;}insert=document.getElementById('PAGEBODY');if(!insert||(insert.tagName!='DIV')){insert=document.getElementById('body');if(!insert||(insert.tagName!='DIV')){insert=document.body;}}frame=document.createElement('iframe');frame.style.width='100%';frame.src=src_base+src;if(document.all){frame.onreadystatechange=function(){if(this.readyState=='complete'){var code=frame.contentWindow.document.form_iframe.iframe_code;alert(code.value);code.focus();code.select();clipboardData.setData('text',code.value);this.onreadystatechange=null;}}}else{frame.onload=function(){var code=frame.contentWindow.document.form_iframe.iframe_code;code.focus();code.select();};}insert.insertBefore(frame,insert.firstChild);})();


はてなダイアリーでの動画の埋め込み

javascript:(function(){var src;var insert;var frame;var match_str='/www.nicovideo.jp/watch/';var src_base='http://www.nicovideo.jp/embed/';var pos=location.href.lastIndexOf(match_str);if(pos>-1){src=location.href.substring(pos+match_str.length);}else{alert('%E5%8B%95%E7%94%BBURL%E5%8F%96%E5%BE%97%E5%A4%B1%E6%95%97');return;}insert=document.getElementById('PAGEBODY');if(!insert||(insert.tagName!='DIV')){insert=document.getElementById('body');if(!insert||(insert.tagName!='DIV')){insert=document.body;}}frame=document.createElement('iframe');frame.style.width='100%';frame.src=src_base+src;if(document.all){frame.onreadystatechange=function(){if(this.readyState=='complete'){var code=frame.contentWindow.document.form_iframe.iframe_code;alert(code.value);code.value+='[niconico:'+src+']';code.focus();code.select();clipboardData.setData('text',code.value);this.onreadystatechange=null;}}}else{frame.onload=function(){var code=frame.contentWindow.document.form_iframe.iframe_code;code.value+='[niconico:'+src+']';code.focus();code.select();};}insert.insertBefore(frame,insert.firstChild);})();


自分用(FireFox only + はてなダイアリー

javascript:(function(){var src;var insert;var frame;var match_str='/www.nicovideo.jp/watch/';var src_base='http://www.nicovideo.jp/embed/';var pos=location.href.lastIndexOf(match_str);if(pos>-1){src=location.href.substring(pos+match_str.length);}else{alert('%E5%8B%95%E7%94%BBURL%E5%8F%96%E5%BE%97%E5%A4%B1%E6%95%97');return;}insert=document.getElementById('PAGEBODY');if(!insert||(insert.tagName!='DIV')){insert=document.getElementById('body');if(!insert||(insert.tagName!='DIV')){insert=document.body;}}frame=document.createElement('iframe');frame.style.width='100%';frame.src=src_base+src;frame.onload=function(){var code=frame.contentWindow.document.form_iframe.iframe_code;code.value+='[niconico:'+src+']';code.focus();code.select();};insert.insertBefore(frame,insert.firstChild);})();