1 // Javascript for Adorno Music Player
3 var base_url = /(https?:\/\/[a-z0-9.-]+\/)/i.exec(document.URL)
4 base_url = base_url[0];
7 ////////////////////////////////////////////////////////////////
8 // Toggle the Artist/Album/Genre/Stream selection
9 ////////////////////////////////////////////////////////////////
10 function toggle_type() {
11 var type_span = document.getElementById('current_type');
12 var type = type_span.innerHTML.toLowerCase();
15 if ( type == 'artist' ) { type = 'album'; }
16 else if ( type == 'album' ) { type = 'stream'; }
17 else if ( type == 'stream' ) { type = 'genre'; }
18 else if ( type == 'genre' ) { type = 'artist'; }
20 type_span.innerHTML = type.substring(0,1).toUpperCase() + type.substring(1);
22 var alphabet = document.getElementById('alphabet').childNodes;
26 var title_match = new RegExp('([0-9]+ )?' + old_type,'g');
28 for (var i = 0; i < alphabet.length; i++) {
29 href = alphabet[i].href;
30 alphabet[i].href = href.replace(old_type,type);
32 // alert( href + "\n" + alphabet[i].href );
34 title = alphabet[i].title;
35 alphabet[i].title = title.replace(title_match,type);
38 var search_form = document.getElementById('search_form');
39 for (var i=0; i < search_form.elements.length; i++ ) {
40 if ( search_form.elements[i].name == 'type' ) {
41 search_form.elements[i].value = type;
48 var status_req = new XMLHttpRequest();
50 var redo_queue = true;
52 function update_now_playing() {
53 var td = document.getElementById('now_playing');
54 status_req.open('GET', base_url + 'current.php', true);
55 status_req.onreadystatechange = function (aEvt) {
56 if ( status_req.readyState == 4 ) {
57 if ( status_req.status == 200 ) {
58 if ( td.innerHTML != status_req.responseText ) {
59 td.innerHTML = status_req.responseText;
60 var in_td = td.childNodes;
62 if ( in_td.length == 1 ) {
63 var nodecontent = status_req.responseText;
64 if ( nodecontent.match(/Nothing is currently playing/i) ) {
65 title = 'Adorno: stopped';
67 else if ( nodecontent.match(/paused/i) ) {
68 title = 'Adorno: paused';
70 in_td = in_td[0].childNodes;
72 for ( var i=0; i < in_td.length; i++ ) {
73 if ( in_td[i].innerHTML == undefined ) continue;
75 title = in_td[i].innerHTML;
77 title = title + ' : ' + in_td[i].innerHTML;
79 document.title = title;
82 else if ( redo_queue )
87 status_req.send(null);
88 mytime=setTimeout('update_now_playing()',10000);
91 function update_queue() {
92 var td = document.getElementById('queue');
94 status_req.open('GET', base_url + 'queue.php', true);
95 status_req.onreadystatechange = function (aEvt) {
96 if ( status_req.readyState == 4 ) {
97 if ( status_req.status == 200 ) {
98 td.innerHTML = status_req.responseText;
104 status_req.send(null);
108 var last_action_result = '';
110 var argv = act.arguments;
111 var argc = argv.length;
113 if ( argc < 1 || argc > 2 ) {
114 alert( 'act(action,details) - only 1 or two arguments, not ' + argc + ' please!' );
118 var action = argv[0];
120 if ( argc == 2 ) details = argv[1];
122 var act_req = new XMLHttpRequest();
123 status_req.open('GET', base_url + 'action.php?action=' + action + details, true);
124 status_req.onreadystatechange = function (aEvt) {
125 if ( status_req.readyState == 4 ) {
126 if ( status_req.status == 200 ) {
127 last_action_result = 'success';
129 update_now_playing();
133 last_action_result = 'failure';
137 status_req.send(null);
141 function enqueue(artist,album,track) {
142 var details = '&l=' + album;
143 if ( artist != '' ) details = details + '&a=' + artist;
144 if ( track != '' ) details = details + '&t=' + track;
145 act('enqueue',details);
149 mytime=setTimeout('update_now_playing()',1000);