Youtube - Copy Channel RSS Feed Url To Clipboard

Adds a Tampermonkey menu to copy a Youtube Channel's RSS feed url to the clipboard.

  1. // ==UserScript==
  2. // @name Youtube - Copy Channel RSS Feed Url To Clipboard
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Adds a Tampermonkey menu to copy a Youtube Channel's RSS feed url to the clipboard.
  6. // @author You
  7. // @match https://www.youtube.com/user/*
  8. // @match https://www.youtube.com/channel/*
  9. // @grant GM_setClipboard
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_xmlhttpRequest
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16. function getChannelRSS(){
  17. let channelRSSurl = ''
  18. /*
  19. we need to re-request the current page cause youtube doesn't update the json on the page in the <script> source or the
  20. ytInitialData.metadata.channelMetadataRenderer.rssUrl when they change the url without a full page reload (e.g. when you click on one of your channels on the left).
  21. */
  22. GM_xmlhttpRequest({
  23. method: "GET",
  24. url: window.location.href,
  25. onload: function({responseText}) {
  26. if(responseText.includes('"rssUrl"')){
  27. channelRSSurl = responseText.split('"rssUrl":"')[1].split('"')[0]
  28. }
  29. else{ // for some reason the rssUrl isn't in the json on the page sometimes, in that case, try to fall back to if the channel name in the url is the youtube channel id
  30. channelRSSurl = `https://www.youtube.com/feeds/videos.xml?channel_id=${ window.location.href.split('/channel/')[1].split('/')[0] }`
  31. }
  32. GM_setClipboard(channelRSSurl)
  33. }
  34. })
  35. }
  36.  
  37. GM_registerMenuCommand('Copy Youtube Channel RSS Feed To Clipboard', getChannelRSS)