# nlフィルタ定義(文字コード判定用なのでこの行は削除しないこと)

#----------------------------------------------------------------------------------------
# dmc対応
[Replace]
Name = popThumb_FA：個人設定1
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/local/popThumb_FA\.js
Multi = TRUE
EachLine = TRUE
MatchLocal = TRUE
Match<
(?<=/cache/(?:ajax_)?rm)
\(cache \?[^)]+\)
(?<=if \(cache\) \{)[^}]+(?=\})
(?<=if \(isDeleted\) \{)[^}]+(?=\})
>
Replace<
all
(cache?(!cache.indexOf('dmc')?(cache=='dmcEconomy'?'nico_dmc_cached_economy':'nico_dmc_cached'):(cache=='economy'?'nico_cached_economy':'nico_cached')):'')
pop_html += '<div class="cacheIcon '+(!cache.indexOf('dmc')?(cache=='dmcEconomy'?'dmcEconomyIconImg':'dmcCacheIconImg'):(cache=='economy'?'economyIconImg':'cacheIconImg'))+'"></div>'
pop_html += '<div class="cacheIcon deleteIconImg"></div>'
>

#----------------------------------------------------------------------------------------
# popThumb.use_always_check=true かつdmcキャッシュがある場合にdmcの情報を表示1
[Replace]
Name = popThumb_FA：個人設定2-1
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/local/popThumb_FA\.js
MatchLocal = TRUE
Match<
var propname_pop_smid = "obj_"(?:.+\r\n){11}\t{3}\}
>
Replace<
if (popThumb.use_always_check && (
			     (!!cache && ~cache.indexOf('conomy') && popThumb.data[`obj_\${pop_smid}`][2])
			     || (!!cache && !pop_smid.indexOf('sm') && !object.dmcMovieType)
			   )){
			  object = window.popThumb._XMLHttpRequest(`http://\${location.host}/cache/info?\${pop_smid}`, false, (r) => {
			    var
			      json = JSON.parse(r.responseText)
			      ,cacheData = json[pop_smid]
			      ,data = window.popThumb.data[`obj_\${pop_smid}`][1];
			    
			    if(!cacheData) return data;
			    data["cache"] = !cacheData.dmc? (!cacheData.economy? 'cache': 'economy'): (!cacheData.economy? 'dmcCache': 'dmcEconomy');
			    
			    if(!cacheData.dmc) return data;
			    data["dmcMovieType"] = cacheData.dmcMovieType;
			    data["dmcMovieType"]["size"] = cacheData.size;
			    
			    window.setTimeout(window.popThumb.save, 1000);
			    
			    return data;
			  });
			}
>

