Won’t talk too much about this, because it’s pretty self-explainatory.

Inspired by RSS Youtube Feeds article, and based on the deviantArt and RSS Feeds Buttons extensions, I made an extension to pull the Youtube feed URL.

πŸ’Ύ

Youtube RSS Feed Button Chrome Extension

youtube-feed-button.zip (5 KB)

The code is simple, so the archive is only 5KB, because it doesn’t use jQuery, just native Javascript, but it had to use a pretty hacky approach, because I couldn’t access the ytInitialData JavaScript variable from the extension. I had to write an inline script that is dumped into a variable which is then injected into the DOM, so it has access to the ytInitialData variable, so it can do the processing. This solution (and others) is found in chapter “Method 2: Inject embedded code (MV2)” in this StackOverflow response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function testEl(element) { 
	if(element.service == 'GOOGLE_HELP') { 
		g = document.createElement('div');
		g.setAttribute("id", "yt-feed-boxes");
		document.body.appendChild(g);
		xLink = document.createElement('a');
        var xLinkText = document.createTextNode("YTRSS");
        xLink.appendChild(xLinkText); 
		xLink.setAttribute("href", "https://www.youtube.com/feeds/videos.xml?channel_id="+element.params[0].value);
		g.appendChild(xLink);
	} 
}
ytInitialData.responseContext.serviceTrackingParams.forEach((element) =>  testEl(element));

All this was dumped into a variable which was then added to the DOM.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var actualCode = `function testEl(element) { 
	//the code of the function
}
ytInitialData.responseContext.serviceTrackingParams.forEach((element) =>  testEl(element));
`;

var script = document.createElement('script');
script.textContent = actualCode;
(document.head||document.documentElement).appendChild(script);
script.remove();

80% of the time works every time, but sometimes I’ve seen it work on a new channel’s page only after a page reload. Your experience might vary.

Changelog

Version 0.1.1 β€” 2023-08-18 β€” Search pattern is now *://*.youtube.com/* instead of *://*.youtube.com/@*, because not all channels begin with an @.
Chrome Extension output

And that’s it! :)