YouTube Downloader (Audio & Video from YouTube - MP3, FHD, MP4, FLV, WKV, etc) - SaveClipBro.com

This script helps to add a YouTube download button.

Versão de: 22/06/2018. Veja: a última versão.

// ==UserScript==
// @name YouTube Downloader (Audio & Video from YouTube - MP3, FHD, MP4, FLV, WKV, etc) - SaveClipBro.com
// @description This script helps to add a YouTube download button.
// @namespace https://greasyfork.org/
// @homepageURL https://greasyfork.org/scripts/34613
// @supportURL https://greasyfork.org/scripts/34613/feedback
// @author SaveClipBro.com
// @version 2.8
// @date 2018-06-22
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible safari
// @license GNU GPL v3.0 or later. http://www.gnu.org/copyleft/gpl.html
// @match       *://www.youtube.com/*
// ==/UserScript==

if("undefined" == typeof (saveclipbro)) {
	var saveclipbro = {

        userUrl: 'http://saveclipbro.com/convert?linkToDownload=',
        currentMediaUrl: null,
		getParam : function (document, variable){
			 var query = document.location.search.substring(1);
			 var vars = query.split("&");
			  for (var i=0;i<vars.length;i++) {
					var pair = vars[i].split("=");
					if(pair[0] == variable){return pair[1];}
			   }       return(false);
		},

		init : function() {
			saveclipbro.onPageLoad();		
		},

		addButtons: function(document) {
				var icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfiBgcWJSfQnWd+AAAA8klEQVQoz4XQvS6DcRQG8F8/SBEf0UR160J0MAkuwCAxsolRuADXYMF1WEQT6UDcgMkgEl9N2MSgvhLRhPf9G5rykiZ9znJyzpNznuehA1KJftSyHBp2PSQJaUsmPLq2bwiv5pwmr2QdCG4tqguCZ1O/y3QnDdm2035rCmr2RFkFw/rQpSgDggEbxh2piFhwoSH48iQSBC/W3QkOdTefbIqFREXqPluEjNiZSWPCTyYpPdK4dyKTwYcrsyqKBv9ILZp32TJb1mvVuyB4UxMEse2miha67YjFtky7ERwb+e8/r6oqjxXnZtpFVFICOeXOKYNvVG9Jr+BMPlYAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTgtMDYtMDdUMjI6Mzc6MzktMDQ6MDAbP7BNAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE4LTA2LTA3VDIyOjM3OjM5LTA0OjAwamII8QAAAABJRU5ErkJggg==';
				var saveclipbropather = saveclipbro.userUrl + encodeURIComponent(document.URL) + '&submit=';
                var div_embed = null;
                var target = '_blank';
				if(document.getElementById('meta-contents')) {
                    var div_embed = document.getElementById('meta-contents').querySelector('#top-row ytd-video-owner-renderer.ytd-video-secondary-info-renderer #sponsor-button');
                    div_embed.innerHTML += '<paper-button subscribed id="saveclipbro" style="float:right" raised class="ytd-button-renderer"><a href="' + saveclipbropather + '" target="' + target + '" style="text-decoration: none; color: black;" class="style-scope ytd-subscribe-button-renderer"><img  style="vertical-align: bottom;" src="' + icon + '"> <strong>Download</strong></a></paper-button>'+ div_embed.innerHTML;
				} else if(document.getElementById('watch8-sentiment-actions')) {
					var div_embed = document.getElementById('watch8-sentiment-actions');
					var buttonclass = "yt-uix-button yt-uix-button-default yt-uix-tooltip";
					var spanclass = "yt-uix-button-group";
                    div_embed.innerHTML = '<span id="saveclipbro" class="' + spanclass + '"><a href="' + saveclipbropather + '" target="' + target + '"><button class="start ' + buttonclass + '" type="button" title="Download"><img alt="" class="" style="" src="' + icon + '"> <span class="yt-uix-button-content"><strong>Download</strong></span></button></a>' + div_embed.innerHTML;
				}
		},

		onPageLoad : function() {
			if(document.body && document.domain == 'www.youtube.com') {
					setInterval(saveclipbro.check, 1300);
                    saveclipbro.check();
			}
		},

        check: function() {
            if(saveclipbro.currentMediaUrl != document.URL  && typeof ytplayer != 'undefined' && ytplayer) {
                saveclipbro.currentMediaUrl = document.URL;
                if(document.getElementById('saveclipbro')) {
                    document.getElementById('saveclipbro').outerHTML="";
                }
			}
            if(!document.getElementById('saveclipbro') && typeof ytplayer != 'undefined' && ytplayer) {
                saveclipbro.addButtons(document);
            }
        },
	};
}
saveclipbro.init();