Adds an RSS feed button to YouTube channels next to the subscribe button
当前为
// ==UserScript==
// @name YouTube RSS Feed
// @namespace http://greasyfork.org/users/2240-doodles
// @author Doodles
// @version 11
// @description Adds an RSS feed button to YouTube channels next to the subscribe button
// @icon http://i.imgur.com/Ty5HNbT.png
// @icon64 http://i.imgur.com/1FfVvNr.png
// @include *://*youtube.*/*
// @grant none
// @run-at document-end
// @updateVersion 11
// ==/UserScript==
// Using a work-around to use jQuery, and be compatible with Chrome
// Found here: http://stackoverflow.com/a/3550261
(function() {
function addJQuery(callback){
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js");
script.addEventListener('load', function(){
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function RssFeedButton(){
// YouTube page load fix, so script runs properly on every page
jQ('a').click(function( event ) {
event.preventDefault();
window.location = jQ(this).attr("href");
});
// NOTE: this is a horrible solution, but everything else I tried didnt work 100% of the time
// Discussion of this problem found here: http://stackoverflow.com/a/21146511
var rssFeedNew = "feed://www.youtube.com/feeds/videos.xml?channel_id=";
var rssFeed = "nope";
if(document.URL.indexOf("/user/") != -1 || document.URL.indexOf("/channel/") != -1){
var metaId = jQ("meta[itemprop='channelId']");
if(metaId.length != 0){
rssFeed = rssFeedNew + jQ(metaId[0]).attr("content");
}else{
var linkRss = jQ("link[title='RSS']");
if(linkRss.length != 0){
rssFeed = jQ(linkRss[0]).attr("href");
if(rssFeed.startsWith("https")){
rssFeed = "feed" + rssFeed.substring(5);
}else if(rssFeed.startsWith("http")){
rssFeed = "feed" + rssFeed.substring(4);
}
}
}
}else if(document.URL.indexOf("/watch") != -1 && document.URL.indexOf("v=") != -1){
var metaId = jQ("meta[itemprop='channelId']");
if(metaId.length != 0){
rssFeed = rssFeedNew + jQ(metaId[0]).attr("content");
}
}
if(rssFeed != "nope"){
var button = document.createElement('button');
button.setAttribute('class', 'yt-uix-button yt-uix-button-size-default yt-uix-button-subscribe-branded yt-uix-button-has-icon no-icon-markup yt-uix-subscription-button yt-can-buffer');
button.setAttribute('onclick', "parent.location='" + rssFeed + "'");
var outerSpan = document.createElement('span');
outerSpan.setAttribute('class', 'yt-uix-button-content');
var innerSpan = document.createElement('span');
innerSpan.setAttribute('class', 'subscribe-label');
innerSpan.appendChild(document.createTextNode('RSS Subscribe '));
button.appendChild(outerSpan);
outerSpan.appendChild(innerSpan);
jQ(button).css("background", "linear-gradient(#fd9b12, #fe6702)");
jQ(button).mouseover(function(){ jQ(this).css("background", "linear-gradient(#fe6702, #fd9b12)"); });
jQ(button).mouseout(function(){ jQ(this).css("background", "linear-gradient(#fd9b12, #fe6702)"); });
if(document.URL.indexOf("/user/") != -1 || document.URL.indexOf("/channel/") != -1){
var header = document.getElementById('c4-primary-header-contents');
if(header != null){
var divs = header.getElementsByTagName('span');
for(var i = 0; i < divs.length;i++){
var cl = divs.item(i).getAttribute('class');
if(cl.indexOf("channel-header-subscription-button-container") != -1){
var firstButton = divs.item(i).getElementsByTagName('button')[0];
divs.item(i).insertBefore(button, firstButton);
var spacer = document.createTextNode(" ");
divs.item(i).insertBefore(spacer, firstButton);
}
}
}
}else if(document.URL.indexOf("/watch") != -1 && document.URL.indexOf("v=") != -1){
var header = document.getElementById('watch7-subscription-container');
if(header != null){
var properSpan = header.getElementsByTagName('span')[0];
properSpan.insertBefore(document.createTextNode(" "), properSpan.firstChild);
properSpan.insertBefore(button, properSpan.firstChild);
}
}
}
}
addJQuery(RssFeedButton);
})();