// video.array使用時の複数収得許可
getFullDesc.getAllID=false;
// 上記trueの場合、shiftを押しながらクリック時のみvideo.array複数収得
getFullDesc.getAllIDpressShift=true;
// video.arrayで複数収得時の最大件数
getFullDesc.maxGetID=10;
// 説明文収得時にタグ追加
getFullDesc.setTags=false;
// ページロード時にキャッシュ済みタグ追加
getFullDesc.setTagsLoad=false;
/*------------------------------------------------------------*/
getFullDesc.url=function(){
		var L=location.href.substring(24).split('/');
		switch(L[0]){
			case 'ranking':return 'Ranking';
			case 'mylist':return 'Mylist';
			case 'my':return (L[1]=='history' ? 'History' :L[1]=='mylist' ? 'MyMylist' :null);
			case 'search':return 'Search';
			case 'tag':return 'Tag';
			default:return null;
	}
}();
getFullDesc.DOMP=function(str){return new DOMParser().parseFromString(str,'application/xml')};
function getFullDesc(elem_caller, smid){
	if (!(window.popThumb&&popThumb.addEvent))return alert('[popThumb_FA.js] not found.');
	var getThumbDesc=function(pop_smid,g,p){
		const data=p.data,HttpRequest=p.HttpRequest,DOMP=g.DOMP;
		var node="";
		if(data[pop_smid] && !DOMP(data[pop_smid][1]).getElementsByTagName('error')[0]){
			node=DOMP(data[pop_smid][1]);
		}else if(data['va_'+pop_smid]){
			node=DOMP(data['va_'+pop_smid][1]);
		}else{
			if(!g.getAllID || !(g.url && g.url!='Search' && g.url!='Tag') || (g.getAllIDpressShift && p.key_now!==16)){
				node=DOMP(HttpRequest("http://"+location.host+"/pr_Redirect_ext.nicovideo.jp/api/getthumbinfo?v="+pop_smid+"&nlFilter", function(res){return res}, false, pop_smid, ['api',pop_smid]));
				if(node.getElementsByTagName('error')[0]){
					node=DOMP(HttpRequest("http://"+location.host+"/pr_Redirect_i.nicovideo.jp/v3/video.array?v="+pop_smid+"&nlFilter", function(res){return res}, false, pop_smid, ['array',pop_smid]));
				}
			}else{
				var smids=function(d){
						var A=[],id,m=g.maxGetID;
						for(var e=d.getElementsByClassName('nl_Desc'),i=e.length; i--;){
							id=e[i].getAttribute('nl-smid');
							if(data['va_' + id] || id==pop_smid)continue;
							A.push(id);
							if(!--m)break;
						}
						m ? A.push(pop_smid) : A[g.maxGetID-1]=pop_smid;
						return A.join(',');
					}(document);
				node=HttpRequest("http://"+location.host+"/pr_Redirect_i.nicovideo.jp/v3/video.array?v="+smids+"&nlFilter",
					function(res){
						var n='',F=false,f=/^\d/.test(pop_smid);
						for(var results=g.DOMP(res).getElementsByTagName('video_info'),i=results.length; i--;){
							var R=results[i],r=R.outerHTML,id=R.querySelector('video > id').textContent;
							data['va_'+id]=['array',r];
							if(F)continue;
							if(!f){
								if(id==pop_smid)n=R,F=true;
							}else{
								id=R.querySelector('thread > id').textContent;
								if(id==pop_smid)n=R,F=true,data['va_'+id]=['array',r];
							}
						}
						if(typeof p.save==="function")window.setTimeout(p.save,1000);
						return n;
					}, false);
			}
		}
		return node.getElementsByTagName('description')[0].textContent;
	}
	const g=window.getFullDesc,p=window.popThumb;
	var origin=elem_caller.parentNode.parentNode,clone=origin.cloneNode(true),nl_Desc=clone.getElementsByClassName('nl_Desc')[0],elem=nl_Desc.parentNode;
	elem.innerHTML=getThumbDesc(smid,g,p);
	elem.setAttribute('style','height:auto; line-height:1.25;');
	if(g.url=='Search' || g.url=='Tag')elem.removeAttribute('title');

	if(g.setTags && !clone.getElementsByClassName('nlTagContent')[0]){
		const data=p.data,DOMP=g.DOMP;
		var id=nl_Desc.getAttribute('nl-smid');
		if(data[id] && !DOMP(data[id][1]).getElementsByTagName('error')[0]){
			var tag=DOMP(data[id][1]).querySelectorAll('tags[domain="jp"] > tag'),A=[];
			for(var i2=tag.length; i2--;){
				var t=tag[i2],txt=t.textContent;
				A.unshift('<a href="http://www.nicovideo.jp/tag/'+txt+'" class="nlTag'+(t.hasAttribute('lock')?' nlTagLock':'')+'">'+txt+'</a>');
			}
			elem.insertAdjacentHTML('BeforeBegin','<div class="nlTagContent">'+A.join('')+'</div>');
		}else if(data['va_'+id]){
			var tag=DOMP(data['va_'+id][1]).querySelectorAll('tags > tag_info'),A=[];
			for(var i2=tag.length; i2--;){
				var t=tag[i2],txt=t.getElementsByTagName('tag')[0].textContent;
				if(t.getElementsByTagName('area')[0].textContent!='jp')continue;
				A.unshift('<a href="http://www.nicovideo.jp/tag/'+txt+'" class="nlTag">'+txt+'</a>');
			}
			elem.insertAdjacentHTML('BeforeBegin','<div class="nlTagContent">'+A.join('')+'</div>');
		}
		if(!g.setTagsCss){
			document.getElementsByTagName('body')[0].insertAdjacentHTML('AfterBegin','<style type="text/css">\
.nlTagContent{border:1px solid #AAA; padding:0px 2px; margin-bottom:4px;}\
.nlTag{margin:0 5px 0 0; display:inline-block; color:#666 !important; line-height:1.3em; font-size:13px;}\
.nlTagLock::before{content:""; display:inline-block; height:15px; width:12px; margin:0 2px -2px 0;\
background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAABOUlEQVQ4ja3OMWvCQBjG8UMQQQPuh4jDDRbd6uBQQQedXQTHDJ38BMW1g1sy+AHM5lKQurt0iUeHpIOTYCjETglaadEh9OlQYkM8ywk9+C/PS36EkMgDLBWwHeAFP9kbwFKJ7AsC3v4KniEqCHhbCjmsNevwpuGw1qy9MyjsnUEhukkhPm/B5y14ZvP4+57ZVMNdCllNGVZThuWE1cNtOWH1cJdCuMHADQZz9IuYI1YP9z8/3m292e7dh1RbbyZEPt0BLkmIfNhXiDbWc6hV0qhV0hjrOcTvQsR7ooiWVRIghIAQgqySQPwuRF4fKaJVy6kjUi2nEL8LkYVBEa+YT6KYT57sC+MMMh9SxOs2Mug2Mif7fHgGebinuCQhovWpq/cpZNL61BUivU5Jubu9uZap1ykpQuQ/3jd/WZygtJp1ZwAAAABJRU5ErkJggg==);}\
</style>');
		g.setTagsCss=true;
		}
	}

	origin.parentNode.replaceChild(clone,origin);
}
getFullDesc.cacheSetTags=function(){
		const g=window.getFullDesc,p=window.popThumb,d=document,data=p.data,DOMP=g.DOMP,url=g.url;
		var origin,clone,Item;
		switch(url){
			case'Ranking':
				origin=d.getElementsByClassName('video')[0].getElementsByClassName('list')[0];
				clone=origin.cloneNode(true);
				Item=clone.getElementsByClassName('item');
				break;
			case'Mylist':
				origin=document.getElementById('SYS_page_items');
				clone=origin.cloneNode(true);
				Item=clone.getElementsByClassName('SYS_box_item');
				break;
			case'MyMylist':
				origin=document.getElementById('SYS_page_items');
				Item=origin.getElementsByClassName('SYS_box_item');
				break;
			case'History':
				origin=document.getElementById('historyList');
				Item=origin.getElementsByClassName('outer');
				break;
		}
		for(var i=Item.length; i--;){
			var I=Item[i],id,elem;
			switch(url){
				case'Ranking':
					id=I.getAttribute('data-id');
					elem=I.getElementsByClassName('itemDescription')[0];
					break;
				default:
					id=I.getElementsByClassName('nl_Desc')[0].getAttribute('nl-smid');
					elem=I.getElementsByClassName('nl_Desc')[0].parentNode;
					break;
			}
			if(data[id] && !DOMP(data[id][1]).getElementsByTagName('error')[0]){
				var tag=DOMP(data[id][1]).querySelectorAll('tags[domain="jp"] > tag'),A=[];
				for(var i2=tag.length; i2--;){
					var t=tag[i2],txt=t.textContent;
					A.unshift('<a href="http://www.nicovideo.jp/tag/'+txt+'" class="nlTag'+(t.hasAttribute('lock')?' nlTagLock':'')+'">'+txt+'</a>');
				}
				elem.insertAdjacentHTML('BeforeBegin','<div class="nlTagContent">'+A.join('')+'</div>');
			}else if(data['va_'+id]){
				var tag=DOMP(data['va_'+id][1]).querySelectorAll('tags > tag_info'),A=[];
				for(var i2=tag.length; i2--;){
					var t=tag[i2],txt=t.getElementsByTagName('tag')[0].textContent;;
					if(t.getElementsByTagName('area')[0].textContent!='jp')continue;
					A.unshift('<a href="http://www.nicovideo.jp/tag/'+txt+'" class="nlTag">'+txt+'</a>');
				}
				elem.insertAdjacentHTML('BeforeBegin','<div class="nlTagContent">'+A.join('')+'</div>');
			}
		}
		Item[0].insertAdjacentHTML('BeforeBegin','<style type="text/css">\
.nlTagContent{border:1px solid #AAA; padding:0px 2px; margin-bottom:4px;}\
.nlTag{margin:0 5px 0 0; display:inline-block; color:#666 !important; line-height:1.3em; font-size:13px;}\
.nlTagLock::before{content:""; display:inline-block; height:15px; width:12px; margin:0 2px -2px 0;\
background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAABOUlEQVQ4ja3OMWvCQBjG8UMQQQPuh4jDDRbd6uBQQQedXQTHDJ38BMW1g1sy+AHM5lKQurt0iUeHpIOTYCjETglaadEh9OlQYkM8ywk9+C/PS36EkMgDLBWwHeAFP9kbwFKJ7AsC3v4KniEqCHhbCjmsNevwpuGw1qy9MyjsnUEhukkhPm/B5y14ZvP4+57ZVMNdCllNGVZThuWE1cNtOWH1cJdCuMHADQZz9IuYI1YP9z8/3m292e7dh1RbbyZEPt0BLkmIfNhXiDbWc6hV0qhV0hjrOcTvQsR7ooiWVRIghIAQgqySQPwuRF4fKaJVy6kjUi2nEL8LkYVBEa+YT6KYT57sC+MMMh9SxOs2Mug2Mif7fHgGebinuCQhovWpq/cpZNL61BUivU5Jubu9uZap1ykpQuQ/3jd/WZygtJp1ZwAAAABJRU5ErkJggg==);}\
</style>');
		g.setTagsCss=true;
		if(url=='Ranking'||url=='Mylist')origin.parentNode.replaceChild(clone,origin);
};

getFullDesc.getTagStart=function(g){
	if(!g.setTagsLoad)return;
	switch(g.url){
			case 'Ranking':
			case 'History':
				g.cacheSetTags();
				return;
			case 'Mylist':
				setTimeout(g.cacheSetTags,500);
				window.addEventListener('hashchange',function(ev){setTimeout(g.cacheSetTags,500)},false);
				return;
			case 'MyMylist':
				setTimeout(g.cacheSetTags,1000);
				return;
	}
}(window.getFullDesc);