Click here to Skip to main content
14,739,302 members
Articles » Web Development » Client side scripting » General
Posted 28 May 2018

Tagged as



A GreaseMonkey script to generate RSS feed links for YouTube channels

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
28 May 2018CPOL
RSS feed 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 browse YouTube videos via RSS, then you have to manually construct the the feed URL for each channel.

I decided to automate it using this Greasemonkey script. A few seconds after a YouTube video page gets loaded, the Javascript adds an RSS icon image next to the channel name. It links the image to the RSS feed of the YouTube channel. (The RSS icon 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 browsers can activate their RSS feed button.

// ==UserScript==
// @name        YouTube RSS feed generator
// @namespace
// @description Adds a RSS feed button to YouTube channels
// @include*
// @version     1
// @grant       none
// ==/UserScript==

document.addEventListener("DOMContentLoaded", startItDelayed, false);
function startItDelayed() {
  if (document.getElementById("YT_RSS_Feed") == null) {
    window.setTimeout(addRssButton, 5000);    

function addRssButton() {  
  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, "".length));
            if (oAnchors[j].href.substring(0, "".length) == "") {
              var sChannelId = oAnchors[j].href.substring("".length);
              var oRssElement = document.createElement("a");
     = "YT_RSS_Feed";
              oRssElement.href = "" + sChannelId;
              oRssElement.innerHTML = "<img src=\"\" style=\"margin: auto 1em; \" />";
              var oLinkElement = document.createElement("link");
              oLinkElement.setAttribute("rel", "alternate");
              oLinkElement.setAttribute("title", oAnchors[j].textContent);
              oLinkElement.setAttribute("type", "application/rss+xml");
              oLinkElement.setAttribute("href", "" + sChannelId);
              bFound = true;
          if (bFound) { break; }
Image 1

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.) RSS feeds ensures that viewers are more likely to get to know about a new video’s existence.

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

V. Subhash
Software Developer
India India
V. Subhash is a

* writer (FFMPEG Quick Hacks and CommonMark Reader Reference (for the new MarkDown standard)),
* programmer (AndroidWithoutStupid, Subhash Browser & Feed Reader, Subhash TweetsToRSS, EmailTweetor, Really Ultimate JavaScript Benchmark, and Really Universal Font Stack Stylesheet)
* illustrator (2020 Fresh Clean Jokes For Everyone) and
* humourist (400 Fresh Clean Jokes For Everyone)

Comments and Discussions

-- There are no messages in this forum --