Skip to content

Instantly share code, notes, and snippets.

@vsubhash
Last active September 10, 2018 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsubhash/958fc4e9b9ff39bc1cf961e0ce74b6ae to your computer and use it in GitHub Desktop.
Save vsubhash/958fc4e9b9ff39bc1cf961e0ce74b6ae to your computer and use it in GitHub Desktop.
YouTube RSS feed generator (com.vsubhash.js.youtube-rss-feed-generator) is a User Script for Youtube that will automatically detect the RSS feed of a channel and add an RSS icon next to the channel name. It also makes the browser aware of the RSS feed causing it to activate the RSS toolbar bar button. This script can be installed in Firfox brows…
// ==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/".length));
if (oAnchors[j].href.substring(0, "https://www.youtube.com/channel/".length) == "https://www.youtube.com/channel/") {
var sChannelId = oAnchors[j].href.substring("https://www.youtube.com/channel/".length);
var oRssElement = document.createElement("a");
oRssElement.id = "YT_RSS_Feed";
oRssElement.href = "https://www.youtube.com/feeds/videos.xml?channel_id=" + 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=" + sChannelId);
document.getElementsByTagName("head")[0].appendChild(oLinkElement);
bFound = true;
break;
}
}
if (bFound) { break; }
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment