// ==UserScript==
// @name          Online Radio URL Extractor
// @version       0.1
// @description   Shows the five most recent comments
// @include	  http://radio.hinet.net/player/*.asp*
// @include	  http://radio.hinet.net/radio/player/player.jsp*

// This is a open source script. You are welcome to modify, redistribute, and put on any place for download.
// ==/UserScript=

(function() {

if(unsafeWindow) w = unsafeWindow;
else w = window;

alert(document.location);
GM_xmlhttpRequest({
    method: 'GET',
    url: document.location,
    headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey Online Radio URL Extractor','Accept': 'application/atom+xml,application/xml,text/html', },
    onload: function(result) {
	alert(1);
	if( result.status != 200 ) alert('Connection to radio fail.');
	alert('Request for Atom feed returned ' + result.status + ' ' + result.statusText + '\n\n' + 'Feed data:\n' + result.responseText);
    }
});


// alert(document.getElementById('Player'));
var player = w.document.getElementById('Player');
alert(player.URL);
var player_document = parent.player.document;
// var player_document = document.getElementsByTagName('frame')[0];
var input_tags = player_document.getElementsByTagName('input');

for(var i=0; i<input_tags.length; i++) {
    if(input_tags[i].name == 'media_url') {
	var text = input_tags[i].value;
	var re = /(mms:\/\/live.media.hinet.net\/radio.*\?.*)$/;
	var url = re.exec(text)[1];
	break;
    }
}

var s = document.createElement('div');
s.style.margin = '20px';
s.style.fontFamily = 'Verdana, Arial, sans-serif';
s.style.fontSize = '12px';
s.appendChild(document.createTextNode('The following link is for Firefox users. Click the mms link will launch Windows Media Player.'));
s.appendChild(document.createElement('br'));
s.appendChild(document.createElement('br'));
s.appendChild(document.createTextNode('mms URL: '));
var link = document.createElement('a');
link.href = url;
link.innerHTML = url;
s.appendChild(link);
player_document.body.appendChild(s);

})();

