YouTube RSS Feed

a script to add an rss feed button to youtube channels next to the subscribe button

Versione datata 09/06/2014. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           YouTube RSS Feed
// @namespace      http://greasyfork.org/users/2240-doodles
// @author         Doodles
// @version        1.7
// @description    a script to add an rss feed button to youtube channels next to the subscribe button
// @include        *://*youtube.*/user/*
// @include        *://*youtube.*/channel/*
// @include        *://*youtube.*/watch*v=*
// @grant          none
// ==/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);
	}
}