YouTube RSS Feed

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

目前為 2014-07-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          YouTube RSS Feed
// @namespace     http://greasyfork.org/users/2240-doodles
// @author        Doodles
// @version       10
// @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.*/user/*
// @include       *://*youtube.*/channel/*
// @include       *://*youtube.*/watch*v=*
// @grant         none
// @updateVersion 10
// ==/UserScript==

if(document.URL.indexOf("/user/") != -1 || document.URL.indexOf("/channel/") != -1)
{
	var rss = chanGetLink();
	if(rss != "//") 
	{
		var button = chanCreateButton(rss);
		var success = chanPlaceButton(button);
		if(document.URL.indexOf("RSSSubscribe=now") != -1)
		{
			document.body.innerHTML = "<div align='center'><br><br>This page is where the RSS Feed is auto-opened " + 
			"from.<br>Just close this page.<br><br><a href='" + document.URL.replace("?RSSSubscribe=now","") + 
			"'>The channel</a> - <a href='"+rss+"'>The RSS Link</a></div>";
			window.location.assign(rss);
		}
	}
}
else if(document.URL.indexOf("/watch") != -1 && document.URL.indexOf("v=") != -1)
{
	var chanLink = vidGetLink();
	if(chanLink != "//")
	{
		var button = vidCreateButton(chanLink);
		var success = vidPlaceButton(button);
	}
}

//
// METHODS
//

function chanGetLink() {
	var links = document.getElementsByTagName("link");
	for (var i = 0; i < links.length; i++) 
	{
		var type = links[i].getAttribute("title");
		if (type == "RSS")
		{
			return links[i].getAttribute("href");
		}
	}
	return "//";
}

function chanCreateButton(rssLink) {
	//
	var button = document.createElement('button');
	button.setAttribute('class', 'yt-subscription-button yt-subscription-button-js-default yt-uix-button yt-uix-button-subscribe-branded');
	button.setAttribute('data-tooltip-text', 'Subscribe by RSS Feed');
	button.setAttribute('onclick', "parent.location='" + rssLink + "'");
	button.setAttribute('type', 'button');
	button.setAttribute('role', 'button');
	//
	var outerSpan = document.createElement('span');
	outerSpan.setAttribute('class', 'yt-uix-button-content');
	//
	var innerSpan = document.createElement('span');
	innerSpan.setAttribute('class', 'subscribe-hh-label');
	innerSpan.appendChild(document.createTextNode('RSS Subscribe '));
	//
	button.appendChild(outerSpan);
	outerSpan.appendChild(innerSpan);
	//
	return button;
}

function chanPlaceButton(button) {
	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);
			}
		}
	}
}

function vidGetLink() {
	var header = document.getElementById('watch7-user-header');
	if(header != null)
	{
		var channelLink = "//";
		var divs = header.getElementsByTagName('a');	
		for(var i = 0; i < divs.length;i++)
		{
			var cl = divs.item(i).getAttribute('class');
			if(cl.indexOf("yt-user-name") != -1)
			{
				var hrefPart = divs.item(i).getAttribute('href');
				var startPart = document.URL.split("/watch")[0];
				channelLink = startPart + hrefPart;
				break;
			}
		}
		return channelLink;
	}
}

function vidCreateButton(chanLink) {
	//
	var button = document.createElement('button');
	button.setAttribute('class', 'yt-subscription-button yt-subscription-button-js-default yt-uix-button yt-uix-button-subscribe-branded');
	button.setAttribute('onclick', "window.open('" + chanLink + "?RSSSubscribe=now" + "','_blank');");
	button.setAttribute('type', 'button');
	button.setAttribute('role', 'button');
	//
	var outerSpan = document.createElement('span');
	outerSpan.setAttribute('class', 'yt-uix-button-content');
	//
	var innerSpan = document.createElement('span');
	innerSpan.setAttribute('class', 'subscribe-hh-label');
	innerSpan.appendChild(document.createTextNode('RSS Subscribe '));
	//
	button.appendChild(outerSpan);
	outerSpan.appendChild(innerSpan);
	//
	return button;
}

function vidPlaceButton(button) {
	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);
	}
}