A GreaseMonkey script to generate RSS feed links for YouTube channels

Many people use RSS feeds as the primary means to access news and information. RSS is anonymous and does not require you to log in.

Though YouTube generates RSS feeds for its channels, it does not display them (to human visitors) or advertise them (to browser software). If you prefer to subscribe to YouTube videos via RSS, then you have to manually construct the the feed URL for each channel.

I decided to automate the task using this Greasemonkey script. A few seconds after a YouTube video page gets loaded, the Greasemonkey Javascript adds an RSS icon image next to the channel name. The script links the image to the RSS feed of the YouTube channel. (This RSS icon image works seamlessly as it is from Google and is used in its “News” pages.) The Greasemonkey script also adds an RSS link tag to the HTML HEAD section so that browser applications can activate their RSS feed toolbar button.


// ==UserScript==
// @name YouTube RSS feed generator
// @namespace com.vsubhash.js.youtube-rss-feed-generator
// @description Adds a RSS feed button to YouTube channels
// @include https://www.youtube.com/watch*
// @version 2018
// @grant none
// ==/UserScript==
document.addEventListener("DOMContentLoaded", startItDelayed, false);
function startItDelayed() {
if (document.getElementById("YT_RSS_Feed") == null) {
window.setTimeout(addRssButton, 6*1000);
}
}
function addRssButton() {
console.log("Executing YouTube RSS feed generator")
var oDivs = document.getElementsByTagName("div");
if ((oDivs != null) && (oDivs.length > 0)) {
for (var i = 0; i < oDivs.length; i++) { if (oDivs[i].className == "yt-user-info") {
//console.log("YRFG Error: Here");
var oAnchors = oDivs[i].getElementsByTagName("a"); if ((oAnchors != null) && (oDivs.length>1)) {
var bFound = false;
for (var j = 0; j < oAnchors.length; j++) {
//console.log("YRFG Error: " + oAnchors[j].href.substring(0, "https://www.youtube.com/channel/&quot;.length));
if (oAnchors[j].href.substring(0, "https://www.youtube.com/channel/&quot;.length) == "https://www.youtube.com/channel/&quot;) {
var sChannelId = oAnchors[j].href.substring("https://www.youtube.com/channel/&quot;.length);
var oRssElement = document.createElement("a");
oRssElement.id = "YT_RSS_Feed";
oRssElement.href = "https://www.youtube.com/feeds/videos.xml?channel_id=&quot; + sChannelId;
oRssElement.innerHTML = "<img src=\"https://www.google.com/images/rss.png\" style=\"margin: auto 1em; \" />";
oAnchors[j].appendChild(oRssElement);
var oLinkElement = document.createElement("link");
oLinkElement.setAttribute("rel", "alternate");
oLinkElement.setAttribute("title", oAnchors[j].textContent);
oLinkElement.setAttribute("type", "application/rss+xml");
oLinkElement.setAttribute("href", "https://www.youtube.com/feeds/videos.xml?channel_id=&quot; + sChannelId);
document.getElementsByTagName("head")[0].appendChild(oLinkElement);
bFound = true;
break;
}
}
if (bFound) { break; }
}
}
}
}
}

A YouTube channel listing in the Bamboo RSS feed reader (a Firefox add-on or extension).

RSS provides an easier way to check Youtube channels. All that matters to YouTube is that people see their ads. RSS does not block ads and so no problem. Viewers who rely on subscriptions are likely to miss new but not so fresh videos if they don’t log in regularly. (Such videos get folded/wrapped/hidden as newer videos are published.) YouTube RSS feeds can ensure that viewers are more likely to get to know about the existence of a new video.

And, to use this script, you will need the Greasemonkey add-on in the browser. It can be installed from the Firefox/Seamonkey browser add-on search page (Tools – Add-ons from the main menu).

This article has been submitted to .

Make a comment