YouTube RSS Feed

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

ของเมื่อวันที่ 09-06-2014 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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