Raw Source
AddonDeveloper / YouTube Converter

// ==UserScript==
// @name            YouTube Converter
// @description     Youtube Converter to MP3 & MP4.
// @icon            https://www.rcyoutube.com/userscript/icon.png
//
// @author          Addon Developer
// @namespace       https://www.rcyoutube.com/
// @downloadURL     https://www.rcyoutube.com/userscript/rcyoutube.user.js
//
// @license         MIT
// @copyright       2020, Addon Developer
//
// @include         http://www.youtube.com/*
// @include         https://www.youtube.com/*
//
// @version         1.0
// @updateURL       https://www.rcyoutube.com/userscript/rcyoutube.user.js
//
// @run-at          document-end
// @unwrap
// ==/UserScript==

var rcy_button_onclick = function (){
  var path ='https://www.rcyoutube.com/convert?v='+encodeURIComponent(window.location);
  window.open(path,'_blank');
};

var getSpan = function(text, className) {
    var _tn = document.createTextNode(text);
    var span = document.createElement("span");
    span.className = className;
    span.appendChild(_tn);
    return span;
};

var myAppInterface = {
  init:function(){
    this.insertGlobalCSS()
  },
  addGlobalStyle: function(doc, css) {
    if(document.querySelector('.rcyoutube-css'))return;
    var head = doc.getElementsByTagName('head')[0];
    if (!head) {return; }
    var style = doc.createElement('style');
    style.id = 'rcyoutube-css';
    style.type = 'text/css';
    if (style.styleSheet) {
      style.styleSheet.cssText = css;
    } else {
      style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);
  },
  insertGlobalCSS: function(){
    var css = function (){
      /*start
      #rcyoutube.youtube-watch{padding-top:10px;overflow: auto;border-bottom: 1px solid #2b3e50;padding-bottom: 10px;}
      #rcyoutube .rcy_button{background-color: #2b3e50;border: #2b3e50;border-radius: 2px;color: #df691a;padding: 10px 16px; font-size: 1.4em;cursor:pointer;display:inline-block}
      @media (min-width: 657px){youtube-watch[theater] #rcyoutube.youtube-watch{margin-right:24px}}
      end*/
    }.toString().replace("/*start",'').replace("end*/",'').slice(14,-1);
    this.addGlobalStyle(document, css);
  },
}

var createButton = function() {
    var obj = document.querySelector('#primary-inner>#info');
    if(obj != null){
        // check if the button has already been created
        var btnRow = document.getElementById('rcyoutube');
        if(btnRow == null){
            myAppInterface.init()
            var rcyoutube = document.createElement("div");
            rcyoutube.id = "rcyoutube";
            rcyoutube.className = "style-scope youtube-watch";

            var rcy_button = document.createElement("div");
            rcy_button.className = "style-scope rcy_button";

            rcy_button.appendChild(getSpan("Convert to MP3 & MP4"))

            rcy_button.onclick = rcy_button_onclick;

            obj.parentNode.insertBefore(rcyoutube, obj);
            rcyoutube.appendChild(rcy_button);
        }
    }
};

var intervalCheck = setInterval(function(){ createButton() }, 250);