// ==UserScript==
// @name          Google Video Download
// @namespace     http://post.thing.net/
// @description   Google Video as it should be. Enable embedded Flash Video(for those countries where it is disabled) and provide download links
// @include       http://video.google.*/*
// ==/UserScript==

// find videourl

var video_obj = document.getElementById('VideoPlayback');
if(video_obj)
  var video_url = unescape(video_obj.data.match(/videoUrl=([^$)]*)/)[1]);
else {

  
  video_obj = document.getElementsByTagName('body')[0];
  var video_url = unescape(video_obj.innerHTML.match(/videoUrl=([^$)]*playerMode=embedded)/)[1]);

  video_innerHTML = document.getElementById('embedhtml').innerHTML;
  video_innerHTML = video_innerHTML.replace('&lt;','<');
  video_innerHTML = video_innerHTML.replace('&gt;','>');
  video_innerHTML = video_innerHTML.replace('&lt;/embed&gt;','</embed>');
  video_innerHTML = video_innerHTML.replace('width:400px; ','width: 100%;');
  playvideoblock = document.getElementById('playvideoblock');
  playvideoblock.innerHTML = video_innerHTML;
}

var banner = document.createElement("div");
banner.innerHTML = '<div style="float:right; margin-top:44px;margin-right:201px;width: 130px; border: 1px solid #000; margin-bottom: 10px; font-size: small; border-bottom:0;">' +
	'<p style="margin: 5px;text-align:center;">' +
	'<a href="' + video_url + '" style="font-weight:bold; font-size:10px;">Download Flash Video</a>' +
	'</p></div>';
document.body.insertBefore(banner, document.body.firstChild);


