Youtube - Copy Channel RSS Feed Url To Clipboard

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

Από την 05/05/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Youtube - Copy Channel RSS Feed Url To Clipboard
// @namespace    http://tampermonkey.net/
// @version      0.4
// @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
// ==/UserScript==

(function() {
'use strict';

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)
})();