// ==UserScript==
// @name	Link2Video
// @namespace	http://shenafu.com/
// @description	Show embedded video if provided URL

// @version	1.00
// @author	Amuseum
// @download	http://www.shenafu.com/opera/link2video.user.js

// @include	http://*.gamefaqs.com/boards/genmessage.php*

// ==/UserScript==

/*
Link2Video

Assumes page uses tables and tds.
Assumes URLs are in text nodes, e.g., not <a>URL</a>, not <object value=URL>, etc.

*/

var EMBEDPATTERN = '<object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/$1&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$1&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object>';

var SEARCHPATTERN = /http:\/\/www.youtube.com\/watch\?v=([0-9A-Za-z_-]+)/g;

function L2VReplace() {
	var tds = document.getElementsByTagName("td");
	for (i=0; i<tds.length; i++) {
		var td = tds[i];
		td.innerHTML = td.innerHTML.replace(SEARCHPATTERN, EMBEDPATTERN);
		//alert(td.innerHTML);
	}
}


window.addEventListener('load', function() {
	L2VReplace();
	},
	false
);