Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Download any YouTube video from anywhere
- // @namespace com.vsubhash.js.youtube.download
- // @description Adds a download button to YouTube videos including those embedded elsewhere
- // @version 1
- // @grant none
- // ==/UserScript==
- /*
- * Moral Volcano's YouTub DL JavaScript
- * https://moralvolcano.wordpress.com/2015/05/09/how-to-download-any-youtube-video-using-just-javascript-no-need-for-any-special-add-on-or-extension-in-opera-12x-or-older/
- * Licensed under GPL v3 as provided at
- * https://www.gnu.org/licenses/gpl.html
- *
- */
- document.addEventListener("DOMContentLoaded", addYouTubeDetectingButton(), false);
- function addYouTubeDetectingButton() {
- console.log("User JS called");
- var i, n, oDlButtonEl, oDlDiv, oVidLink;
- if ((location.href.indexOf("youtube.com/embed") != -1) ||
- (location.href.indexOf("youtube.com/watch") != -1)) {
- console.log("Inside YouTube Iframe");
- oDlDiv = document.createElement("div");
- oDlDiv.setAttribute("id", "mvJsDiv");
- oDlDiv.setAttribute("style", "color: black; background-color: orange!important; width: 100%!important; height: 1.2cm!important; font-size: 0.34cm!important; line-height: 0.4cm!important; font-family: sans-serif!important; ");
- oDlButtonEl = document.createElement("input");
- oDlDiv.setAttribute("id", "mvJsButton");
- oDlButtonEl.setAttribute("type", "button");
- oDlButtonEl.setAttribute("value", "Grab Video");
- oDlButtonEl.addEventListener("click", handle_DownloadButtonClick, false);
- oDlButtonEl.setAttribute("style", "color: white!important; border: 1px solid orange; box-shadow: 2px 2px 5px black; background-color: red!important; height: 0.9cm!important; width: 5cm!important; font-size: 0.4cm!important; line-height: 0.5cm!important; ; font-family: sans-serif!important;");
- oDlDiv.appendChild(oDlButtonEl);
- oVidLink = document.createElement("a");
- oVidLink.setAttribute("id", "mvJsLink");
- oVidLink.setAttribute("style", "color: darkblue!important; text-decoration: underline!important; font-size: 0.3cm!important; margin: 0.2cm 1cm 0.2cm 1cm!important;");
- oVidLink.innerHTML="Video URL";
- oVidLink.setAttribute("href","javascript:window.alert('First play the video a bit and pause. Then, we will get the video link.');");
- oDlDiv.appendChild(oVidLink);
- document.getElementById("player").setAttribute("style", document.getElementById("player").getAttribute("style") + "height: 90%!important; ");
- document.getElementById("player").parentNode.insertBefore(oDlDiv, document.getElementById("player"));
- document.getElementsByTagName("body")[0].style="background-color: white!important; line-height: 0.5cm;";
- document.getElementById("player").parentNode.style="background-color: white!important; ";
- }
- }
- function handle_DownloadButtonClick() {
- if (document.getElementsByTagName("video").length > 0) {
- if (document.getElementsByTagName("video")[0].src.length > 10) {
- document.getElementById("mvJsLink").setAttribute("href",document.getElementsByTagName("video")[0].src + "&title=" + document.title+".flv");
- document.getElementById("mvJsLink").innerHTML = document.getElementsByTagName("video")[0].src.substring(0,35) + "...";
- location.href=document.getElementsByTagName("video")[0].src + "&title=" + document.title+".flv";
- } else {
- window.alert("First play the video a bit and pause. Then, we will get the video link.");
- }
- } else {
- window.alert("No video has loaded yet.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement