# nlフィルタ定義(文字コード判定用なのでこの行は削除しないこと)
# 17/01/22
[Replace]
Name = キャッシュ済動画のリンク色変更(watch)
URL = (?:www|news)\.nicovideo\.jp/watch/
Multi = TRUE
idGroup = 2
Match<
(href="(?:|/|http://www\.nicovideo\.jp/)watch/([a-z]{2}\d+)[^"]*"[^>]*)(>\s*)(?!
Replace<
$1 style="color:#;"$3
>
# watchページのURLをリンク化
[Replace]
Name = watchURLtoLink
URL = www\.nicovideo\.jp/watch/
Multi = TRUE
Match<
(?i)h?(ttps?://[a-z0-9:./?!&\-~#=_%;+]+)(?![^<>]*>|[^<>]*(?:a|textarea|script)>)
>
Replace<
$0
>
[Replace]
Name = キャッシュアイコンを追加(GINZA)
URL = www\.nicovideo\.jp/watch/
Require = res\.nimg\.jp/css/watch_zero/watch\.css\?
Multi = TRUE
Match<
(\s*)]*class="(?:thumbnail|itemThumbnail)"\s*/?>
>
Replace<
$0$1
>
[Style]
Name = キャッシュアイコンを定義(GINZA)
URL = www\.nicovideo\.jp/watch/
Require = res\.nimg\.jp/css/watch_zero/watch
Append<
#playlistContainer .playlistItem .thumbContainer .cacheIcon,
#videoExplorer .cacheIcon {
position:absolute; top:auto; bottom:0px; left:0px; z-index:1000; display:none;
}
#playlistContainer .playlistItem .thumbContainer .cacheInfo {
position:absolute; bottom:-8px; padding:0 4px 0 4px; background-color:rgba(0,0,0,.6); color:white;
}
>
[Script]
Name = キャッシュアイコンを表示(GINZA)
URL = www\.nicovideo\.jp/watch/
Require = res\.nimg\.jp/js/watch/require
Append<
require([
'jquery',
'watchapp/init/PlaylistInitializer',
'watchapp/init/VideoExplorerInitializer',
'WatchJsApi'
], function($, PlaylistInitializer, VideoExplorerInitializer) {
WatchJsApi.onInitialized(function() {
var playlist = PlaylistInitializer.playlist;
var playlistData = JSON.parse($('#playlistDataContainer').text());
if (playlistData) {
$(playlistData.playlist).each(function(index, data) {
if (data.has_data) {
var item = playlist.getItemByWatchID(data.id);
if (item && item.id) {
if (data.cache) {
item.cache = data.cache
} else if (item.id.match(/^[a-z]{2}[0-9]+$/)) {
item.cache = 'none';
}
}
}
});
}
VideoExplorerInitializer.videoExplorer.addEventListener('refreshEnd', function (e) {
setTimeout(function() {
$(e.content.getItems()).each(function(index, item) {
showCacheIcon(item._id, item._seed.cache);
});
}, 500);
});
WatchJsApi.player.addEventListener('onVideoInitialized', function() {
var item = playlist.getPlayingItem();
checkCached(item.id, function(cache) {
if (cache != 'none') {
item.cache = showCacheIcon(item.id, cache);
} else {
var info = $('');
var index = playlist.getPlayingIndex();
if (index >= 0) {
var thumb = $('#playlistContainer ul.playlistItemList>li').eq(index)
.find('.thumbContainer');
thumb.find('.cacheIcon').hide();
thumb.append(info);
}
var npc = PlayerApp.ns.player.Nicoplayer.getInstance()._nicoplayerConnector;
var timer = setInterval(function() {
var ratio = npc.getVideoBufferedRatio();
info.text(Math.floor(ratio * 100) + '%');
if (ratio == 1) {
clearInterval(timer);
setTimeout(function() {
checkCached(item.id, function(cache) {
info.remove();
item.cache = showCacheIcon(item.id, cache);
});
}, 1000);
}
}, 1000);
}
});
});
$('#playlistContainer ul.playlistItemList').on('DOMNodeInserted', function(e) {
var target = $(e.target);
if (target.hasClass('playlistItem')) {
var timer = setInterval(function() {
var id = target.attr('data-nicowatch-video-id');
if (id) {
clearInterval(timer);
var item = playlist.getItemByWatchID(id);
if (item) {
if (item.cache) {
showCacheIcon(target, item.cache);
} else {
var a = $('#videoExplorer a[href*="watch/' + id + '"]');
var icon = a.find('.cacheIcon[src]').get(0);
if (icon) {
item.cache = showCacheIcon(target, icon.src);
} else {
checkCached(id, function(cache) {
item.cache = showCacheIcon(target, cache);
});
}
}
}
}
}, 50);
}
});
function checkCached(id, callback) {
var cache = 'none';
$.get('/cache/info?' + id, function(data) {
var info = data[id];
if (info != null && !info['caching'] && !info['normalSize']) {
cache = info['dmc'] ? (info['economy'] ? 'dmceconomy' : 'dmcicon'):
(info['economy'] ? 'economy' : 'icon');
}
callback(cache);
});
}
});
function showCacheIcon(target, src) {
var cache = 'none';
if (target && typeof src === 'string' && src != 'none') {
if (typeof target === 'string') {
target = $('a[href*="watch/' + target + '"]');
}
if (target.length > 0) {
if (src == 'icon' || src == 'economy' || src == 'dmcicon' || src == 'dmceconomy') {
cache = src;
src = 'http://www.nicovideo.jp/local/cache' + src + '.gif';
} else if (src.indexOf('dmcicon') >= 0) {
cache = 'dmcicon';
} else if (src.indexOf('dmceconomy') >= 0) {
cache = 'dmceconomy';
} else if (src.indexOf('icon') >= 0) {
cache = 'icon';
} else if (src.indexOf('economy') >= 0) {
cache = 'economy';
}
target.find('.cacheIcon').attr('src', src).show();
target.find('span.title').css('color',
cache == 'icon' ? '#C00000':
cache == 'economy' ? '#C08000':
cache == 'dmcicon' ? '#008000':
cache == 'dmceconomy' ? '#808000' : '#C00000');
}
}
return cache;
}
});
>