YouTube RSS Feed

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

Από την 20/07/2014. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);
	}
}