【发布时间】:2016-09-07 07:02:35
【问题描述】:
所以,我在这个主题中看到了很多问题,但所有答案都是从旧的 gdata url 开始的,这不再起作用了。
如果我单击此页面上的(附加)按钮,我想为每个视频获取 cmets:
https://www.youtube.com/feed/subscriptions
显然这是一个篡改脚本。
我的结局是,我想从内容中获得一点点偷窥,所以我可以决定是否点击 youtube 链接。
也许我计划为 cmets 提供回复功能,但这只是一个未来的计划。
我现在拥有的:
// ==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
});
});
我想在这个时候将代码分开工作,所以我当然想在工作格式上添加这个:
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");
}
});
});
});
当我用我的 api 密钥查看浏览器时,这个 URL:
'https://www.googleapis.com/youtube/v3/comments?id=yVqreR8VXwQ&key=YOURAPIKEY&part=snippet'
我得到了这个结果:
{
"kind": "youtube#commentListResponse",
"etag": "\"kiOs9cZLH2FUp6r6KJ8eyq_LIOk/pGLBhpjR05yQoJV31WoAx2PEFVw\"",
"items": []
}
我不明白为什么,为什么我没有收到任何物品?
该网址对我来说看起来不错。
【问题讨论】:
标签: jquery youtube tampermonkey youtube-data-api