#----------------------------------------------------------------------------------------
# popThumb.use_always_check=true かつdmcキャッシュがある場合にdmcの情報を表示2
[Replace]
Name = popThumb_FA：個人設定2-2
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/local/popThumb_FA\.js
MatchLocal = TRUE
Match<
if \(isGetthumbinfo\) \{\r\n(?:.+\r\n){5}
>
Replace<
if (!object.dmcMovieType) {
			$0
			} else {
			  let
			    dmcMovieType = object.dmcMovieType
			    ,dmcSizeM = (dmcMovieType.size /1024 /1024) +"";
			  pop_html +=
			    `<tr><td>dmcモード</td><td>：</td><td>\${dmcMovieType.videoMode}</td></tr>` +
			    `<tr><td>dmc映像レート</td><td>：</td><td>\${dmcMovieType.videoBitrate} kbps</td></tr>` +
			    `<tr><td>dmc音声レート</td><td>：</td><td>\${dmcMovieType.audioBitrate} kbps</td></tr>` +
			    `<tr><td>サイズ</td><td>：</td><td>\${dmcSizeM.slice(0, dmcSizeM.indexOf('.') +2)} MiB</td></tr>`;
			}
			
>

#----------------------------------------------------------------------------------------
# 消去動画を api.ce.nicovideo.jp/nicoapi/v1/video.info から
[Replace]
Name = popThumb_FA：個人設定3
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/local/popThumb_FA\.js
MatchLocal = TRUE
Match<
(// 削除動画・.+\s+)(.+)
>
Replace<
$1//$2<CRLF>
				let F = (e) => {
					let
				      {video, thread, tags} = (JSON.parse(e.responseText)).nicovideo_video_response
				      ,object = {};
				    
				    object["usingAPI"] = { videoarray:1,};
				    object["thumbnail_url"] = "http://tn-skr.smilevideo.jp/smile?i="+(video.id.slice(2));
				    object["deleted"] = video.deleted;
				    object["video_options_ppv_type"] = video.ppv_video;
				    object["title"] = video.title;
				    object["description_videoarray"] = video.description;
				    object["cache"] = video.cache;
				    object["video_id"] = video.id;
				    object["first_retrieve"] = video.first_retrieve;
				    object["length_in_seconds;"] = video.length_in_seconds;
				    object["length"] = ((video.length_in_seconds /60) |0) + ':' +('0' + (video.length_in_seconds % 60)).slice(-2);
				    object["size_high"] = 1;
				    object["size_low"] = 1;
				    object["view_counter"] = video.view_counter;
				    object["mylist_counter"] = video.mylist_counter;
				    object["comment_counter"] = thread.num_res;
				    object["last_res_body"] = thread.summary;
				    object["user_id"] = video.user_id;
				    object["ch_id"] = video.community_id;
				    
				    let
				      _tags = []
				      ,tagInfo = tags.tag_info;
				    for(let l = tagInfo.length; l--;){
				      let tag = tagInfo[l];
				      _tags.unshift({text:tagInfo.tag, domain:tagInfo.area, area:tagInfo.area,});
				    }
				    object["tags"] = _tags;
				   
				    window.popThumb.data["obj_" + pop_smid] = ["object", object];
				    window.setTimeout(window.popThumb.save, 1000);
				    make_from_object(null, pop_smid, object);
				  };
				window.popThumb._XMLHttpRequest(
				  "http://"+location.host+"/pr_Redirect_api.ce.nicovideo.jp/nicoapi/v1/video.info?__format=json&v=" + pop_smid + "&nlFilter",
				  true, F);
>

#----------------------------------------------------------------------------------------
# 動画説明文を api.ce.nicovideo.jp/nicoapi/v1/video.info から
#[Replace]
Name = popThumb_FA：個人設定4
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/local/popThumb_FA\.js
MatchLocal = TRUE
Match<
(?=var isVideoArray = !!object.usingAPI.videoarray)
>
Replace<
/**/
			if(!object.usingAPI.videoarray){
			object = window.popThumb._XMLHttpRequest("http://" + location.host + "/pr_Redirect_api.ce.nicovideo.jp/nicoapi/v1/video.info?__format=json&v=" + pop_smid + "&nlFilter", false, (e) => {
			    let
			      json = JSON.parse(e.responseText)
			      ,video = json.nicovideo_video_response.video
			      ,data = window.popThumb.data["obj_" + pop_smid][1];
			    data["deleted"] = video.deleted;
			    data["video_options_ppv_type"] = video.ppv_video;
			    data["description_videoarray"] = video.description;
			    if(~pop_smid.indexOf('so')){
			      let threadId = json.nicovideo_video_response.thread.id
			      data["channel_thread_id"] = threadId;
			      data["last_res_body"] = window.popThumb._XMLHttpRequest("http://"+location.host+"/pr_Redirect_api.ce.nicovideo.jp/nicoapi/v1/video.info?__format=json&v=" + threadId + "&nlFilter", false, (e)=>{return JSON.parse(e.responseText).nicovideo_video_response.thread.summary});
			    }
			    data.usingAPI["videoarray"] = video.description;
			    
			    window.setTimeout(window.popThumb.save, 1000);
			    
			    return data;
			  })
			}
			/**/
			
>

#----------------------------------------------------------------------------------------
#[Replace]
Name = popThumb_FA：ext埋め込み
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/local/popThumb_FA\.js
MatchLocal = TRUE
Match<
(?=// html構造がバグっているサイト用)
>
Replace<
/**/
new Promise(()=>{
  var
    S = document.createElement('script')
    ,DF = document.createDocumentFragment()
    ,A = [
        "/local/popThumb_FA-extension_addDic.js",
        "/local/popThumb_FA-extension_largeThumb.js",
      ];
  for (let a of A){
    let S2 = S.cloneNode(true);
    S2.setAttribute('type', 'text/javascript');
    S2.setAttribute('charset', 'utf-8');
    S2.setAttribute('src', `//\${location.host}\${a}`);
    DF.appendChild(S2);
  }
  document.body.appendChild(DF);
});
/**/
>

#----------------------------------------------------------------------------------------
[Replace]
Name = popThumb_FA：watch視聴時にdataコンテナ更新&作成(HTML5)
URL = www\.nicovideo\.jp/watch/
Require = "js-initial-watch-data"
Match<
(?=</body>)
>
Replace<
<script type="text/javascript" src="/$TS(local/popThumb_FA-watchPage_updateData.js)"></script><CRLF>
>