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

# ポップアップ用スクリプト埋め込み
[Replace]
Name = ポップアップ用スクリプト埋め込み
#URL = (?:www|ch|com)\.nicovideo\.jp/(?:$|category_recent.php|\?g|tag/|search/|thumb/|newarrival|recent|api/getthumbinfo/|mylist/|my/mylist|ranking|history|user/|hotlist|channel/|search_video/|watch/|video/|top/)
URL = (?!ads|.*api)[^/]+\.nicovideo\.jp/(?!api/|thumb[_/]|embed/)
ContentType = text/html
Match<
(?=</head>)
>
Replace<
<script type="text/javascript" src="http://www.nicovideo.jp/local/overlib_mini.js"></script>
<script type="text/javascript" src="http://www.nicovideo.jp/$TS(local/popThumb.js)"></script><CRLF>
>

# 上から順に、
# コミュニティ(co)をリンク、それ以外のsmid系、
# mylist/userへのリンク、視聴履歴内動画タイトル
[Replace]
Name = ポップアップリンク置換(検索系)
URL = (?:www|ext|ch|com)\.nicovideo\.jp/(?:$|category_recent\.php|\?g|tag/|search/|newarrival|recent|ranking|history|user/(?!\d+/video\?rss=).*|myvideo/|hotlist|channel/|search_video/|video/|top/|video_top)
ContentType = text/(?:html|xml)
Multi = TRUE
EachLine = TRUE
Match<
co\d{1,8}+(?!["\\'?.]|&quot;|low|</[vw]|[^<]*>|.*(?:</(?:a|title)>|class="search"|style="width:200px;"></td>|unescapeHTML|">[\r\n])|.+\}\);|.+,cc:\d+.*\})
(?<![a-z])(?:sm|nm|so|ca|ax|yo|nl|ig|na|cw|z[a-e]|om|sk|yk)\d{1,8}+(?!["\\'?.]|&quot;|low|</[vw]|[^<]*>|[^>]*(?:</(?:a|title)>|class="search"|style="width:200px;"></td>|unescapeHTML|">[\r\n])|.+\}\);|.+,cc:\d+.*\})
(?:mylist|user)/\d{1,8}+(?:/\d++|)(?!["\\'?.]|&quot;|.+</(?:form|title)>|.*">[\r\n]|[^<]*>|</a>|<\\|.+\}\);|.+,cc:\d+.*\})
>
Replace<
<a target="_top" href="http://com.nicovideo.jp/community/$0" onMouseOver="return popThumb2('$0', 0)" onMouseOut="return nd()">$0</a>
<a class="watch" target="_top" href="/watch/$0" onMouseOver="return popThumb2('$0', 0)" onMouseOut="return nd()">$0</a>
<a class="watch" target="_top" href="/$0" onMouseOver="return popThumb2('$0', 0)" onMouseOut="return nd()">$0</a>
>

# APIパラメータに nlFilter を付加した時のみ有効になるフィルタ群

# getthumbinfo のパラメータに ?nlFilter を付加した場合、ポップアップリンクの有無に関わらず
# <description><tag>内の実体参照が必ず二重置換されるようになる (video.array と同じ仕様)
[Replace]
Name = 実体参照の仕様を video.array に合わせる(getthumbinfo)
URL = ext\.nicovideo\.jp/api/getthumbinfo/\w{2}\d+\?nlFilter
Multi = TRUE
EachLine = TRUE
Match<
&amp;((?:amp|lt|gt);)(?![^<>]*</(?!description))
&quot;(?![^<>]*</(?!description))
&apos;(?![^<>]*</(?!description))
&(?![^<>]*</(?!description|tag))
>
Replace<
&$1
"
'
&amp;
>

