Youtube - Copy Channel RSS Feed Url To Clipboard

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

目前为 2017-12-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube - Copy Channel RSS Feed Url To Clipboard
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  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. // ==/UserScript==
  12.  
  13. /***
  14. Youtube doesn't seem to update ytInitialData.metadata.channelMetadataRenderer.rssUrl, or the
  15. <script> source for the page when they change the url without a full page reload.
  16. */
  17.  
  18. function getChannelRSS(){
  19. let channelRSSurl = ''
  20. /*
  21. we need to re-request the current page cause youtube doesn't update the json on the page in the <script> source or the
  22. 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).
  23. */
  24. GM_xmlhttpRequest({
  25. method: "GET",
  26. url: window.location.href,
  27. onload: function({responseText}) {
  28. if(responseText.includes('"rssUrl"')){
  29. channelRSSurl = responseText.split('"rssUrl":"')[1].split('"')[0]
  30. }
  31. 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
  32. channelRSSurl = `https://www.youtube.com/feeds/videos.xml?channel_id=${ window.location.href.split('/channel/')[1].split('/')[0] }`
  33. }
  34. GM_setClipboard(channelRSSurl)
  35. }
  36. })
  37. }
  38.  
  39. GM_registerMenuCommand('Copy Youtube Channel RSS Feed To Clipboard', getChannelRSS)