From 7e88a7b9d34d1bde215c9a9537773e3ec590b875 Mon Sep 17 00:00:00 2001 From: Ican Bachors Date: Sat, 20 Aug 2016 16:10:05 +0700 Subject: [PATCH] v03 remove window.history.pushState add multi channel playlist --- js/ycp.js | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 js/ycp.js diff --git a/js/ycp.js b/js/ycp.js new file mode 100644 index 0000000..2dde229 --- /dev/null +++ b/js/ycp.js @@ -0,0 +1,109 @@ +/****************************************************** +* #### jQuery-Youtube-Channels-Playlist v03 #### +* Coded by Ican Bachors 2014. +* http://ibacor.com/labs/jquery-youtube-channels-playlist/ +* Updates will be posted to this site. +******************************************************/ + +$.fn.ycp = function(m, n, o) { + + $(this).each(function(i, a) { + var b = ($(this).attr('id') != null ? '#' + $(this).attr('id') : '.' + $(this).attr('class')), + channel = $(this).data('ycp'), + tipe = (channel.substring(0, 2) == 'UC' ? 'id' : 'forUsername'), + html = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; + $(this).html(html); + ycp_play(channel, tipe, i, b) + }); + + function ycp_play(c, d, e, f) { + $.ajax({ + url: 'https://www.googleapis.com/youtube/v3/channels?part=contentDetails&' + d + '=' + c + '&key=' + o, + crossDomain: true, + dataType: 'json' + }).done(function(a) { + var b = a.items[0].contentDetails.relatedPlaylists.uploads, + chid = a.items[0].id, + pageToken = '', + autop = 0; + if (n) { + autop = 1 + } + ycp_list(b, pageToken, chid, autop, e, f) + }) + } + + function ycp_list(f, g, h, j, k, l) { + $.ajax({ + url: 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=' + m + '&playlistId=' + f + '&key=' + o + '&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) { + var e = $(l + ' .ycp div#ycp_youtube_channels' + k + ' div.play').attr("data-vvv"); + $(l + ' .ycp div#ycp_vid_play' + 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, h, j, k, l); + return false + }) + } + $(l + ' .ycp div#ycp_youtube_channels' + k + ' span.vid-next').click(function() { + g = c.nextPageToken; + ycp_list(f, g, h, j, k, l); + return false + }); + $(l + ' .ycp div#ycp_youtube_channels' + k + ' div.play').each(function() { + $(this).click(function() { + var a = $(this).attr("data-vvv"); + $(l + ' .ycp div#ycp_youtube_channels' + k + ' div').removeClass('vid-active'); + $(this).addClass('vid-active'); + $(l + ' .ycp div#ycp_vid_play' + k).html(''); + return false + }) + }) + }) + } + + function ycp_part(c, i, d, e) { + $.ajax({ + url: 'https://www.googleapis.com/youtube/v3/videos?id=' + c + '&key=' + o + '&part=contentDetails,snippet', + 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(a.items[0].snippet.channelTitle) + }) + } + +}