Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Niconico Mylist Search ブックマークレット(GINZA)
/***** Niconico Mylist Search ブックマークレット *****
ニコニコ動画のマイリストをインクリメンタルサーチします。
@auther : moroya http://moroya.hatenablog.jp/
@license: MIT License
*/
(function($){
if(location.href.indexOf('www.nicovideo.jp/my/mylist') === -1) {
if(window.confirm('このページはニコニコ動画の\nマイリストページではありません\nマイリストページへジャンプしますか?')) {
location.href="http://www.nicovideo.jp/my/mylist";
}
return false;
}
var df_list = [];
var group_id = [''];
var group_name = ['とりあえずマイリスト'];
var group_link = ['/my/mylist#/home'];
var myitem = [];
var ready_num = 0;
var mylist_tpl = '<li class="SYS_box_item">';
mylist_tpl += '<div class="thumbContainer"><a href="watch/{watchsmid}"><img src="{thumb}"><span class="videoTime">{time}</span></a></div>';
mylist_tpl += '<div class="mylistVideo"><h5><a href="/watch/{watchsmid}">{title}</a></h5>';
mylist_tpl += '<ul class="metadata"><li>登録リスト: <a style="color:#C00;font-weight:boid;" href="{mylistlink}">{mylistname}</a></li><li class="play">再生: {playnum}</li><li class="comment">コメ: {commnum}</li><li class="mylist">マイ: <a href="mylistcomment/video/{watchsmid}">{mylistnum}</a></li></ul>';
mylist_tpl += '<p class="date">{conttime} 投稿/{regtime} 登録</p>';
mylist_tpl += '<div class="commentContainer SYS_box_memo">{memostr}</div>';
mylist_tpl += '</li>';
$('#SYS_page_items, .mylistFormWrap,.articleBody').empty();
$('#myContBody .aside, #myContBody .buttonOuter').remove();
$('.articleBody').append('<ul id="SYS_page_items" class="myContList videoList"></ul>');
$('#myContHead h3').text('マイリストサーチ');
$('#myContHead').after('<div id="myContSerach" style="margin:10px;"><div id="myContSerachBox" style="display:none;"><input type="text" size="40" id="searchbx">(文字入力 or Enter)</div><div id="myContSerachWait">検索準備中です。しばらくお待ちください。 <span id="waittext"></span></div>');
$('#myNavMylist li[id^="SYS_box_group"]').each(function(){
group_id.push($(this).attr('id').replace('SYS_box_group_',''));
group_name.push($(this).find('a span').text());
group_link.push($(this).find('a').attr('href'));
});
if($('.noListMsg').size() === 1) {
$('#myContBody').append('<ul id="SYS_page_items" class="myContList videoList"></ul>');
$('.noListMsg').remove();
}
$.ajax({
type: 'POST',
url: '/api/deflist/list',
dataType: 'json',
data: {
token: NicoAPI.token
}
}).done(function(json){
myitem[0] = json;
for(i=1;i<group_id.length;i++) {
get_mylist_json(i);
}
});
function get_mylist_json(i) {
$.ajax({
type: 'POST',
url: '/api/mylist/list',
dataType: 'json',
data: {
token: NicoAPI.token,
group_id: group_id[i]
}
}).done(function(json){
myitem[i] = json;
ready_num++;
$('#waittext').text('(' + parseInt((ready_num+1)/group_id.length*100, 10) + '%)');
if(ready_num == group_id.length-1) {
$('#myContSerachWait').slideUp();
$('#myContSerachBox').slideDown();
$('#searchbx').keyup(function(){
if($(this).val().length > 1) incremental_search($(this).val());
if($(this).val() === '') jQuery('#SYS_page_items, #SYS_box_mylist_body').empty();
});
}
});
}
function addFigure (str) {
var num = String(str).replace(/,/g, '');
while(num != (num = num.replace(/^(-?\d+)(\d{3})/, '$1,$2')));
return num;
}
function incremental_search (srcstr) {
var itms = $('#SYS_page_items');
itms.empty();
srcstr = new RegExp(srcstr, 'ig');
for(j=0;j<myitem.length;j++) {
for(i=0;i<myitem[j].mylistitem.length;i++) {
if( (myitem[j].mylistitem[i].item_data.title.match(srcstr) !== null) || (myitem[j].mylistitem[i].description.match(srcstr) !== null) ) {
data=myitem[j].mylistitem[i].item_data;
tmptpl=mylist_tpl;
tmptpl=tmptpl.replace(/{watchsmid}/g,data.video_id);
tmptpl=tmptpl.replace(/{time}/g,Math.floor(data.length_seconds/60)+':'+data.length_seconds%60);
var tD=new Date(data.first_retrieve*1000);
tD.setTime(tD.getTime()+(60*60));
tmptpl=tmptpl.replace(/{conttime}/g,tD.getFullYear()+''+(tD.getMonth()+1)+''+tD.getDate()+''+tD.getHours()+':'+tD.getMinutes());
tD = new Date(myitem[j].mylistitem[i].create_time*1000);
tD.setTime(tD.getTime()+(60*60));
tmptpl=tmptpl.replace(/{regtime}/g,tD.getFullYear()+''+(tD.getMonth()+1)+''+tD.getDate()+''+tD.getHours()+':'+tD.getMinutes());
tmptpl=tmptpl.replace(/{thumb}/g,data.thumbnail_url);
tmptpl=tmptpl.replace(/{title}/g,data.title);
tmptpl=tmptpl.replace(/{playnum}/g,addFigure(data.view_counter));
tmptpl=tmptpl.replace(/{commnum}/g,addFigure(data.num_res));
tmptpl=tmptpl.replace(/{mylistname}/g,group_name[j]);
tmptpl=tmptpl.replace(/{mylistlink}/g,group_link[j]);
tmptpl=tmptpl.replace(/{mylistnum}/g,addFigure(data.mylist_counter));
if(myitem[j].mylistitem[i].description === '') tmptpl=tmptpl.replace('{memostr}', '');
else tmptpl=tmptpl.replace("{memostr}",'<div class="myListCommentT"><div class="myListCommentB"><div class="myListCommentL"><div class="myListCommentR"><p>'+myitem[j].mylistitem[i].description+'</p></div></div></div></div>');
itms.append(tmptpl);
}
}
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.