From c63a31605a9dfe0b8cfaa6c1a406073b2790179a Mon Sep 17 00:00:00 2001 From: Ican Bachors Date: Wed, 15 Mar 2017 17:10:51 +0700 Subject: [PATCH] v06 --- js/ycp.min.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/js/ycp.min.js b/js/ycp.min.js index 1c0690b..d2840e8 100644 --- a/js/ycp.min.js +++ b/js/ycp.min.js @@ -1,8 +1,7 @@ /****************************************************** -* #### jQuery-Youtube-Channels-Playlist v05 #### +* #### jQuery-Youtube-Channels-Playlist v06 #### * Coded by Ican Bachors 2014. * http://ibacor.com/labs/jquery-youtube-channels-playlist/ * Updates will be posted to this site. ******************************************************/ - -$.fn.ycp=function(h){var j={playlist:10,autoplay:false,related:false};h.playlist=(h.playlist==undefined?j.playlist:h.playlist);h.autoplay=(h.autoplay==undefined?j.autoplay:h.autoplay);h.related=(h.related==undefined?j.related:h.related);$(this).each(function(i,a){var b=($(this).attr('id')!=null&&$(this).attr('id')!=undefined?'#'+$(this).attr('id'):'.'+$(this).attr('class')),channel=$(this).data('ycp'),html='
'+'
'+'
'+'
'+'
'+'
'+'
'+'
';$(this).html(html);if(channel.substring(0,2)=='PL'||channel.substring(0,2)=='UU'){var c='';ycp_list(channel,c,i,b)}else{var d=(channel.substring(0,2)=='UC'?'id':'forUsername');ycp_play(channel,d,i,b)}});function ycp_play(c,d,e,f){$.ajax({url:'https://www.googleapis.com/youtube/v3/channels?part=contentDetails&'+d+'='+c+'&key='+h.apikey,crossDomain:true,dataType:'json'}).done(function(a){var b=a.items[0].contentDetails.relatedPlaylists.uploads,pageToken='';ycp_list(b,pageToken,e,f)})}function ycp_list(f,g,k,l){$.ajax({url:'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults='+h.playlist+'&playlistId='+f+'&key='+h.apikey+'&pageToken='+g,dataType:'json'}).done(function(c){var d='';d+='
';d+='Previous ';d+='Next?
';$.each(c.items,function(i,a){var b=c.items[i].snippet.resourceId.videoId;ycp_part(b,i,k,l);d+='
';d+='
'+c.items[i].snippet.title+'

-
'});d+='
';$(l+' .ycp div#ycp_youtube_channels'+k).html(d);if(c.prevPageToken==null||c.prevPageToken==undefined){var e=$(l+' .ycp div#ycp_youtube_channels'+k+' div.play').attr("data-vvv"),imag=$(l+' .ycp div#ycp_youtube_channels'+k+' div.play').attr("data-img");if(h.autoplay==false){$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('')}else{$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('')}$(l+' .ycp div#ycp_youtube_channels'+k+' div').removeClass('vid-active');$(l+' .ycp div#ycp_youtube_channels'+k+' div.play:eq(0)').addClass('vid-active')}else{$(l+' .ycp div#ycp_youtube_channels'+k+' span.vid-prev').click(function(){g=c.prevPageToken;ycp_list(f,g,k,l);return false})}$(l+' .ycp div#ycp_youtube_channels'+k+' span.vid-next').click(function(){g=c.nextPageToken;ycp_list(f,g,k,l);return false});$(l+' .ycp div#ycp_youtube_channels'+k+' div.play').each(function(){$(this).click(function(){var a=$(this).attr("data-vvv"),m=$(this).attr("data-img");$(l+' .ycp div#ycp_youtube_channels'+k+' div').removeClass('vid-active');$(this).addClass('vid-active');if(h.autoplay==false){$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('')}else{$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('')}return false})});$(l+' .ycp div.ycp_vid_play:eq('+k+')').click(function(){var a=$(l+' .ycp div#ycp_youtube_channels'+k+' div.play.vid-active').attr("data-vvv");$(this).html('');return false})})}function ycp_part(c,i,d,e){$.ajax({url:'https://www.googleapis.com/youtube/v3/videos?id='+c+'&key='+h.apikey+'&part=contentDetails,snippet,statistics',dataType:'json'}).done(function(a){var b=a.items[0].contentDetails.duration,dataw='',menit='',detik='';if(b.match(/M/g)){dataw=b.split('M');menit=dataw[0].replace('PT','');if(dataw[1]!=''){detik=dataw[1].replace('S','')}else{detik='00'}}else{dataw=b.split('PT');menit='00';detik=dataw[1].replace('S','')}$(e+' .ycp div#ycp_youtube_channels'+d+' span.tm'+i).html(menit+':'+detik);$(e+' .ycp div#ycp_youtube_channels'+d+' span.by'+i).html('by '+a.items[0].snippet.channelTitle);$(e+' .ycp div#ycp_youtube_channels'+d+' span.views'+i).html(addCommas(a.items[0].statistics.viewCount)+' views');$(e+' .ycp div#ycp_youtube_channels'+d+' span.date'+i).html(_timeSince(new Date(a.items[0].snippet.publishedAt).getTime()))})}function _timeSince(a){var s=Math.floor((new Date()-a)/1000),i=Math.floor(s/31536000);if(i>1){return i+" years ago"}i=Math.floor(s/2592000);if(i>1){return i+" months ago"}i=Math.floor(s/86400);if(i>1){return i+" days ago"}i=Math.floor(s/3600);if(i>1){return i+" hours ago"}i=Math.floor(s/60);if(i>1){return i+" minutes ago"}return Math.floor(s)+" seconds ago"}function addCommas(a){a+='';x=a.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var b=/(\d+)(\d{3})/;while(b.test(x1)){x1=x1.replace(b,'$1'+','+'$2')}return x1+x2}} +$.fn.ycp=function(j){var n={playlist:10,autoplay:false,related:false};j.playlist=(j.playlist==undefined?n.playlist:j.playlist);j.autoplay=(j.autoplay==undefined?n.autoplay:j.autoplay);j.related=(j.related==undefined?n.related:j.related);$(this).each(function(i,a){var b=($(this).attr('id')!=null&&$(this).attr('id')!=undefined?'#'+$(this).attr('id'):'.'+$(this).attr('class')),title=($(this).data('ycp_title')==undefined?'YCP.js':$(this).data('ycp_title')),channel=$(this).data('ycp_channel'),html='
'+'
'+'
'+'
'+'
'+'
'+'
'+'
';$(this).html(html);if(channel.substring(0,2)=='PL'||channel.substring(0,2)=='UU'){var c='';ycp_list(title,channel,c,i,b)}else{var d=(channel.substring(0,2)=='UC'?'id':'forUsername');ycp_play(title,channel,d,i,b)}});function ycp_play(g,c,d,e,f){$.ajax({url:'https://www.googleapis.com/youtube/v3/channels?part=contentDetails&'+d+'='+c+'&key='+j.apikey,crossDomain:true,dataType:'json'}).done(function(a){var b=a.items[0].contentDetails.relatedPlaylists.uploads,pageToken='';ycp_list(g,b,pageToken,e,f)})}function ycp_list(h,f,g,k,l){$.ajax({url:'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults='+j.playlist+'&playlistId='+f+'&key='+j.apikey+'&pageToken='+g,dataType:'json'}).done(function(c){var d='';d+='
';d+='
'+h+'
';d+='Prev ';d+='Next
';$.each(c.items,function(i,a){var b=c.items[i].snippet.resourceId.videoId;ycp_part(b,i,k,l);d+='
';d+='
'+c.items[i].snippet.title+'

-
'});d+='
';$(l+' .ycp div#ycp_youtube_channels'+k).html(d);if(c.prevPageToken==null||c.prevPageToken==undefined){var e=$(l+' .ycp div#ycp_youtube_channels'+k+' div.play').attr("data-vvv"),imag=$(l+' .ycp div#ycp_youtube_channels'+k+' div.play').attr("data-img");if(j.autoplay==false){$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('Play');$(l+' .ycp div.kenca:eq('+k+')').css('background','url('+imag+') no-repeat');$(l+' .ycp div.kenca:eq('+k+')').css('-webkit-background-size','cover');$(l+' .ycp div.kenca:eq('+k+')').css('-moz-background-size','cover');$(l+' .ycp div.kenca:eq('+k+')').css('-o-background-size','cover');$(l+' .ycp div.kenca:eq('+k+')').css('background-size','cover')}else{$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('')}$(l+' .ycp div#ycp_youtube_channels'+k+' div').removeClass('vid-active');$(l+' .ycp div#ycp_youtube_channels'+k+' div.play:eq(0)').addClass('vid-active')}else{$(l+' .ycp div#ycp_youtube_channels'+k+' span.vid-prev').click(function(){g=c.prevPageToken;ycp_list(h,f,g,k,l);return false})}$(l+' .ycp div#ycp_youtube_channels'+k+' span.vid-next').click(function(){g=c.nextPageToken;ycp_list(h,f,g,k,l);return false});$(l+' .ycp div#ycp_youtube_channels'+k+' div.play').each(function(){$(this).click(function(){var a=$(this).attr("data-vvv"),m=$(this).attr("data-img");$(l+' .ycp div#ycp_youtube_channels'+k+' div').removeClass('vid-active');$(this).addClass('vid-active');if(j.autoplay==false){$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('Play');$(l+' .ycp div.kenca:eq('+k+')').css('background','url('+m+') no-repeat');$(l+' .ycp div.kenca:eq('+k+')').css('-webkit-background-size','cover');$(l+' .ycp div.kenca:eq('+k+')').css('-moz-background-size','cover');$(l+' .ycp div.kenca:eq('+k+')').css('-o-background-size','cover');$(l+' .ycp div.kenca:eq('+k+')').css('background-size','cover')}else{$(l+' .ycp div.ycp_vid_play:eq('+k+')').html('')}return false})});$(l+' .ycp div.ycp_vid_play:eq('+k+')').click(function(){var a=$(l+' .ycp div#ycp_youtube_channels'+k+' div.play.vid-active').attr("data-vvv");$(this).html('');return false})})}function ycp_part(c,i,d,e){$.ajax({url:'https://www.googleapis.com/youtube/v3/videos?id='+c+'&key='+j.apikey+'&part=contentDetails,snippet,statistics',dataType:'json'}).done(function(a){var b=a.items[0].contentDetails.duration,dataw='',menit='',detik='';if(b.match(/M/g)){dataw=b.split('M');menit=dataw[0].replace('PT','');if(dataw[1]!=''){detik=dataw[1].replace('S','')}else{detik='00'}}else{dataw=b.split('PT');menit='00';detik=dataw[1].replace('S','')}$(e+' .ycp div#ycp_youtube_channels'+d+' span.tm'+i).html(menit+':'+detik);$(e+' .ycp div#ycp_youtube_channels'+d+' span.by'+i).html('by '+a.items[0].snippet.channelTitle);$(e+' .ycp div#ycp_youtube_channels'+d+' span.views'+i).html(addCommas(a.items[0].statistics.viewCount)+' views');$(e+' .ycp div#ycp_youtube_channels'+d+' span.date'+i).html(_timeSince(new Date(a.items[0].snippet.publishedAt).getTime()))})}function _timeSince(a){var s=Math.floor((new Date()-a)/1000),i=Math.floor(s/31536000);if(i>1){return i+" years ago"}i=Math.floor(s/2592000);if(i>1){return i+" months ago"}i=Math.floor(s/86400);if(i>1){return i+" days ago"}i=Math.floor(s/3600);if(i>1){return i+" hours ago"}i=Math.floor(s/60);if(i>1){return i+" minutes ago"}return Math.floor(s)+" seconds ago"}function addCommas(a){a+='';x=a.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var b=/(\d+)(\d{3})/;while(b.test(x1)){x1=x1.replace(b,'$1'+','+'$2')}return x1+x2}}