2 function RefreshNowPlaying() {
4 var req = new XMLHttpRequest();
6 req.onreadystatechange = function () {
7 if (this.readyState != 4 || this.status != 200) return;
8 document.getElementById('nowplaying_content').innerHTML=this.responseText;
9 document.title='MPD Player: '+this.responseText;
12 req.open("GET", "ajax/trackinfo.php", true);
17 function RefreshPlayerState() {
19 var req = new XMLHttpRequest();
21 req.onreadystatechange = function () {
22 if (this.readyState != 4 || this.status != 200) return;
23 if (this.responseText=="play") {
24 document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('pause')\"><img class=\"button\" src=\"images/pause.png\"></span>";
26 document.getElementById('playpausebutton').innerHTML="<span onclick=\"Command('play')\"><img class=\"button\" src=\"images/play.png\"></span>";
30 req.open("GET", "ajax/playerstate.php", true);
35 function RefreshRepeatState() {
37 var req = new XMLHttpRequest();
39 req.onreadystatechange = function () {
40 if (this.readyState != 4 || this.status != 200) return;
41 if (this.responseText=="1") {
42 document.getElementById('repeatstate').innerHTML="<img src=\"images/repeaton.png\"></a>";
44 document.getElementById('repeatstate').innerHTML="<img src=\"images/repeatoff.png\"></a>";
48 req.open("GET", "ajax/repeatstate.php", true);
53 function RefreshVolume() {
55 var req = new XMLHttpRequest();
57 req.onreadystatechange = function () {
58 if (this.readyState != 4 || this.status != 200) return;
59 document.getElementById('volume_total').innerHTML="<div id=\"volume_actual\" style=\"width:"+this.responseText+"%\">";
62 req.open("GET", "ajax/volume.php", true);
67 function RefreshPageStatus() {
76 function RefreshPlaylist() {
78 var req = new XMLHttpRequest();
80 req.onreadystatechange = function () {
81 if (this.readyState != 4 || this.status != 200) return;
82 document.getElementById('playlist').innerHTML=this.responseText;
85 req.open("GET", "ajax/playlist.php", true);
90 function EditPlayList(dir) {
92 var req = new XMLHttpRequest();
94 req.onreadystatechange = function () {
95 if (this.readyState != 4 || this.status != 200) return;
96 document.getElementById('playlist').innerHTML=this.responseText;
99 if (!dir) { dir = ''; };
101 req.open("GET", "ajax/editplaylist.php?dir="+dir, true);
106 function RefreshPageContent() {
113 function Command(cmd) {
115 var req = new XMLHttpRequest();
117 req.onreadystatechange = function () {
118 if (this.readyState != 4 || this.status != 200) return;
122 req.open("GET", "ajax/command.php?task="+cmd, true);
127 function PlaylistCommand(cmd,item) {
129 var req = new XMLHttpRequest();
131 req.onreadystatechange = function () {
132 if (this.readyState != 4 || this.status != 200) return;
133 RefreshPageContent();
136 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
141 function PlaylistEditCommand(cmd,item) {
143 var req = new XMLHttpRequest();
145 req.onreadystatechange = function () {
146 if (this.readyState != 4 || this.status != 200) return;
150 req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true);
156 function PlaylistItemsCommand(cmd) {
158 var req = new XMLHttpRequest();
160 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
166 req.onreadystatechange = function () {
167 if (this.readyState != 4 || this.status != 200) return;
168 RefreshPageContent();
171 params=selected.map(function(el) {
172 //Map each field into a name=value string, make sure to properly escape!
173 return 'itemlist[]=' + encodeURIComponent(el);
176 req.open("POST", "ajax/playlist-command.php?task="+cmd, true);
177 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
182 function PlaylistEditItemsCommand(cmd,dir) {
184 var req = new XMLHttpRequest();
186 var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) {
192 params=selected.map(function(el) {
193 //Map each field into a name=value string, make sure to properly escape!
194 return 'itemlist[]=' + encodeURIComponent(el);
197 req.onreadystatechange = function () {
198 if (this.readyState != 4 || this.status != 200) return;
202 req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true);
203 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
208 setInterval(RefreshPageStatus, 10000);