YouTube RSS Feed

Adds an RSS feed button to YouTube channels next to the subscribe button

当前为 2016-12-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          YouTube RSS Feed
// @namespace     http://greasyfork.org/users/2240-doodles
// @author        Doodles
// @version       16
// @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
// @require       http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @updateVersion 16
// ==/UserScript==

(function() {
	window.jQ=jQuery.noConflict(true);
	RssFeedButton();
	document.body.addEventListener("DOMSubtreeModified", SelectiveFire);
	function SelectiveFire(){
		setTimeout(function() {
			if(jQ('#rssSubButton').length == 0){
				RssFeedButton();
			}
		}, 2500);
	}
	function RssFeedButton(){
		var rssFeed = navigator.userAgent.indexOf("Firefox") > 0 ? "http" : "feed";
		if(document.URL.indexOf("/playlist?list=") != -1){
			var playlistId = document.URL.split("list=")[1].split("&")[0];
			if(!playlistId.startsWith("PL")){
				playlistId = "PL" + playlistId;
			}
			rssFeed += "://www.youtube.com/feeds/videos.xml?playlist_id=" + playlistId;
		}else{
			rssFeed += "://www.youtube.com/feeds/videos.xml?channel_id=" + jQ("meta[itemprop='channelId']").attr("content");
		}
		if(jQ("link[title='RSS']").length === 0){
			jQ('head').append('<link rel="alternate" type="application/rss+xml" title="RSS" href="' + rssFeed + '" />');
		}
		var rssSubButton = jQ('<a/>').attr('id', 'rssSubButton').attr('target', '_blank').attr('href', rssFeed)
			.addClass('yt-uix-button yt-uix-button-size-default yt-uix-button-subscribe-branded yt-uix-button-has-icon no-icon-markup')
			.css("background", "linear-gradient(#fd9b12, #fe6702)");
		jQ(rssSubButton).html('<span class="yt-uix-button-content"><span class="subscribe-label">RSS Subscribe </span></span>');
		jQ(rssSubButton).mouseover(function(){ jQ(this).css("background", "linear-gradient(#fe6702, #fd9b12)"); });
		jQ(rssSubButton).mouseout(function(){ jQ(this).css("background", "linear-gradient(#fd9b12, #fe6702)"); });
		if(document.URL.indexOf("/playlist?list=") != -1){
			jQ('div.playlist-actions').append(rssSubButton);
		}else if(document.getElementById('c4-primary-header-contents') !== null){
			jQ('span.channel-header-subscription-button-container').prepend(document.createTextNode(" "));
			jQ('span.channel-header-subscription-button-container').prepend(rssSubButton);
		}else if(document.URL.indexOf("/watch") != -1 && document.URL.indexOf("v=") != -1){
			jQ('#watch7-subscription-container > span:first-child').prepend(document.createTextNode(" "));
			jQ('#watch7-subscription-container > span:first-child').prepend(rssSubButton);
		}
	}
})();