So, I saw a lot of question in this subject, but all answers is start with old gdata url, which is dosen't work anymore.
I would like to get comments for every video, if I click a (appended) button on this page:
https://www.youtube.com/feed/subscriptions
Obviously this is a tampermonkey script.
My finish is, I whanna get a little sneek peak from the content, so I can decid I whana click for the youtube link or not.
Maybe I plan reply function for the comments, but this just a future plan.
What I have now:
// ==UserScript==
// @name hovercards for youtube
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.youtube.com/*
// @grant none
// @require https://code.jquery.com/jquery-latest.min.js
// ==/UserScript==
/* jshint -W097 */
//'use strict';
jQuery(document).ready(function() {
$("a.yt-uix-tile-link,.yt-ui-ellipsis-2k").on("mouseover",function() {
//Replace video block start
$(function() {
$('a.yt-uix-tile-link,.yt-ui-ellipsis-2k').each(function() {
var yt_url = this.href,
yt_id = yt_url.split('?v=')[1],
yt_title = $(this).text();
$(this).replaceWith('<div class="youtube-box" style="background-image:url(https://img.youtube.com/vi/' + yt_id + '/0.jpg);"><span class="youtube-title">' + yt_title + '</span><span class="youtube-bar"><span class="yt-bar-left"></span><span class="yt-bar-right"></span></span> </div>');
$("div.youtube-box").on("mouseover",function() {
$(this).replaceWith('<iframe width="560" height="315" frameborder="0" allowfullscreen class="youtube-frame" src="https://www.youtube.com/embed/' + yt_id + '?autoplay=1"></iframe>');
});
});
});
//Replace video block end
});
});
And I would like to separete that code isent work at this time, so i would like to add this on working format of course:
jQuery(document).ready(function() {
jQuery("'a.yt-uix-tile-link,.yt-ui-ellipsis-2k").append("<input type='button' value='Give me my comments' class='button'>");
jQuery(".button").on("click",function() {
jQuery.getJSON('https://www.googleapis.com/youtube/v3/comments?id=yVqreR8VXwQ&key=YOURAPIKEY&part=snippet',function(data){
//Replace the YOURAPI key section for your key
if (typeof(data.items[0]) != "undefined") {
console.log('video exists ' + data.items[0].snippet.comment);
$(".result").append( data.items[0].snippet.comment);
} else {
console.log('video not exists');
jQuery("result").append("Nope, we don't get any data");
}
});
});
});
When I looked in to the broweser this URL with my api key:
'https://www.googleapis.com/youtube/v3/comments?id=yVqreR8VXwQ&key=YOURAPIKEY&part=snippet
'
I get this result:
{
"kind": "youtube#commentListResponse",
"etag": "\"kiOs9cZLH2FUp6r6KJ8eyq_LIOk/pGLBhpjR05yQoJV31WoAx2PEFVw\"",
"items": []
}
And I don't understand why, why I dosen't get any items?
The url looks fine to me.