Sunday, September 30, 2012

Simple YouTube MP4 Downloader (No Java)


// ==UserScript==
// @name           Simple YouTube MP4 Downloader
// @namespace      http://www.youtubeinmp4.com
// @description    A download button will be added to YouTube videos that allow you to download. No java required!
// @include        http://*youtube.*/*watch*
// @include        https://*youtube.*/*watch*
// @version        1.3.3
// ==/UserScript==

// ==ChangeLog==
// @history        1.3.3  Server update
// @history        1.3.2  Server update
// @history        1.3  MP3 section added
// @history        1.2  Download Page Edited
// @history        1.1  Servers upgraded
// @history        1.00 Initial release.
// ==/ChangeLog==

(function () {
 var FromYouTubeMP4URL = 'http://www.youtubeinmp4.com/youtube.php?video=' + location.href, container = document.getElementById('watch-actions');
 
 if (container && !document.getElementById('watch-download')) {
  var btn = document.createElement('button'),
   lastContainerChild = container.lastElementChild;
  
  btn.className = 'master-sprite yt-uix-tooltip-reverse yt-uix-button yt-uix-tooltip';
  btn.id = 'watch-download';
  btn.setAttribute('type', 'button');
  btn.setAttribute('title', 'Download This Video');
  btn.setAttribute('data-tooltip', 'Download This Video');
  btn.setAttribute('data-tooltip-title', 'Download This Video');
  
  var txt = document.createElement('span');
  txt.appendChild(document.createTextNode('Download MP4'));
  txt.setAttribute('class', 'yt-uix-button-content');
  
  btn.appendChild(txt);
  
  btn.addEventListener('click', function () {
   window.open(FromYouTubeMP4URL, 'downloadWindow');
  }, false);
  
  if (lastContainerChild) {
   btn.className = lastContainerChild.className;
   
   container.insertBefore(btn, lastContainerChild.nextSibling);
   
   lastContainerChild.style.marginRight = '0.5em';
  } else {
   container.appendChild(btn);
  }
  
  if (btn.offsetTop > lastContainerChild.offsetTop) {
   var btnMarginTop = '0.5em', containerStyle = getComputedStyle(container);
   
   btn.style.marginTop = btnMarginTop;
   
   container.style.height = (parseInt(containerStyle.getPropertyValue('height'), 10) +
    parseInt(btnMarginTop, 10) +
    parseInt(btn.offsetTop, 10) -
    parseInt(btn.offsetHeight, 10)).toString() +
    'px';
  }
 }
 
 if (location.search.search('v=') !== -1) {
  FromYouTubeMP4URL = 'http://www.youtubeinmp4.com/youtube.php?video=' + 'http://www.youtube.com/watch?v=' + location.search.split('v=')[1].split('&')[0];
 } else {
  window.addEventListener('message', function (event) {
   FromYouTubeMP4URL = 'http://www.youtubeinmp4.com/youtube.php?video=' + 'http://www.youtube.com/watch?v=' + event.data;
  }, false);
  
  location.assign('javascript:void(' + function () {
   typeof yt !== 'undefined' && window.postMessage(yt.getConfig('VIDEO_ID'), '*');
  }.toString() + '());');
 }
}());

0 comments:

Post a Comment