Skip to content

Instantly share code, notes, and snippets.

@nucular
Created March 18, 2015 17:12
Show Gist options
  • Save nucular/59e65f05020460b02b39 to your computer and use it in GitHub Desktop.
Save nucular/59e65f05020460b02b39 to your computer and use it in GitHub Desktop.
TubeAlien - Replaces Reddit comments on videos with YouTube comments!
// ==UserScript==
// @name TubeAlien for Reddit
// @namespace http://nucular.github.io
// @version 0.1
// @description TubeAlien is an userscript that replaces Reddit comments on videos with YouTube comments!
// @include /https?\:\/\/(www\.)?reddit.com\/r\/[^\/]+\/comments\/\w+\/\w+/
// @copyright 2015+, nucular
// ==/UserScript==
$(function() {
var m = $(".title .title").attr("href").match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i);
if (!m) return;
$(".commentarea").children().remove();
var $l = $("<div class='sitetable nestedlisting'></div>").appendTo(".commentarea");
$.get("https://gdata.youtube.com/feeds/api/videos/" + m[1] + "/comments", function(res) {
var $res = $(res);
$.each($res.find("entry"), function(k, v) {
var $v = $(v);
var $c = $("<div class='thing noncollapsed comment'>\
<div class='midcol likes'><div class='arrow login-required up'></div><div class='arrow login-required down'></div></div>\
<div class='entry likes'>\
<p class='tagline'>\
<a class='author may-blank'></a>\
<form action='#' type='hidden' class='usertext'>\
<div class='usertext-body may-blank-within md-container'>\
<div class='md'><p class='actual-comment-finally'></p></div>\
</div>\
</form>\
<ul class='flat-list buttons'>\
<li class='first'>\<a class='bylink' rel='nofollow'>permalink</a>\</li>\
</ul>\
</p>\
</div>\
</div>");
$c.find(".author").text($v.find("author").find("name").text())
.attr("href", "http://www.youtube.com/user/" + $v.find("author").find("uri").text().match(/users\/(.+)/)[1]);
$c.find(".actual-comment-finally").html($v.find("content").text());
$c.find(".bylink").attr("href",
"https://www.youtube.com/watch?v=" + m[1] + "&google_comment_id=" + $v.find("id").text().match(/comments\/(\w+)/)[1]);
$c.appendTo($l);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment