|
| 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