// FLV Player
// Version 0.1
// 
// Copyright (c) 2006 Michael Sheldon
// Released under the GNU GPL
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name		FLV Player
// @namespace		http://www.mikeasoft.com/
// @description		Converts YouTube flash player in to an embedded link for mozilla-mplayer (or other embedded players)
// @include		http://www.youtube.com/*
// @include		http://youtube.com/*
// ==/UserScript==

var reg = /&t=[\w-]{10,}/ig
var html = document.getElementById("interactDiv").innerHTML;
extra = reg.exec(html);
if (extra) {
	var flashplayer = document.getElementById("playerDiv");
	var title = document.getElementById("video_title");
	var embedded = document.createElement("div");
	URL = window.location.href;
	var code = URL.substr(URL.lastIndexOf('v=')+2);
	if(code.indexOf('&') != -1) {
		code = code.substr(0,code.indexOf('&'))
	}
	flvURL = 'http://youtube.com/get_video?video_id=' + code + extra[0];
	embedded.innerHTML = "<embed id='player' name='player' src='" + flvURL + "' type='application/x-mplayer2' width='455' height='340' pluginspage='http://mplayerplug-in.sourceforge.net/'></embed>";
	title.parentNode.insertBefore(embedded, title.nextSibling);
	flashplayer.parentNode.removeChild(flashplayer);
}
