From ac55e8a604ad2f44d33e01c8fa963229f82b1aea Mon Sep 17 00:00:00 2001 From: andreevksya Date: Wed, 9 May 2018 20:27:33 +0000 Subject: [PATCH] [Issue 128] Current track in page title --- htdocs/js/mpd.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index ce2fd8e..066d5a6 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -528,7 +528,7 @@ function webSocketConnect() { socket.send('MPD_API_GET_QUEUE,'+pagination); break; case 'song_change': - + updatePageTitle(obj.data); $('#album').text(""); $('#artist').text(""); @@ -552,8 +552,7 @@ function webSocketConnect() { $('.top-right').notify({ message:{html: notification}, type: "info", - }).show(); - + }).show(); break; case 'mpdhost': $('#mpdhost').val(obj.data.host); @@ -667,6 +666,20 @@ var updatePlayIcon = function(state) } } +var updatePageTitle = function(songInfo) { + if(!songInfo || (!songInfo.artist && !songInfo.title)) { + document.title = 'ympd'; + return; + } + if(songInfo.artist) { + if(songInfo.title) { + document.title = songInfo.artist + ' - ' + songInfo.title; + } + } else { + document.title = songInfo.title; + } +} + function updateDB() { socket.send('MPD_API_UPDATE_DB'); $('.top-right').notify({ -- 2.20.1