Søvnløs og scripting

Jeg baksede et hurtigt javascript sammen som hentede det nuværende nummer som spiller fra min favorit radiostation. Det er hverken kønt eller specielt brugbart men det slog da en times tid ihjel.

 

function HttpRequest(url){
var pageRequest = false //variable to hold ajax object
if (!pageRequest && typeof XMLHttpRequest != 'undefined')
   pageRequest = new XMLHttpRequest()
if (pageRequest){ //if pageRequest is not false
   pageRequest.open('GET', url, false) //get page synchronously 
   pageRequest.send(null)
   embedpage(pageRequest)
   }
}

function embedpage(request){
//if viewing page offline or the document was successfully retrieved online (status code=2000)
if (window.location.href.indexOf("http")==-1 || request.status==200)
	var ebmContent = request.responseText;
	var re = /]*>([\S\s]*?)<\/p>/g;
	var match = re.exec(  ebmContent.substring(2200, 3000)   );
	var CurrentTrack = match[1];

	CurrentTrack = CurrentTrack.replace(/&(lt|gt);/g, function (strMatch, p1){ return (p1 == "lt")? "<" : ">";});	//remove tags
   CurrentTrack = CurrentTrack.replace(/<\/?[^>]+(>|$)/g, "");

	CurrentTrack = CurrentTrack.replace(/^\s*|\s*$/g,'');	//remove additional whitespaces
	CurrentTrack = CurrentTrack.replace(/\s/g,'+');			//turn whitespaces into +
	
		window.location = "http://www.twitter.com/home?status=EBM-radio+is+playing+:::+"+ CurrentTrack;
}

HttpRequest("http://www.ebm-radio.de/scripts/latest_tracks/scxml_onlydata.php") //include "external.htm" onto current page