Youtube - Copy Channel RSS Feed Url To Clipboard

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube - Copy Channel RSS Feed Url To Clipboard
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Adds a Tampermonkey menu to copy a Youtube Channel's RSS feed url to the clipboard.
// @author       You
// @match        https://www.youtube.com/user/*
// @match        https://www.youtube.com/channel/*
// @grant        GM_setClipboard
// @grant        GM_registerMenuCommand
// @grant        GM_xmlhttpRequest
// ==/UserScript==



function getChannelRSS(){
  let channelRSSurl = ''
  
  /*
    we need to re-request the current page cause youtube doesn't update the json on the page in the <script> source or the 
    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).
  */
  
  GM_xmlhttpRequest({
    method: "GET",
    url: window.location.href,
    onload: function({responseText}) {
      if(responseText.includes('"rssUrl"')){
        channelRSSurl = responseText.split('"rssUrl":"')[1].split('"')[0]
      }
      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
        channelRSSurl = `https://www.youtube.com/feeds/videos.xml?channel_id=${ window.location.href.split('/channel/')[1].split('/')[0] }`
      }
      GM_setClipboard(channelRSSurl)
    }
  })
}

GM_registerMenuCommand('Copy Youtube Channel RSS Feed To Clipboard', getChannelRSS)