// ==UserScript== // @name Download MP3 & Video for YouTube v2.2 - (HD, MP4, AVI, FLV, Others) // @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 Punisher // @version 2.2 // @date 2018-02-03 // @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/* // @downloadURL none // ==/UserScript== if(document.getElementById("polymer-app") || document.getElementById("masthead") || window.Polymer){ setInterval(function(){ if(window.location.href.indexOf("watch?v=") < 0){ return false; } if(document.getElementById("count") && document.getElementById("genyoutube") === null){ polymerInject(); } }, 100); } else { setInterval(function(){ if(window.location.href.indexOf("watch?v=") < 0){ return false; } if(document.getElementById("watch7-subscription-container") && document.getElementById("genyoutube") === null){ htmlInject(); } }, 100); } function htmlInject(){ if (document.getElementById("watch7-subscription-container")) { var wrap = document.getElementById('watch7-subscription-container'); var button = "
"; button += ""; button += ""; button += "Download
"; var style = ""; var tmp = wrap.innerHTML; wrap.innerHTML = tmp + button + style; } } function polymerInject(){ var buttonDiv = document.createElement("span"); buttonDiv.style.width = "100%"; buttonDiv.id = "youtube"; var targetElement = document.querySelectorAll("[id='count']"); for(var i = 0; i < targetElement.length; i++){ if(targetElement[i].className.indexOf("ytd-video-primary-info-renderer") > -1){ targetElement[i].appendChild(buttonDiv); } } } function ytvid(url) { var p = /((http|https)\:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig; return (url.match(p)) ? RegExp.$3 : false; }