X-Git-Url: https://git.rvb.name/mpd-web.git/blobdiff_plain/585224f5dbe2565ed04c97b054e8d8354c21dc5e..75e2078309389c03d7baa25c2f597b4b42367894:/ajax/mpd.js~ diff --git a/ajax/mpd.js~ b/ajax/mpd.js~ new file mode 100644 index 0000000..fec89c6 --- /dev/null +++ b/ajax/mpd.js~ @@ -0,0 +1,263 @@ + +function RefreshNowPlaying() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('nowplaying_content').innerHTML=this.responseText; +}; + +req.open("GET", "ajax/trackinfo.php", true); +req.send(); + +} + +function RefreshTitle() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.title='MPD Player: '+this.responseText; +}; + +req.open("GET", "ajax/trackname.php", true); +req.send(); +} + +function RefreshPlayerState() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + if (this.responseText=="play") { + document.getElementById('playpausebutton').innerHTML=""; + } else { + document.getElementById('playpausebutton').innerHTML=""; + } +}; + +req.open("GET", "ajax/playerstate.php", true); +req.send(); + +} + +function RefreshRepeatState() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + if (this.responseText=="1") { + document.getElementById('repeatstate').innerHTML=""; + } else { + document.getElementById('repeatstate').innerHTML=""; + } +}; + +req.open("GET", "ajax/repeatstate.php", true); +req.send(); + +} + +function RefreshVolume() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('volume_total').innerHTML="
"; +}; + +req.open("GET", "ajax/volume.php", true); +req.send(); + +} + +function RefreshPageStatus() { + + RefreshTitle(); + RefreshNowPlaying(); + RefreshPlayerState(); + RefreshRepeatState(); + RefreshVolume(); + +} + +function RefreshPlaylist() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('playlist').innerHTML=this.responseText; +}; + +req.open("GET", "ajax/playlist.php", true); +req.send(); + +} + +function EditPlayList(dir) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('playlist').innerHTML=this.responseText; +}; + +if (!dir) { dir = ''; }; + +req.open("GET", "ajax/editplaylist.php?dir="+dir, true); +req.send(); + +} + +function LoadPlayList() { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + document.getElementById('playlist').innerHTML=this.responseText; +}; + +req.open("GET", "ajax/playlists.php", true); +req.send(); + +} + +function RefreshPageContent() { + + RefreshPageStatus(); + RefreshPlaylist(); + +} + +function Command(cmd) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageStatus(); +}; + +req.open("GET", "ajax/command.php?task="+cmd, true); +req.send(); + +} + +function PlaylistCommand(cmd,item) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageContent(); +}; + +req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true); +req.send(); + +} + +function PlaylistCommandRefStatus(cmd,item) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageStatus(); +}; + +req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true); +req.send(); + +} + +function PlaylistEditCommand(cmd,item) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageStatus(); +}; + +req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true); +req.send(); + +} + +function PlaylistEditCommandRefFull(cmd,item) { + +var req = new XMLHttpRequest(); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageContent(); +}; + +req.open("GET", "ajax/playlist-command.php?item="+item+"&task="+cmd, true); +req.send(); + +} + + +function PlaylistItemsCommand(cmd) { + +var req = new XMLHttpRequest(); + +var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) { + return c.checked; +}).map(function(c) { + return c.value; +}); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageContent(); +}; + +params=selected.map(function(el) { + //Map each field into a name=value string, make sure to properly escape! + return 'itemlist[]=' + encodeURIComponent(el); + }).join('&'); + +req.open("POST", "ajax/playlist-command.php?task="+cmd, true); +req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); +req.send(params); + +} + +function PlaylistEditItemsCommand(cmd,dir) { + +var req = new XMLHttpRequest(); + +var selected = [].filter.call(document.getElementsByName('itemlist[]'), function(c) { + return c.checked; +}).map(function(c) { + return c.value; +}); + +params=selected.map(function(el) { + //Map each field into a name=value string, make sure to properly escape! + return 'itemlist[]=' + encodeURIComponent(el); + }).join('&'); + +req.onreadystatechange = function () { + if (this.readyState != 4 || this.status != 200) return; + RefreshPageStatus(); +}; + +req.open("POST", "ajax/playlist-command.php?dir="+dir+"&task="+cmd, true); +req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); +req.send(params); + +} + +setInterval(RefreshPageStatus, 10000);