[Replace]
Name = ポップアップリンク置換(getthumbinfo/video.array)
URL = (?:ext\.nicovideo\.jp/api/getthumbinfo/\w{2}\d+\?|i\.nicovideo\.jp/v3/video\.array\?(?:|v=[\w,]+&))nlFilter
Multi = TRUE
EachLine = TRUE
Match<
(?<!href="|&quot;)http://[^/]+\.nicovideo\.jp/[a-z/]+\d+(?:\?eco=1)?(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"&gt;|&lt;/a)
(?<!href="|&quot;|"&gt;|h)h?(ttps?://(?:(?!&(?:quot|lt|gt);)[-\w:./?!&~#=%;+])+)(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body))
(?<![a-z])(?:sm|nm|so|ca|ax|yo|nl|ig|na|cw|z[a-e]|om|sk|yk)\d{1,8}+(?:\?eco=1)?(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
watch/\d{10}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?:mylist|user)/\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])co\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])ch\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])lv\d{1,9}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])(?:sg|mg)\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])im\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])nc\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
(?<![a-z])dw\d{1,8}+(?![^<>]*>|[^<>]*</(?!description|tag|last_res_body)|&quot;|"|&lt;/a)
>
Replace<
&lt;a href="$0"&gt;$0&lt;/a&gt;
&lt;a href="h$1" target="_blank"&gt;$0&lt;/a&gt;
&lt;a href="http://www.nicovideo.jp/watch/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()" class="watch"&gt;$0&lt;/a&gt;
&lt;a href="http://www.nicovideo.jp/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()" class="watch"&gt;$0&lt;/a&gt;
&lt;a href="http://www.nicovideo.jp/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()"&gt;$0&lt;/a&gt;
&lt;a href="http://com.nicovideo.jp/community/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()"&gt;$0&lt;/a&gt;
&lt;a href="http://ch.nicovideo.jp/channel/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()"&gt;$0&lt;/a&gt;
&lt;a href="http://live.nicovideo.jp/watch/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()"&gt;$0&lt;/a&gt;
&lt;a href="http://seiga.nicovideo.jp/watch/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()" class="watch"&gt;$0&lt;/a&gt;
&lt;a href="http://seiga.nicovideo.jp/seiga/$0" onMouseOver="popThumb2('$0', 0)" onMouseOut="nd()"&gt;$0&lt;/a&gt;
&lt;a href="http://www.niconicommons.jp/material/$0"&gt;$0&lt;/a&gt;
&lt;a href="http://ichiba.nicovideo.jp/item/$0"&gt;$0&lt;/a&gt;
>

[Replace]
Name = ポップアップ追加(getthumbinfo/video.array)
URL = (?:ext\.nicovideo\.jp/api/getthumbinfo/\w{2}\d+\?|i\.nicovideo\.jp/v3/video\.array\?(?:|v=[\w,]+&))nlFilter
Multi = TRUE
EachLine = TRUE
Match<
(?:<|&lt;)a href="http://[^.]+.nicovideo.jp/((?:mylist|user|community|channel|seiga)/\w{2}\d+)(?:\?[^"]*)?"(?=>|&gt;)
(?:<|&lt;)a href="http://[^.]+.nicovideo.jp/(watch/\w{2}\d+)(?:\?[^"]*)?"(?:| target="_blank")(?=>|&gt;)
>
Replace<
$0 onMouseOver="popThumb2('$1', 0)" onMouseOut="nd()"
$0 onMouseOver="popThumb2('$1', 0)" onMouseOut="nd()" class="watch"
>

[Replace]
Name = キャッシュ済動画のリンク色変更(getthumbinfo/video.array)
URL = (?:ext\.nicovideo\.jp/api/getthumbinfo/\w{2}\d+\?|i\.nicovideo\.jp/v3/video\.array\?v=\w{2}\d+&)nlFilter
Multi = TRUE
idGroup = 2
Match<
((?:<|&lt;)a href="http://www\.nicovideo\.jp/watch/(\w{2}\d+)")((?:(?!>|&gt;).)+class="watch")
>
Replace<
$1 style="color:#<C00000$C08000>;"$3
>

# 複数動画の場合はパフォーマンスが悪くなるので threadId を対象としない
[Replace]
Name = キャッシュ済動画のリンク色変更(video.array/複数動画)
URL = i\.nicovideo\.jp/v3/video\.array\?(?:|v=[\w,]+&)nlFilter
Multi = TRUE
idGroup = 2
Match<
((?:<|&lt;)a href="http://www\.nicovideo\.jp/watch/([a-z]{2}\d+)")((?:(?!>|&gt;|style=).)+class="watch")
>
Replace<
$1 style="color:#<C00000$C08000>;"$3
>

