1
+ var subscriberCount = [ ] , viewCount = [ ] , commentCount = [ ] , videoCount = [ ] ;
2
+
3
+ $ ( document ) . ready ( function ( ) {
4
+ this . keyword = 'Developers@Work' ;
5
+ searchCode ( this . keyword ) ;
6
+ var i = 0 ;
7
+ //for(i=0;i<temp.length;i++){
8
+ countCode ( channelId [ i ] , i ) ;
9
+ displaychannelscount ( i ) ;
10
+ //}
11
+ } ) ;
12
+
13
+ function getNewChannel ( ) {
14
+ document . getElementById ( 'display' ) . innerHTML = '' ;
15
+ this . keyword = prompt ( 'Enter Channel Id/Title/username' , 'Developers@Work' ) ;
16
+ searchCode ( this . keyword ) ;
17
+ var i = 0 ;
18
+ //for(i=0;i<temp.length;i++){
19
+ countCode ( channelId [ i ] , i ) ;
20
+ displaychannelscount ( i ) ;
21
+ //}
22
+ }
23
+
24
+
25
+ function countCode ( channelId , i = 0 ) {
26
+ var API_KEY = API ( ) ;
27
+ $ . ajax ( {
28
+ url :'https://www.googleapis.com/youtube/v3/channels' ,
29
+ data :{
30
+ key : API_KEY ,
31
+ id : channelId ,
32
+ part : 'statistics'
33
+ } ,
34
+ async :false ,
35
+ success : function ( data ) {
36
+ var temp = data . items [ 0 ] ;
37
+ subscriberCount [ i ] = temp . statistics . subscriberCount ;
38
+ viewCount [ i ] = temp . statistics . viewCount ;
39
+ commentCount [ i ] = temp . statistics . commentCount ;
40
+ videoCount [ i ] = temp . statistics . videoCount ;
41
+ }
42
+ } ) ;
43
+ }
44
+
45
+ function displaychannelscount ( i ) {
46
+ $ ( '#display' ) . append ( '\
47
+ <div id="channel' + channelId [ i ] + '">\
48
+ <img src="' + channelThumbnail [ i ] + '">\
49
+ <h1 id="' + channelTitle [ i ] + '" onClick="getNewChannel()">' + channelTitle [ i ] + '</h1>\
50
+ <h2 id="' + channelId [ i ] + '">Subscribers : ' + subscriberCount [ i ] + '</h2>\
51
+ <h2 id="' + channelId [ i ] + '">Channel Views: ' + viewCount [ i ] + '</h2>\
52
+ <h2 id="' + channelId [ i ] + '">Videos : ' + videoCount [ i ] + '</h2>\
53
+ <h2 id="' + channelId [ i ] + '">Comments : ' + commentCount [ i ] + '</h2>\
54
+ </div>\
55
+ ' ) ;
56
+ }
0 commit comments