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

Commit 862923e

Browse files
Add files via upload
1 parent 653be5b commit 862923e

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

docready.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
$(document).ready(function(){
3+
var keyword = 'Building Android Device Tree Developers@Work';
4+
searchVideosCode(keyword);
5+
var i=0;
6+
//for(i=0;i<videoId.length;i++){
7+
videosCountCode(videoId[i]);
8+
displayVideosCount(i);
9+
commentsOnAVideoCode(videoId[i]);
10+
document.getElementById(videoTitle[i]).outerHTML = '<h1 id="'+videoTitle[i]+'">'+videoTitle[i]+'</h1>';
11+
commentsOnAVideoDisplay(videoId[i]);
12+
//}
13+
});

index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html>
2+
<head>
3+
<title>CodingwithAPIs Episode - 6</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/SimpleYTVSE-VideoEmbed/script.js"></script>
6+
<script src="https://rawgit.com/DevelopersWork/CodingWithAPIs/YTCount-Views_Comments_Likes_Dislikes_Favorites/script.js"></script>
7+
<script src="auth.js"></script>
8+
<script src="script.js"></script>
9+
<script async src="docready.js"></script>
10+
</head>
11+
<body>
12+
<section id="display">
13+
Video Keyword/Title/Id: <input id="searchBar"><br>
14+
Max Results to be Displayed: <input id="maxResults" value="25"><br>
15+
<button onClick="buttonClickedSearchCommentsByVideoId()">submit</button>
16+
</section>
17+
</body>
18+
</html>

script.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
var temp = [],
2+
commentedId = [],commentedTotalReplyCount=[],
3+
commentedAuthorDisplayName=[],commentedAuthorProfileImageUrl=[],commentdAuthorChannelId=[],
4+
commentedTextDisplay=[],commentedLikeCount=[],commentedPublishedAt=[],commentedUpdatedAt=[];
5+
6+
function commentsOnAVideoCode(YouTubeVideoId,max='10'){
7+
var API_KEY = API();
8+
9+
$.ajax({
10+
url:'https://www.googleapis.com/youtube/v3/commentThreads',
11+
data:{
12+
key:API_KEY,
13+
part:'snippet',
14+
order:'time',
15+
maxResults:max,
16+
videoId:YouTubeVideoId
17+
},
18+
async:false,
19+
success:function(data){
20+
temp = data.items;
21+
22+
for(var i=0;i<temp.length;i++){
23+
commentedId[i] = temp[i].id;
24+
commentedTotalReplyCount[i] = temp[i].snippet.totalReplyCount;
25+
26+
commentedAuthorDisplayName[i] = temp[i].snippet.topLevelComment.snippet.authorDisplayName;
27+
commentedAuthorProfileImageUrl[i] = temp[i].snippet.topLevelComment.snippet.authorProfileImageUrl;
28+
commentdAuthorChannelId[i] = temp[i].snippet.topLevelComment.snippet.authorChannelId.value;
29+
30+
commentedTextDisplay[i] = temp[i].snippet.topLevelComment.snippet.textDisplay;
31+
commentedLikeCount[i] = temp[i].snippet.topLevelComment.snippet.likeCount;
32+
commentedPublishedAt[i] = temp[i].snippet.topLevelComment.snippet.publishedAt;
33+
commentedUpdatedAt[i] = temp[i].snippet.topLevelComment.snippet.updatedAt;
34+
}
35+
}
36+
});
37+
};
38+
39+
function commentsOnAVideoDisplay(YouTubeVideoId){
40+
for(var i=0;i<temp.length;i++){
41+
$('#video'+YouTubeVideoId).append('\
42+
<div id="comment'+commentedId[i]+'">\
43+
<img src="'+commentedAuthorProfileImageUrl[i]+'">\
44+
<a href="https://youtube.com/channel/'+commentdAuthorChannelId[i]+'" target="_blank">\
45+
<h1 id="'+commentdAuthorChannelId+commentedId[i]+'">"'+commentedAuthorDisplayName[i]+'"</h1>\
46+
</a>\
47+
<h2 id="'+commentedId[i]+'">\
48+
Comment:'+commentedTextDisplay[i]+'<br>\
49+
Replies:'+commentedTotalReplyCount[i]+'<br>\
50+
Likes for Comment:'+commentedLikeCount[i]+'<br>\
51+
Commented At:'+commentedPublishedAt[i]+'<br>\
52+
Last Edited:'+commentedUpdatedAt[i]+'<br></h2>\
53+
</div>\
54+
');
55+
}
56+
};
57+
58+
function buttonClickedSearchCommentsByVideoId(){
59+
this.keyword = document.getElementById('searchBar').value;
60+
document.getElementById('display').innerHTML = 'Video Keyword/Title/Id: <input id="searchBar"><br>\
61+
Max Results to be Displayed: <input id="maxResults" value="25"><br>\
62+
<button onClick="buttonClickedSearchCommentsByVideoId()">submit</button>';
63+
64+
searchVideosCode(keyword);
65+
var i=0;
66+
//for(i=0;i<videoId.length;i++){
67+
videosCountCode(videoId[i]);
68+
displayVideosCount(i);
69+
commentsOnAVideoCode(videoId[i]);
70+
document.getElementById(videoTitle[i]).outerHTML = '<h1 id="'+videoTitle[i]+'">'+videoTitle[i]+'</h1>';
71+
commentsOnAVideoDisplay(videoId[i]);
72+
//}
73+
74+
};
75+

0 commit comments

Comments
 (0)