[Replace]
Name = ポップアップ追加(Jarty系ページ)
URL = www\.nicovideo\.jp/(?:mylist/\d+|my/mylist|my/history|recommendations)
EachLine = TRUE
Multi = TRUE
Match<
<a href="/?watch/(\{\$item\.item_data\.watch_id[^\}]*\})[^"]*"[^>]+class="(?:vinfo_title|watch)"
<h[45]><a href="/?watch/(\{\$item\.item_data\.watch_id.*?\}|\w{2}\d+)[^"]*"
<h5 class="font12"><a href="[^"]+?(\{\$(video|item)\.id\|escape:url\})[^"]*"
>
Replace<
$0 onMouseOver="return popThumb2('$1',0)" onMouseOut="return nd()"
$0 onMouseOver="return popThumb2('$1',0)" onMouseOut="return nd()"
$0 onMouseOver="return popThumb2('$1',0)" onMouseOut="return nd()"
>

# .js はブラウザにキャッシュされてるので、初回&修正時は
# ブラウザのキャッシュクリアが必要
[Replace]
Name = ポップアップ追加(mylist説明文)
URL = res\.nimg\.jp/js/mylist2\.js
Match<
'<a href="' \+ formatRules\[i-1\]\[1\]\(match\[i\]\) \+ '">' \+ match\[0\] \+ '</a>';
>
Replace<
'<a href="' + formatRules[i-1][1](match[i]) + '" onMouseOver="return popThumb2(\\'' + match[0] + '\\',0)" onMouseOut="return nd()">' + match[0] + '</a>';
>

[Replace]
Name = ポップアップ追加(wwwドメイン汎用)
URL = www\.nicovideo\.jp/
ContentType = text/(?:html|plain|xml)
Multi = TRUE
Match<
(<a [^>]*href="\s*(?:|/|[^"]+?(?:video|live)_?id=|
[^"]*?http://(?:www|live|ch|com|seiga)\.nicovideo\.jp/(?:gate/)?|
http://rd\.nicovideo\.jp/cc/[^/]+/|/ch[^/]+/video/)
((?:watch/|mylist/|user/|channel/|community/|seiga/)?(?:(?:(?!nw|pk|ap)\w{2})\d+|#id#|%id%))(?:|\?(?!playlist)[^"]+)"
(?:(?!popThumb|title=)[^>])*(?: title="[^"]+"(?:(?!vocaloid_top)[^>])*)?)(>\s*+)
(?!<img|<span class="time"|(?:一般|プレミアム)回線で視聴)
>
Replace<
$1 onMouseOver="return popThumb2('$2', 0)" onMouseOut="return nd()"$3
>

# kakorokuRecorderが誤パースするのでwatch/lv〜を対象から外す
[Replace]
Name = ポップアップ追加(wwwドメイン以外汎用)
URL = (?!www)[^/]+\.nicovideo\.jp/(?!api/|thumb[_/]|embed/|watch/lv\d+)
ContentType = text/html
Multi = TRUE
Match<
(<a [^>]*href="\s*(?:[^"]+?(?:video|live)_?id=|
[^"]*?http://(?:www|live|ch|com|seiga)\.nicovideo\.jp/(?:gate/)?|
http://rd\.nicovideo\.jp/cc/nicotop_[^/]+/|/ch[^/]+/video/)
((?:watch/|mylist/|user/|channel/|community/|seiga/)?(?:\w{2}\d+|#id#|%id%))(?:[\?&][^"]*)?"
(?:(?!popThumb|timeshift_watch|title=)[^>])*(?: title="[^"]+"[^>]*)?)(>\s*)(?!<img)
>
Replace<
$1 onMouseOver="return popThumb2('$2', 0)" onMouseOut="return nd()"$3
>

[Replace]
Name = ポップアップ追加(flog)
URL = www\.nicovideo\.jp/(?:$|video_top|category_recent\.php)
Multi = TRUE
EachLine = TRUE
Match<
(<a href="#link#\?top_flog"(?:(?!title=)[^>])*(?: title="[^"]+"[^>]*)?)(>\s*)(?!<img)
\{link:"http://www\.flog\.jp/w\.php/http://www\.nicovideo\.jp/watch/(\w{2}\d+)"
>
Replace<
$1 onMouseOver="return popThumb2('#id#', 0)" onMouseOut="return nd()"$2
$0,id:"$1"
>

[Replace]
Name = ポップアップ追加(静画)
URL = seiga\.nicovideo\.jp/
ContentType = text/html
Multi = TRUE
Match<
<a [^>]*href="/?(?:bbs|watch|seiga)/((?:sg|im|mg)\d+)[^"]*"
>
Replace<
$0 onMouseOver="return popThumb2('$1', 0)" onMouseOut="return nd()"
>

[Replace]
Name = ポップアップ追加(世界の新着動画)
URL = live\.nicovideo\.jp/newworld
Multi = TRUE
Match<
<a [^>]*href="http://www\.nicovideo\.jp/(watch/\w{2}\d+)[^"]*"
>
Replace<
$0 onMouseOver="return popThumb2('$1', 0)" onMouseOut="return nd()"
>
