I've written a simple bookmarklet to go to the YouTube channel RSS feed URL from at least any video or channel page:
javascript:(function () {
var newLocation = function () {
var url;
Array.prototype.slice.call(document.getElementsByTagName('link')).forEach(function (element) {
if (element.getAttribute('type') === 'application/rss+xml') {
console.log('Found direct feed link');
url = element.getAttribute('href');
}
});
if (!url) {
Array.prototype.slice.call(document.getElementsByTagName('meta')).forEach(function (element) {
if (element.getAttribute('itemprop') === 'channelId') {
console.log('Found channel ID');
url = 'https://www.youtube.com/feeds/videos.xml?channel_id=' + element.getAttribute('content');
}
});
}
return url;
}();
if (newLocation === undefined) {
console.log('Could not find a channel RSS feed from ' + location.href);
} else {
location.href = newLocation;
}
})();
Some questions which come to mind:
- Is this the simplest way to find an element with a specific attribute value?
- Does this work with recent browsers other than Firefox?
- Does it use any non-standard/deprecated features?
- Are there any YouTube pages this does not work on, where it should?