Skip to content

Instantly share code, notes, and snippets.

@edvakf
Created May 26, 2011 07:48
Show Gist options
  • Save edvakf/992730 to your computer and use it in GitHub Desktop.
Save edvakf/992730 to your computer and use it in GitHub Desktop.
ニコニコ動画から Tumblr に投稿するブックマークレット改変
/*
http://d.hatena.ne.jp/takeken/20091113/1258104204
これの改変バージョン。
ニコニコ動画の外部プレーヤー用のスクリプトは document.write を使ってるのでどうしても同期じゃないといけない。
そこで、iframe を作ってその中でニコニコ動画のスクリプトを読み込んでいる。
*/
javascript:(function(){var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://www.tumblr.com/share',l=d.location,e=encodeURIComponent;if(/nicovideo.jp/.test(l.host)){var n=location.href.match(/.*([ns]m[0-9]\d+)/)[1];k=Date.now();s='<a href="http://www.nicovideo.jp/watch/'+n+'">'+document.title+'<noscript><br><img width="300" src="http://tn-skr'+((Math.random()*4|0)+1)+'.smilevideo.jp/smile?i='+n.slice(2)+'"></noscript></a><script id="nicovideo_'+k+'">(function(d,s,v,f){f=d.createElement("iframe");f.style.border="none";f.height=385;f.width=485;v=d.getElementById(v);v.parentNode.insertBefore(f,v);f.contentDocument.write("<!DOCTYPE html><head><style>*{margin:0;padding:0;}body *{display:block}<\\/style><\\/head><body><scr"+"ipt src="+s+"><\\/scr"+"ipt><\\/body>")}(document,"http://ext.nicovideo.jp/thumb_watch/'+n+'?w=485&h=385","nicovideo_'+k+'"));</script>'}var p='?v=3&u='+e(l.href)+'&t='+e(d.title)+'&s='+e(e(s));u=f+p;try{if(!/^(.*\.)?tumblr[^.]*$/.test(l.host))throw(0);tstbklt()}catch(z){a=function(){if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=450,height=430'))l.href=u};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a()}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment