mkey / WittyTV Amici DL Link Getter

// ==UserScript==
// @name        WittyTV Amici DL Link Getter
// @namespace   amici
// @include     http://www.wittytv.it/*
// @version     1
// @grant       GM_xmlhttpRequest
// ==/UserScript==

main();

function main()
{
	var id = document.URL.match(/\d{6}/g);
	id = id.pop();
	
	if (!id)
		return alert('Stream ID not found');
	
	GM_xmlhttpRequest({
		method: 'GET',
		url: 'http://plr.video.mediaset.it/player/js/Configuration.js',
		onload: function(e)
		{
			if (e.readyState==4 && e.status!=200)
				return;
			
			var cdn = e.responseText.match(/CDN_SELECTOR_URL = "(.+)";/);
			
			if (!cdn.length)
				return alert('CDN not found');
			
			cdn = cdn.pop();
			
			GM_xmlhttpRequest({
				method: 'GET',
				url: cdn + id + '&format=json',
				onload: function(e)
				{
					if (e.readyState==4 && e.status!=200)
						return;
					
					var video = e.responseText.match(/,"(.+)"]/);
					
					if (!video.length)
						return alert('MP4 not found');
					
					video = video.pop();
					
					document.getElementsByTagName('h1')[0].innerHTML += '<br/><a style="font-size:40%;" href="' + video + '">' + video + '</a>';
				}
			});
		}
	});
}