Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit 5deaec0

Browse files
Add files via upload
1 parent 653be5b commit 5deaec0

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<title>Channels Count</title>
4+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
5+
<script src="https://rawgit.com/DevelopersWork/CodingWithAPIs/SimpleYTCSE/script.js"></script>
6+
<script src="auth.js"></script>
7+
<script async src="script.js"></script>
8+
9+
</head>
10+
<body>
11+
<section id="display" align="center" style="text-align:center">
12+
</section>
13+
</body>
14+
</html>

script.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)