# nlフィルタ定義(文字コード判定用なのでこの行は削除しないこと)
# 12/05/26
#
# このフィルタはNicoCache_nl+modで追加した機能の使い方サンプルを兼ねています
# よって、他の標準フィルタでは対応しない若干複雑な処理も敢えて行っています

[Replace]
Name = 3列表示用CSS
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Match<
</head>
>
Replace<
<style type="text/css"><!--
	/* 3列Filter独自クラス */
	.nc_thumb_block {
		width: 322px;
		overflow: hidden;
		word-break: break-all;
		float: left;
		border: solid 1px lightgray;
		background-color: #F9FCFC;
		margin: 2px;
	}
	/* 画面幅いっぱいに(右側は消す) */
	.content_672 { width:984px; }
--></style>
</head>
>

[Replace]
Name = 検索結果3列表示(前処理)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Multi = TRUE
EachLine = TRUE
Match<
<div style="width:624px;[^"]+
<table width="672"
<table width="312"
$NEST(<div,style="clear:both;">\s*(<div class="thumb_col_2[^>]+>[\s\S]+$),</div>)
$NEST(<div,class="content_312",</div>)
>
Replace<
<div style="width:984px; overflow:hidden;
<table width="984"
<table width="100%"
$1
>

# $LST/$INC使い方サンプル
# $LSTで指定するファイル名はダブルクォート無しでも良い
[Replace]
Name = 検索結果3列表示(NGvideoId)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Multi = TRUE
Match<
<div class="thumb_col_2[^>]+>\s*
<!---->\s*
<table(?:(?!id="thumb_uad_msg_)[\s\S])+?
<div id="thumb_uad_msg_$LST(list/NGvideoId.txt)"[\s\S]+?
<!---->\s*
</div>\s*$INC(3列FilterNGCount)
>
Replace<
>

# 先に動画IDで判定してからタイトルで判定する方が効率良さげ
[Replace]
Name = 検索結果3列表示(NGtitle)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Multi = TRUE
Match<
<div class="thumb_col_2[^>]+>\s*
<!---->\s*
<table(?:(?!class="watch")[\s\S])+?
class="watch[^>]+title="[^"]*$LST("list/NGtitle.txt")[^"]*"[\s\S]+?
<!---->\s*
</div>\s*$INC(3列FilterNGCount)
>
Replace<
>

# 必要ならコメントアウトを外してください
#[Replace]
Name = 検索結果3列表示(キャッシュ済み消去)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Multi = TRUE
Match<
<div class="thumb_col_2[^>]+>\s*
<!---->\s*
<table(?:(?!vinfo_length)[\s\S])+
<img src="http://www\.nicovideo\.jp/local/cache(?:icon|economy)\.gif"[\s\S]+?
<!---->\s*
</div>\s*
>
Replace<
>

[Replace]
Name = 検索結果3列表示(NG追加リンク)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Multi = TRUE
Match<
<a href="http://uad\.nicovideo\.jp/ads/\?vid=([a-z]{2}\d+)".+?(?=</nobr>)
>
Replace<
$0 <a href="javascript:void(0)" title="NGvideoIdに追加" onclick="NicoCache_nl.addNGvideoId(this,'$1')">ID</a>/<a href="javascript:void(0)" title="NGtitleに追加" onclick="NicoCache_nl.addNGtitle(this,'$1')">TI</a>
>

# LST追加API使い方サンプル
# LSTの追加に成功した場合はキャッシュも削除する
[Replace]
Name = 検索結果3列表示(NG追加処理)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Match<
(?=</head>)
>
Replace<
<script type="text/javascript"><!--
NicoCache_nl.extend({
	addNGvideoId: function(elem, smid) {
		this.addLST(smid, "NGvideoId.txt?" + smid, this.findThumbBlock(elem));
	},
	addNGtitle: function(elem, smid) {
		var thumbBlock = this.findThumbBlock(elem);
		var a = thumbBlock.querySelector("a.watch"); // SelectorAPIを使うのでIE8以降
		var title = a.textContent || a.innerText;
		if (title) {
			this.addLST(smid, "NGtitle.txt?" + encodeURIComponent(title), thumbBlock);
		}
	},
	addLST: function(smid, params, thumbBlock) {
		var self = this;
		this.get("/cache/addlist/" + params, function(r) {
			if (r.responseText.indexOf("NG") == 0) {
				alert("NG登録失敗！");
			} else if (thumbBlock) {
				if (thumbBlock.innerHTML.indexOf("cacheIcon") > 0) {
					self.get("/cache/ajax_rm?" + smid);
				}
				thumbBlock.style.display = 'none';
			}
		});
	},
	findThumbBlock: function(elem) {
		while (elem = elem.parentNode) {
			if (elem.className == "nc_thumb_block") {
				return elem;
			}
		}
		return null;
	}
});
//--></script><CRLF>
>

# nlVar参照サンプル($INCでカウントした件数を表示)
# 変数名に日本語を含むことができる
[Replace]
Name = 検索結果3列表示(NG件数)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Match<
class="pager"><tr>
>
Replace<
$0<td><span>NG：<nlVar:3列FilterNGCount>件</span></td>
>

[Replace]
Name = 検索結果3列表示(後処理)
URL = www\.nicovideo\.jp/(?:search|tag|recent|hotlist|newarrival)
Require = !Cookie\.set\('col',\s*'2'
Multi = TRUE
Match<
<div class="thumb_col_2[^>]+>\s*
(<!---->\s*
<table[\s\S]*?
<!---->\s*)
</div>\s*

(?:<div class="thumb_col_2[^>]+>\s*
(<!---->\s*
<table[\s\S]*?
<!---->\s*)
</div>\s*)?

(?:<div class="thumb_col_2[^>]+>\s*
(<!---->\s*
<table[\s\S]*?
<!---->\s*)
</div>\s*)?
>
Replace<
<div style="clear:both;">

<div class="nc_thumb_block">
$1</div>

<div class="nc_thumb_block">
$2</div>

<div class="nc_thumb_block">
$3</div>

</div>


>

# SearchExtension用設定を上書きする
# これは3列用
[Config]
Name = SearchExtConf
Require = !Cookie\.set\('col',\s*'2'
Match<
<!--↓左列↓-->
>
Replace<
<div style="display:none; clear:both;" name="cacheResult" id="cacheResult">
<div style="width:328px; float:left;"><div style="background-color:<colorBlock>; margin:2px; padding:4px; border:1px solid lightgray;">
<table><tr><td valign="top"><thumbBlock></td><td><descBlock></td></tr></table>
</div></div>
<div style="width:328px; float:left;"><div style="background-color:<colorBlock>; margin:2px; padding:4px; border:1px solid lightgray;">
<table><tr><td valign="top"><thumbBlock></td><td><descBlock></td></tr></table>
</div></div>
<div style="width:328px; float:left;"><div style="background-color:<colorBlock>; margin:2px; padding:4px; border:1px solid lightgray;">
<table><tr><td valign="top"><thumbBlock></td><td><descBlock></td></tr></table>
</div></div>
</div>
>

# これはその他･デフォルト
[Config]
Name = SearchExtConf0
Match<
<!--↓左列↓-->
>
Replace<
<div style="display:none; clear:both;" name="cacheResult" id="cacheResult">
<div style="width:33%; float:left;"><div style="background-color:<colorBlock>; margin:2px; padding:4px; border:1px solid lightgray;"><thumbBlock><descBlock></div></div>
<div style="width:33%; float:left;"><div style="background-color:<colorBlock>; margin:2px; padding:4px; border:1px solid lightgray;"><thumbBlock><descBlock></div></div>
<div style="width:33%; float:left;"><div style="background-color:<colorBlock>; margin:2px; padding:4px; border:1px solid lightgray;"><thumbBlock><descBlock></div></div>
</div>
>
