/**
* @title ニコ動を直接見る…的な
* @description my bookmarklet
* @license MIT License
* @require
*/
window.O__O={};
window.O__O.e1=setInterval(function(){
if(document.querySelector("#external_nicoplayer")){
window.O__O.i=document.createElement('iframe');
window.O__O.o=document.querySelector("#external_nicoplayer");
window.O__O.i.width=o.width;
window.O__O.i.height=o.height;
window.O__O.o.parentNode.replaceChild(i,o);
}
},200);
setTimeout(function(){
clearInterval(window.O__O.e1);
},8000);
if(location.host=="flapi.nicovideo.jp"){
if(opener!=null){
var x=new XMLHttpRequest();
x.addEventListener('readystatechange',function(e){
if(e.target.responseText.length>=60){
GM_setValue("cookie__flapi_nicovideo",document.cookie);
window.close();
}
},false);
x.open("GET",location.href);
x.send();
}
}else if(location.host=="www.nicovideo.jp"){
var x=new XMLHttpRequest();
x.addEventListener('readystatechange',function(e){
if(e.target.responseText.length>=60){
window.O__O.i.src=decodeURIComponent(e.target.responseText.match(/url\=([\w\%\-\.]+)/)[1]);
}else{
window.open("http://flapi.nicovideo.jp/api/getflv/"+location.href.match(/sm\d+/)[0]);
setTimeout(function(){location.reload()},3000);
}
},false);
x.setRequestHeader("Cookie",GM_setValue("cookie__flapi_nicovideo"));
x.open("GET","http://flapi.nicovideo.jp/api/getflv/"+location.href.match(/sm\d+/)[0]);
x.send();
}