2018-06-21 21:29:49 +00:00
var $jscomp = $jscomp || { } ; $jscomp . scope = { } ; $jscomp . ASSUME _ES5 = ! 1 ; $jscomp . ASSUME _NO _NATIVE _MAP = ! 1 ; $jscomp . ASSUME _NO _NATIVE _SET = ! 1 ; $jscomp . defineProperty = $jscomp . ASSUME _ES5 || "function" == typeof Object . defineProperties ? Object . defineProperty : function ( a , b , c ) { a != Array . prototype && a != Object . prototype && ( a [ b ] = c . value ) } ; $jscomp . getGlobal = function ( a ) { return "undefined" != typeof window && window === a ? a : "undefined" != typeof global && null != global ? global : a } ; $jscomp . global = $jscomp . getGlobal ( this ) ; $jscomp . SYMBOL _PREFIX = "jscomp_symbol_" ;
$jscomp . initSymbol = function ( ) { $jscomp . initSymbol = function ( ) { } ; $jscomp . global . Symbol || ( $jscomp . global . Symbol = $jscomp . Symbol ) } ; $jscomp . Symbol = function ( ) { var a = 0 ; return function ( b ) { return $jscomp . SYMBOL _PREFIX + ( b || "" ) + a ++ } } ( ) ;
$jscomp . initSymbolIterator = function ( ) { $jscomp . initSymbol ( ) ; var a = $jscomp . global . Symbol . iterator ; a || ( a = $jscomp . global . Symbol . iterator = $jscomp . global . Symbol ( "iterator" ) ) ; "function" != typeof Array . prototype [ a ] && $jscomp . defineProperty ( Array . prototype , a , { configurable : ! 0 , writable : ! 0 , value : function ( ) { return $jscomp . arrayIterator ( this ) } } ) ; $jscomp . initSymbolIterator = function ( ) { } } ; $jscomp . arrayIterator = function ( a ) { var b = 0 ; return $jscomp . iteratorPrototype ( function ( ) { return b < a . length ? { done : ! 1 , value : a [ b ++ ] } : { done : ! 0 } } ) } ;
2018-07-03 21:46:07 +00:00
$jscomp . iteratorPrototype = function ( a ) { $jscomp . initSymbolIterator ( ) ; a = { next : a } ; a [ $jscomp . global . Symbol . iterator ] = function ( ) { return this } ; return a } ; $jscomp . makeIterator = function ( a ) { $jscomp . initSymbolIterator ( ) ; var b = a [ Symbol . iterator ] ; return b ? b . call ( a ) : $jscomp . arrayIterator ( a ) } ; $jscomp . arrayFromIterator = function ( a ) { for ( var b , c = [ ] ; ! ( b = a . next ( ) ) . done ; ) c . push ( b . value ) ; return c } ; $jscomp . arrayFromIterable = function ( a ) { return a instanceof Array ? a : $jscomp . arrayFromIterator ( $jscomp . makeIterator ( a ) ) } ;
$jscomp . checkStringArgs = function ( a , b , c ) { if ( null == a ) throw new TypeError ( "The 'this' value for String.prototype." + c + " must not be null or undefined" ) ; if ( b instanceof RegExp ) throw new TypeError ( "First argument to String.prototype." + c + " must not be a regular expression" ) ; return a + "" } ;
$jscomp . polyfill = function ( a , b , c , e ) { if ( b ) { c = $jscomp . global ; a = a . split ( "." ) ; for ( e = 0 ; e < a . length - 1 ; e ++ ) { var d = a [ e ] ; d in c || ( c [ d ] = { } ) ; c = c [ d ] } a = a [ a . length - 1 ] ; e = c [ a ] ; b = b ( e ) ; b != e && null != b && $jscomp . defineProperty ( c , a , { configurable : ! 0 , writable : ! 0 , value : b } ) } } ;
$jscomp . polyfill ( "String.prototype.repeat" , function ( a ) { return a ? a : function ( a ) { var b = $jscomp . checkStringArgs ( this , null , "repeat" ) ; if ( 0 > a || 1342177279 < a ) throw new RangeError ( "Invalid count value" ) ; a |= 0 ; for ( var e = "" ; a ; ) if ( a & 1 && ( e += b ) , a >>>= 1 ) b += b ; return e } } , "es6" , "es3" ) ;
2018-07-16 17:33:20 +00:00
var socket , last _song = "" , last _state , current _song = { } , playstate = "" , settings = { } , alertTimeout , deferredPrompt , app = { apps : { Playback : { state : "0/-/" , scrollPos : 0 } , Queue : { state : "0/Any Tag/" , scrollPos : 0 } , Browse : { active : "Database" , tabs : { Filesystem : { state : "0/-/" , scrollPos : 0 } , Playlists : { state : "0/-/" , scrollPos : 0 } , Database : { active : "Artist" , views : { Artist : { state : "0/-/" , scrollPos : 0 } , Album : { state : "0/-/" , scrollPos : 0 } } } } } , Search : { state : "0/Any Tag/" , scrollPos : 0 } } , current : { app : "Playback" , tab : void 0 , view : void 0 , page : 0 , filter : "" ,
search : "" , scrollPos : 0 } , last : { app : void 0 , tab : void 0 , view : void 0 , filter : "" , search : "" , scrollPos : 0 } } , domCache = { } ; domCache . navbarBottomBtns = document . getElementById ( "navbar-bottom" ) . getElementsByTagName ( "div" ) ; domCache . navbarBottomBtnsLen = domCache . navbarBottomBtns . length ; domCache . panelHeadingBrowse = document . getElementById ( "panel-heading-browse" ) . getElementsByTagName ( "a" ) ; domCache . panelHeadingBrowseLen = domCache . panelHeadingBrowse . length ; domCache . counter = document . getElementById ( "counter" ) ;
domCache . volumePrct = document . getElementById ( "volumePrct" ) ; domCache . volumeControl = document . getElementById ( "volumeControl" ) ; domCache . volumeIcon = document . getElementById ( "volumeIcon" ) ; domCache . btnPlay = document . getElementById ( "btnPlay" ) ; domCache . btnPrev = document . getElementById ( "btnPrev" ) ; domCache . btnNext = document . getElementById ( "btnNext" ) ; domCache . progressBar = document . getElementById ( "progressBar" ) ; domCache . volumeBar = document . getElementById ( "volumeBar" ) ; domCache . outputs = document . getElementById ( "outputs" ) ;
domCache . btnAdd = document . getElementById ( "btnAdd" ) ; var modalConnectionError = new Modal ( document . getElementById ( "modalConnectionError" ) ) , modalSettings = new Modal ( document . getElementById ( "modalSettings" ) ) , modalAddstream = new Modal ( document . getElementById ( "modalAddstream" ) ) , modalSavequeue = new Modal ( document . getElementById ( "modalSavequeue" ) ) , modalSongDetails = new Modal ( document . getElementById ( "modalSongDetails" ) ) , mainMenu = new Dropdown ( document . getElementById ( "mainMenu" ) ) ;
2018-07-09 19:20:09 +00:00
function appPrepare ( a ) { if ( app . current . app != app . last . app || app . current . tab != app . last . tab || app . current . view != app . last . view ) { for ( var b = 0 ; b < domCache . navbarBottomBtnsLen ; b ++ ) domCache . navbarBottomBtns [ b ] . classList . remove ( "active" ) ; document . getElementById ( "cardPlayback" ) . classList . add ( "hide" ) ; document . getElementById ( "cardQueue" ) . classList . add ( "hide" ) ; document . getElementById ( "cardBrowse" ) . classList . add ( "hide" ) ; document . getElementById ( "cardSearch" ) . classList . add ( "hide" ) ; for ( b = 0 ; b < domCache . panelHeadingBrowseLen ; b ++ ) domCache . panelHeadingBrowse [ b ] . classList . remove ( "active" ) ;
2018-07-03 21:46:07 +00:00
document . getElementById ( "cardBrowsePlaylists" ) . classList . add ( "hide" ) ; document . getElementById ( "cardBrowseDatabase" ) . classList . add ( "hide" ) ; document . getElementById ( "cardBrowseFilesystem" ) . classList . add ( "hide" ) ; document . getElementById ( "card" + app . current . app ) . classList . remove ( "hide" ) ; document . getElementById ( "nav" + app . current . app ) . classList . add ( "active" ) ; void 0 != app . current . tab && ( document . getElementById ( "card" + app . current . app + app . current . tab ) . classList . remove ( "hide" ) , document . getElementById ( "card" + app . current . app +
2018-07-09 19:20:09 +00:00
"Nav" + app . current . tab ) . classList . add ( "active" ) ) ; scrollTo ( a ) } }
function appGoto ( a , b , c , e ) { var d = document . body . scrollTop ? document . body . scrollTop : document . documentElement . scrollTop ; void 0 != app . apps [ app . current . app ] . scrollPos ? app . apps [ app . current . app ] . scrollPos = d : void 0 != app . apps [ app . current . app ] . tabs [ app . current . tab ] . scrollPos ? app . apps [ app . current . app ] . tabs [ app . current . tab ] . scrollPos = d : void 0 != app . apps [ app . current . app ] . tabs [ app . current . tab ] . views [ app . current . view ] . scrollPos && ( app . apps [ app . current . app ] . tabs [ app . current . tab ] . views [ app . current . view ] . scrollPos = d ) ; app . apps [ a ] . tabs ?
( void 0 == b && ( b = app . apps [ a ] . active ) , app . apps [ a ] . tabs [ b ] . views ? ( void 0 == c && ( c = app . apps [ a ] . tabs [ b ] . active ) , a = "/" + a + "/" + b + "/" + c + "!" + ( void 0 == e ? app . apps [ a ] . tabs [ b ] . views [ c ] . state : e ) ) : a = "/" + a + "/" + b + "!" + ( void 0 == e ? app . apps [ a ] . tabs [ b ] . state : e ) ) : a = "/" + a + "!" + ( void 0 == e ? app . apps [ a ] . state : e ) ; location . hash = a }
function appRoute ( ) { if ( params = decodeURI ( location . hash ) . match ( /^#\/(\w+)\/?(\w+)?\/?(\w+)?!((\d+)\/([^\/]+)\/(.*))$/ ) ) { app . current . app = params [ 1 ] ; app . current . tab = params [ 2 ] ; app . current . view = params [ 3 ] ; app . apps [ app . current . app ] . state ? ( app . apps [ app . current . app ] . state = params [ 4 ] , app . current . scrollPos = app . apps [ app . current . app ] . scrollPos ) : app . apps [ app . current . app ] . tabs [ app . current . tab ] . state ? ( app . apps [ app . current . app ] . tabs [ app . current . tab ] . state = params [ 4 ] , app . apps [ app . current . app ] . active = app . current . tab , app . current . scrollPos =
app . apps [ app . current . app ] . tabs [ app . current . tab ] . scrollPos ) : app . apps [ app . current . app ] . tabs [ app . current . tab ] . views [ app . current . view ] . state && ( app . apps [ app . current . app ] . tabs [ app . current . tab ] . views [ app . current . view ] . state = params [ 4 ] , app . apps [ app . current . app ] . active = app . current . tab , app . apps [ app . current . app ] . tabs [ app . current . tab ] . active = app . current . view , app . current . scrollPos = app . apps [ app . current . app ] . tabs [ app . current . tab ] . views [ app . current . view ] . scrollPos ) ; app . current . page = parseInt ( params [ 5 ] ) ; app . current . filter =
2018-07-16 17:33:20 +00:00
params [ 6 ] ; app . current . search = params [ 7 ] ; appPrepare ( app . current . scrollPos ) ; if ( "Playback" == app . current . app ) sendAPI ( { cmd : "MPD_API_GET_CURRENT_SONG" } , songChange ) ; else if ( "Queue" == app . current . app ) { document . getElementById ( "QueueList" ) . classList . add ( "opacity05" ) ; for ( var a = document . getElementById ( "searchqueuetag" ) . getElementsByTagName ( "button" ) , b = 0 ; b < a . length ; b ++ ) a [ b ] . classList . remove ( "active" ) , a [ b ] . innerText == app . current . filter && ( a [ b ] . classList . add ( "active" ) , document . getElementById ( "searchqueuetagdesc" ) . innerText =
a [ b ] . innerText ) ; getQueue ( ) } else if ( "Browse" == app . current . app && "Playlists" == app . current . tab ) document . getElementById ( "BrowsePlaylistsList" ) . classList . add ( "opacity05" ) , sendAPI ( { cmd : "MPD_API_GET_PLAYLISTS" , data : { offset : app . current . page , filter : app . current . filter } } , parsePlaylists ) , doSetFilterLetter ( "BrowsePlaylistsFilter" ) ; else if ( "Browse" == app . current . app && "Database" == app . current . tab && "Artist" == app . current . view ) document . getElementById ( "BrowseDatabaseArtistList" ) . classList . add ( "opacity05" ) , sendAPI ( { cmd : "MPD_API_GET_ARTISTS" ,
data : { offset : app . current . page , filter : app . current . filter } } , parseListDBtags ) , doSetFilterLetter ( "BrowseDatabaseFilter" ) ; else if ( "Browse" == app . current . app && "Database" == app . current . tab && "Album" == app . current . view ) document . getElementById ( "BrowseDatabaseAlbumCards" ) . classList . add ( "opacity05" ) , sendAPI ( { cmd : "MPD_API_GET_ARTISTALBUMS" , data : { offset : app . current . page , filter : app . current . filter , albumartist : app . current . search } } , parseListDBtags ) , doSetFilterLetter ( "BrowseDatabaseFilter" ) ; else if ( "Browse" == app . current . app &&
"Filesystem" == app . current . tab ) { document . getElementById ( "BrowseFilesystemList" ) . classList . add ( "opacity05" ) ; sendAPI ( { cmd : "MPD_API_GET_FILESYSTEM" , data : { offset : app . current . page , path : app . current . search ? app . current . search : "/" , filter : app . current . filter } } , parseFilesystem ) ; app . current . search ? document . getElementById ( "BrowseFilesystemAddAllSongs" ) . removeAttribute ( "disabled" ) : document . getElementById ( "BrowseFilesystemAddAllSongs" ) . setAttribute ( "disabled" , "disabled" ) ; a = '<li class="breadcrumb-item"><a data-uri="">root</a></li>' ;
2018-07-09 19:20:09 +00:00
var c = app . current . search . split ( "/" ) , e = c . length , d = "" ; for ( b = 0 ; b < e ; b ++ ) { if ( e - 1 == b ) { a += '<li class="breadcrumb-item active">' + c [ b ] + "</li>" ; break } d += c [ b ] ; a += '<li class="breadcrumb-item"><a data-uri="' + d + '">' + c [ b ] + "</a></li>" ; d += "/" } b = document . getElementById ( "BrowseBreadcrumb" ) ; b . innerHTML = a ; a = b . getElementsByTagName ( "a" ) ; c = a . length ; for ( b = 0 ; b < c ; b ++ ) a [ b ] . addEventListener ( "click" , function ( ) { appGoto ( "Browse" , "Filesystem" , void 0 , "0/" + app . current . filter + "/" + this . getAttribute ( "data-uri" ) ) } , ! 1 ) ; doSetFilterLetter ( "BrowseFilesystemFilter" ) } else if ( "Search" ==
2018-07-16 17:33:20 +00:00
app . current . app ) for ( document . getElementById ( "searchstr" ) . focus ( ) , document . getElementById ( "SearchList" ) . classList . add ( "opacity05" ) , app . last . app != app . current . app && "" != app . current . search && ( document . getElementById ( "SearchList" ) . getElementsByTagName ( "tbody" ) [ 0 ] . innerHTML = '<tr><td><span class="material-icons">search</span></td><td colspan="5">Searching...</td></tr>' ) , 2 <= app . current . search . length ? sendAPI ( { cmd : "MPD_API_SEARCH" , data : { mpdtag : app . current . filter , offset : app . current . page , searchstr : app . current . search } } ,
parseSearch ) : ( document . getElementById ( "SearchList" ) . getElementsByTagName ( "tbody" ) [ 0 ] . innerHTML = "" , document . getElementById ( "searchAddAllSongs" ) . setAttribute ( "disabled" , "disabled" ) , document . getElementById ( "panel-heading-search" ) . innerText = "" , document . getElementById ( "SearchList" ) . classList . remove ( "opacity05" ) ) , a = document . getElementById ( "searchtags" ) . getElementsByTagName ( "button" ) , c = a . length , b = 0 ; b < c ; b ++ ) a [ b ] . classList . remove ( "active" ) , a [ b ] . innerText == app . current . filter && ( a [ b ] . classList . add ( "active" ) ,
document . getElementById ( "searchtagsdesc" ) . innerText = a [ b ] . innerText ) ; else appGoto ( "Playback" ) ; app . last . app = app . current . app ; app . last . tab = app . current . tab ; app . last . view = app . current . view } else appGoto ( "Playback" ) }
2018-07-03 21:46:07 +00:00
function appInit ( ) { getSettings ( ) ; sendAPI ( { cmd : "MPD_API_GET_OUTPUTNAMES" } , parseOutputnames ) ; webSocketConnect ( ) ; domCache . volumeBar . value = 0 ; domCache . volumeBar . addEventListener ( "change" , function ( a ) { sendAPI ( { cmd : "MPD_API_SET_VOLUME" , data : { volume : domCache . volumeBar . value } } ) } , ! 1 ) ; domCache . progressBar . value = 0 ; domCache . progressBar . addEventListener ( "change" , function ( a ) { current _song && 0 <= current _song . currentSongId && sendAPI ( { cmd : "MPD_API_SET_SEEK" , data : { songid : current _song . currentSongId , seek : Math . ceil ( domCache . progressBar . value /
100 * current _song . totalTime ) } } ) } , ! 1 ) ; document . getElementById ( "modalAbout" ) . addEventListener ( "shown.bs.modal" , function ( ) { sendAPI ( { cmd : "MPD_API_GET_STATS" } , parseStats ) } ) ; document . getElementById ( "modalSettings" ) . addEventListener ( "shown.bs.modal" , function ( ) { getSettings ( ) ; document . getElementById ( "settingsFrm" ) . classList . remove ( "was-validated" ) ; document . getElementById ( "inputCrossfade" ) . classList . remove ( "is-invalid" ) ; document . getElementById ( "inputMixrampdb" ) . classList . remove ( "is-invalid" ) ; document . getElementById ( "inputMixrampdelay" ) . classList . remove ( "is-invalid" ) } ) ;
2018-07-16 17:33:20 +00:00
document . getElementById ( "modalAddstream" ) . addEventListener ( "shown.bs.modal" , function ( ) { document . getElementById ( "streamurl" ) . focus ( ) } ) ; document . getElementById ( "addstreamFrm" ) . addEventListener ( "submit" , function ( ) { addStream ( ) } ) ; addFilterLetter ( "BrowseFilesystemFilterLetters" ) ; addFilterLetter ( "BrowseDatabaseFilterLetters" ) ; addFilterLetter ( "BrowsePlaylistsFilterLetters" ) ; for ( var a = document . querySelectorAll ( "button[data-href], a[data-href]" ) , b = a . length , c = 0 ; c < b ; c ++ ) a [ c ] . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ;
a . stopPropagation ( ) ; a = JSON . parse ( this . getAttribute ( "data-href" ) . replace ( /'/g , '"' ) ) ; if ( "function" === typeof window [ a . cmd ] ) switch ( a . cmd ) { case "sendAPI" : sendAPI . apply ( null , $jscomp . arrayFromIterable ( a . options ) ) ; break ; default : window [ a . cmd ] . apply ( null , $jscomp . arrayFromIterable ( a . options ) ) } } , ! 1 ) ; a = document . querySelectorAll ( ".pages" ) ; b = a . length ; for ( c = 0 ; c < b ; c ++ ) a [ c ] . addEventListener ( "click" , function ( a ) { "BUTTON" == a . target . nodeName && gotoPage ( a . target . getAttribute ( "data-page" ) ) } , ! 1 ) ; document . getElementById ( "outputs" ) . addEventListener ( "click" ,
function ( a ) { "BUTTON" == a . target . nodeName && a . stopPropagation ( ) ; sendAPI ( { cmd : "MPD_API_TOGGLE_OUTPUT" , data : { output : a . target . getAttribute ( "data-output-id" ) , state : a . target . classList . contains ( "active" ) ? 0 : 1 } } ) ; toggleBtn ( a . target . id ) } , ! 1 ) ; document . getElementById ( "QueueList" ) . addEventListener ( "click" , function ( a ) { "TD" == a . target . nodeName ? sendAPI ( { cmd : "MPD_API_PLAY_TRACK" , data : { track : a . target . parentNode . getAttribute ( "data-trackid" ) } } ) : "A" == a . target . nodeName && ( a . preventDefault ( ) , showMenu ( a . target ) ) } , ! 1 ) ; document . getElementById ( "BrowseFilesystemList" ) . addEventListener ( "click" ,
function ( a ) { if ( "TD" == a . target . nodeName ) switch ( a . target . parentNode . getAttribute ( "data-type" ) ) { case "dir" : appGoto ( "Browse" , "Filesystem" , void 0 , "0/" + app . current . filter + "/" + decodeURI ( a . target . parentNode . getAttribute ( "data-uri" ) ) ) ; break ; case "song" : appendQueue ( "song" , decodeURI ( a . target . parentNode . getAttribute ( "data-uri" ) ) , a . target . parentNode . getAttribute ( "data-name" ) ) ; break ; case "plist" : appendQueue ( "plist" , decodeURI ( a . target . parentNode . getAttribute ( "data-uri" ) ) , a . target . parentNode . getAttribute ( "data-name" ) ) } else "A" ==
a . target . nodeName && ( a . preventDefault ( ) , showMenu ( a . target ) ) } , ! 1 ) ; document . getElementById ( "BrowsePlaylistsList" ) . addEventListener ( "click" , function ( a ) { "TD" == a . target . nodeName ? appendQueue ( "plist" , decodeURI ( a . target . parentNode . getAttribute ( "data-uri" ) ) , a . target . parentNode . getAttribute ( "data-name" ) ) : "A" == a . target . nodeName && ( a . preventDefault ( ) , showMenu ( a . target ) ) } , ! 1 ) ; document . getElementById ( "BrowseDatabaseArtistList" ) . addEventListener ( "click" , function ( a ) { "TD" == a . target . nodeName && appGoto ( "Browse" , "Database" ,
"Album" , "0/-/" + a . target . parentNode . getAttribute ( "data-uri" ) ) } , ! 1 ) ; document . getElementById ( "SearchList" ) . addEventListener ( "click" , function ( a ) { "TD" == a . target . nodeName ? appendQueue ( "song" , decodeURI ( a . target . parentNode . getAttribute ( "data-uri" ) ) , a . target . parentNode . getAttribute ( "data-name" ) ) : "A" == a . target . nodeName && ( a . preventDefault ( ) , showMenu ( a . target ) ) } , ! 1 ) ; document . getElementById ( "searchtags" ) . addEventListener ( "click" , function ( a ) { "BUTTON" == a . target . nodeName && appGoto ( app . current . app , app . current . tab , app . current . view ,
"0/" + a . target . innerText + "/" + app . current . search ) } , ! 1 ) ; document . getElementById ( "searchqueuestr" ) . addEventListener ( "keyup" , function ( a ) { appGoto ( app . current . app , app . current . tab , app . current . view , "0/" + app . current . filter + "/" + this . value ) } , ! 1 ) ; document . getElementById ( "searchqueuetag" ) . addEventListener ( "click" , function ( a ) { "BUTTON" == a . target . nodeName && appGoto ( app . current . app , app . current . tab , app . current . view , app . current . page + "/" + a . target . innerText + "/" + app . current . search ) } , ! 1 ) ; document . getElementById ( "search" ) . addEventListener ( "submit" ,
function ( ) { return ! 1 } , ! 1 ) ; document . getElementById ( "searchqueue" ) . addEventListener ( "submit" , function ( ) { return ! 1 } , ! 1 ) ; document . getElementById ( "searchstr" ) . addEventListener ( "keyup" , function ( a ) { appGoto ( "Search" , void 0 , void 0 , "0/" + app . current . filter + "/" + this . value ) } , ! 1 ) ; window . addEventListener ( "hashchange" , appRoute , ! 1 ) ; document . addEventListener ( "keydown" , function ( a ) { if ( "INPUT" != a . target . tagName ) { switch ( a . which ) { case 37 : clickPrev ( ) ; break ; case 39 : clickNext ( ) ; break ; case 32 : clickPlay ( ) ; break ; default : return } a . preventDefault ( ) } } ,
! 1 ) ; "serviceWorker" in navigator && window . addEventListener ( "load" , function ( ) { navigator . serviceWorker . register ( "/sw.js" , { scope : "/" } ) . then ( function ( a ) { console . log ( "ServiceWorker registration successful with scope: " , a . scope ) } , function ( a ) { console . log ( "ServiceWorker registration failed: " , a ) } ) } ) ; window . addEventListener ( "beforeinstallprompt" , function ( a ) { a . preventDefault ( ) ; deferredPrompt = a } ) ; window . addEventListener ( "beforeinstallprompt" , function ( a ) { a . preventDefault ( ) ; deferredPrompt = a ; domCache . btnAdd . classList . remove ( "hide" ) } ) ;
domCache . btnAdd . addEventListener ( "click" , function ( a ) { domCache . btnAdd . classList . add ( "hide" ) ; deferredPrompt . prompt ( ) ; deferredPrompt . userChoice . then ( function ( a ) { "accepted" === a . outcome ? console . log ( "User accepted the A2HS prompt" ) : console . log ( "User dismissed the A2HS prompt" ) ; deferredPrompt = null } ) } ) ; window . addEventListener ( "appinstalled" , function ( a ) { console . log ( "appinstalled" ) } ) }
2018-07-05 20:23:44 +00:00
function webSocketConnect ( ) { socket = new WebSocket ( getWsUrl ( ) ) ; try { socket . onopen = function ( ) { console . log ( "connected" ) ; showNotification ( "Connected to myMPD" , "" , "" , "success" ) ; modalConnectionError . hide ( ) ; appRoute ( ) } , socket . onmessage = function ( a ) { if ( a . data !== last _state && 0 != a . data . length ) { try { var b = JSON . parse ( a . data ) } catch ( c ) { console . log ( "Invalid JSON data received: " + a . data ) } switch ( b . type ) { case "state" : parseState ( b ) ; break ; case "disconnected" : showNotification ( "myMPD lost connection to MPD" , "" , "" , "danger" ) ;
break ; case "update_queue" : "Queue" === app . current . app && getQueue ( ) ; break ; case "song_change" : songChange ( b ) ; break ; case "error" : showNotification ( b . data , "" , "" , "danger" ) } } } , socket . onclose = function ( ) { console . log ( "disconnected" ) ; modalConnectionError . show ( ) ; setTimeout ( function ( ) { console . log ( "reconnect" ) ; webSocketConnect ( ) } , 3E3 ) } } catch ( a ) { alert ( "Error: " + a ) } }
function getWsUrl ( ) { var a = document . URL ; if ( "https" == a . substring ( 0 , 5 ) ) { var b = "wss://" ; a = a . substr ( 8 ) } else b = "ws://" , "http" == a . substring ( 0 , 4 ) && ( a = a . substr ( 7 ) ) ; a = a . split ( "#" ) ; var c = /\/$/ . test ( a [ 0 ] ) ? "" : "/" ; return b + a [ 0 ] + c + "ws" }
2018-07-03 21:46:07 +00:00
function parseStats ( a ) { document . getElementById ( "mpdstats_artists" ) . innerText = a . data . artists ; document . getElementById ( "mpdstats_albums" ) . innerText = a . data . albums ; document . getElementById ( "mpdstats_songs" ) . innerText = a . data . songs ; document . getElementById ( "mpdstats_dbplaytime" ) . innerText = beautifyDuration ( a . data . dbplaytime ) ; document . getElementById ( "mpdstats_playtime" ) . innerText = beautifyDuration ( a . data . playtime ) ; document . getElementById ( "mpdstats_uptime" ) . innerText = beautifyDuration ( a . data . uptime ) ; var b = new Date ( 1E3 *
2018-07-16 20:56:56 +00:00
a . data . dbupdated ) ; document . getElementById ( "mpdstats_dbupdated" ) . innerText = b . toUTCString ( ) ; document . getElementById ( "mympdVersion" ) . innerText = a . data . mympd _version ; document . getElementById ( "mpdVersion" ) . innerText = a . data . mpd _version } function toggleBtn ( a , b ) { if ( a = document . getElementById ( a ) ) void 0 == b && ( b = a . classList . contains ( "active" ) ? 0 : 1 ) , 1 == b ? ( a . classList . add ( "active" ) , a . setAttribute ( "aria-pressed" , "true" ) ) : ( a . classList . remove ( "active" ) , a . setAttribute ( "aria-pressed" , "false" ) ) }
2018-07-03 21:46:07 +00:00
function parseSettings ( a ) { toggleBtn ( "btnRandom" , a . data . random ) ; toggleBtn ( "btnConsume" , a . data . consume ) ; toggleBtn ( "btnSingle" , a . data . single ) ; toggleBtn ( "btnRepeat" , a . data . repeat ) ; void 0 != a . data . crossfade ? ( document . getElementById ( "inputCrossfade" ) . removeAttribute ( "disabled" ) , document . getElementById ( "inputCrossfade" ) . value = a . data . crossfade ) : document . getElementById ( "inputCrossfade" ) . setAttribute ( "disabled" , "disabled" ) ; void 0 != a . data . mixrampdb ? ( document . getElementById ( "inputMixrampdb" ) . removeAttribute ( "disabled" ) ,
document . getElementById ( "inputMixrampdb" ) . value = a . data . mixrampdb ) : document . getElementById ( "inputMixrampdb" ) . setAttribute ( "disabled" , "disabled" ) ; void 0 != a . data . mixrampdelay ? ( document . getElementById ( "inputMixrampdelay" ) . removeAttribute ( "disabled" ) , document . getElementById ( "inputMixrampdelay" ) . value = a . data . mixrampdelay ) : document . getElementById ( "inputMixrampdelay" ) . setAttribute ( "disabled" , "disabled" ) ; document . getElementById ( "selectReplaygain" ) . value = a . data . replaygain ; var b = document . getElementById ( "btnnotifyWeb" ) ;
notificationsSupported ( ) ? a . data . notificationWeb ? ( toggleBtn ( "btnnotifyWeb" , a . data . notificationWeb ) , Notification . requestPermission ( function ( b ) { "permission" in Notification || ( Notification . permission = b ) ; "granted" === b ? toggleBtn ( "btnnotifyWeb" , 1 ) : ( toggleBtn ( "btnnotifyWeb" , 0 ) , a . data . notificationWeb = 0 ) } ) ) : toggleBtn ( "btnnotifyWeb" , 0 ) : ( b . setAttribute ( "disabled" , "disabled" ) , toggleBtn ( "btnnotifyWeb" , 0 ) ) ; toggleBtn ( "btnnotifyPage" , a . data . notificationPage ) ; settings = a . data ; settings . mpdstream = "http://" ; settings . mpdstream =
"127.0.0.1" == settings . mpdhost || "localhost" == settings . mpdhost ? settings . mpdstream + window . location . hostname : settings . mpdstream + settings . mpdhost ; settings . mpdstream += ":" + settings . streamport + "/" } function getSettings ( ) { sendAPI ( { cmd : "MPD_API_GET_SETTINGS" } , parseSettings ) }
function parseOutputnames ( a ) { for ( var b = "" , c = a . data . outputs . length , e = 0 ; e < c ; e ++ ) b += '<button id="btnoutput' + a . data . outputs [ e ] . id + '" data-output-id="' + a . data . outputs [ e ] . id + '" class="btn btn-secondary btn-block"><span class="material-icons float-left">volume_up</span> ' + a . data . outputs [ e ] . name + "</button>" ; domCache . outputs . innerHTML = b }
function parseState ( a ) { if ( JSON . stringify ( a ) !== JSON . stringify ( last _state ) ) { 1 == a . data . state ? ( domCache . btnPlay . innerText = "play_arrow" , playstate = "stop" ) : 2 == a . data . state ? ( domCache . btnPlay . innerText = "pause" , playstate = "play" ) : ( domCache . btnPlay . innerText = "play_arrow" , playstate = "pause" ) ; - 1 == a . data . nextsongpos ? domCache . btnNext . setAttribute ( "disabled" , "disabled" ) : domCache . btnNext . removeAttribute ( "disabled" ) ; 0 >= a . data . songpos ? domCache . btnPrev . setAttribute ( "disabled" , "disabled" ) : domCache . btnPrev . removeAttribute ( "disabled" ) ;
0 == a . data . queue _length ? domCache . btnPlay . setAttribute ( "disabled" , "disabled" ) : domCache . btnPlay . removeAttribute ( "disabled" ) ; - 1 == a . data . volume ? ( domCache . volumePrct . innerText ( "Volumecontrol disabled" ) , domCache . volumeControl . classList . add ( "hide" ) ) : ( domCache . volumeControl . classList . remove ( "hide" ) , domCache . volumePrct . innerText = a . data . volume + " %" , domCache . volumeIcon . innerText = 0 == a . data . volume ? "volume_off" : 50 > a . data . volume ? "volume_down" : "volume_up" ) ; domCache . volumeBar . value = a . data . volume ; current _song . totalTime =
a . data . totalTime ; current _song . currentSongId = a . data . currentsongid ; var b = Math . floor ( a . data . totalTime / 60 ) , c = a . data . totalTime - 60 * b , e = Math . floor ( a . data . elapsedTime / 60 ) , d = a . data . elapsedTime - 60 * e ; domCache . progressBar . value = Math . floor ( 100 * a . data . elapsedTime / a . data . totalTime ) ; b = e + ":" + ( 10 > d ? "0" : "" ) + d + " / " + b + ":" + ( 10 > c ? "0" : "" ) + c ; domCache . counter . innerText = b ; last _state && ( c = document . getElementById ( "queueTrackId" + last _state . data . currentsongid ) ) && ( e = c . getElementsByTagName ( "td" ) , e [ 4 ] . innerText = c . getAttribute ( "data-duration" ) ,
e [ 0 ] . classList . remove ( "material-icons" ) , e [ 0 ] . innerText = c . getAttribute ( "data-songpos" ) , c . classList . remove ( "font-weight-bold" ) ) ; if ( c = document . getElementById ( "queueTrackId" + a . data . currentsongid ) ) e = c . getElementsByTagName ( "td" ) , e [ 4 ] . innerText = b , e [ 0 ] . classList . add ( "material-icons" ) , e [ 0 ] . innerText = "play_arrow" , c . classList . add ( "font-weight-bold" ) ; void 0 != last _state && a . data . queue _version == last _state . data . queue _version || sendAPI ( { cmd : "MPD_API_GET_CURRENT_SONG" } , songChange ) ; b = a . data . outputs . length ; for ( c = 0 ; c <
2018-07-16 20:56:56 +00:00
b ; c ++ ) toggleBtn ( "btnoutput" + a . data . outputs [ c ] . id , a . data . outputs [ c ] . state ) ; last _state = a } } function getQueue ( ) { 2 <= app . current . search . length ? sendAPI ( { cmd : "MPD_API_SEARCH_QUEUE" , data : { mpdtag : app . current . filter , offset : app . current . page , searchstr : app . current . search } } , parseQueue ) : sendAPI ( { cmd : "MPD_API_GET_QUEUE" , data : { offset : app . current . page } } , parseQueue ) }
2018-07-15 22:26:59 +00:00
function parseQueue ( a ) { if ( "Queue" === app . current . app ) { 0 < a . totalTime ? document . getElementById ( "panel-heading-queue" ) . innerText = a . totalEntities + " Songs \u2013 " + beautifyDuration ( a . totalTime ) : 0 < a . totalEntities ? document . getElementById ( "panel-heading-queue" ) . innerText = a . totalEntities + " Songs" : document . getElementById ( "panel-heading-queue" ) . innerText = "" ; var b = a . data . length , c = document . getElementById ( app . current . app + "List" ) ; c . setAttribute ( "data-version" , a . queue _version ) ; c = c . getElementsByTagName ( "tbody" ) [ 0 ] ;
for ( var e = c . getElementsByTagName ( "tr" ) , d = 0 ; d < b ; d ++ ) if ( ! e [ d ] || e [ d ] . getAttribute ( "data-trackid" ) != a . data [ d ] . id ) { var f = Math . floor ( a . data [ d ] . duration / 60 ) , g = a . data [ d ] . duration - 60 * f ; f = f + ":" + ( 10 > g ? "0" : "" ) + g ; g = document . createElement ( "tr" ) ; g . setAttribute ( "data-trackid" , a . data [ d ] . id ) ; g . setAttribute ( "id" , "queueTrackId" + a . data [ d ] . id ) ; g . setAttribute ( "data-songpos" , a . data [ d ] . pos + 1 ) ; g . setAttribute ( "data-duration" , f ) ; g . setAttribute ( "data-uri" , a . data [ d ] . uri ) ; g . innerHTML = "<td>" + ( a . data [ d ] . pos + 1 ) + "</td><td>" + a . data [ d ] . title +
"</td><td>" + a . data [ d ] . artist + "</td><td>" + a . data [ d ] . album + "</td><td>" + f + '</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>' ; d < e . length ? e [ d ] . replaceWith ( g ) : c . append ( g ) } for ( d = e . length - 1 ; d >= b ; d -- ) e [ d ] . remove ( ) ; "queuesearch" == a . type && 0 == b ? c . innerHTML = '<tr><td><span class="material-icons">error_outline</span></td><td colspan="5">No results, please refine your search!</td></tr>' : "queue" == a . type && 0 == b && ( c . innerHTML = '<tr><td><span class="material-icons">error_outline</span></td><td colspan="5">Empty queue</td></tr>' ) ;
setPagination ( a . totalEntities ) ; document . getElementById ( "QueueList" ) . classList . remove ( "opacity05" ) } } function parseSearch ( a ) { "Search" === app . current . app && ( document . getElementById ( "panel-heading-search" ) . innerHTML = a . totalEntities + " Songs found" , 0 < a . totalEntities ? document . getElementById ( "searchAddAllSongs" ) . removeAttribute ( "disabled" ) : document . getElementById ( "searchAddAllSongs" ) . setAttribute ( "disabled" , "disabled" ) , parseFilesystem ( a ) ) }
2018-07-09 19:20:09 +00:00
function parseFilesystem ( a ) { if ( "Browse" === app . current . app || "Filesystem" === app . current . tab || "Search" === app . current . app ) { for ( var b = a . data . length , c = document . getElementById ( app . current . app + ( void 0 == app . current . tab ? "" : app . current . tab ) + "List" ) . getElementsByTagName ( "tbody" ) [ 0 ] , e = c . getElementsByTagName ( "tr" ) , d = 0 ; d < b ; d ++ ) { var f = encodeURI ( a . data [ d ] . uri ) ; if ( ! e [ d ] || e [ d ] . getAttribute ( "data-uri" ) != f ) { var g = document . createElement ( "tr" ) ; g . setAttribute ( "data-type" , a . data [ d ] . type ) ; g . setAttribute ( "data-uri" , f ) ; g . setAttribute ( "data-name" ,
a . data [ d ] . name ) ; switch ( a . data [ d ] . type ) { case "dir" : g . innerHTML = '<td><span class="material-icons">folder_open</span></td><td colspan="4">' + a . data [ d ] . name + '</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>' ; break ; case "song" : f = Math . floor ( a . data [ d ] . duration / 60 ) ; var h = a . data [ d ] . duration - 60 * f ; g . innerHTML = '<td><span class="material-icons">music_note</span></td><td>' + a . data [ d ] . title + "</td><td>" + a . data [ d ] . artist + "</td><td>" + a . data [ d ] . album + "</td><td>" + f + ":" + ( 10 > h ? "0" : "" ) + h + '</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>' ;
break ; case "plist" : g . innerHTML = '<td><span class="material-icons">list</span></td><td colspan="4">' + a . data [ d ] . name + '</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>' } d < e . length ? e [ d ] . replaceWith ( g ) : c . append ( g ) } } for ( d = e . length - 1 ; d >= b ; d -- ) e [ d ] . remove ( ) ; setPagination ( a . totalEntities ) ; 0 == b && ( c . innerHTML = '<tr><td><span class="material-icons">error_outline</span></td><td colspan="5">No results</td></tr>' ) ; document . getElementById ( app . current . app + ( void 0 == app . current . tab ? "" :
2018-07-05 22:02:14 +00:00
app . current . tab ) + "List" ) . classList . remove ( "opacity05" ) } }
2018-07-09 19:20:09 +00:00
function parsePlaylists ( a ) { if ( "Browse" === app . current . app || "Playlists" === app . current . tab ) { for ( var b = a . data . length , c = document . getElementById ( app . current . app + app . current . tab + "List" ) . getElementsByTagName ( "tbody" ) [ 0 ] , e = c . getElementsByTagName ( "tr" ) , d = 0 ; d < b ; d ++ ) { var f = encodeURI ( a . data [ d ] . uri ) ; if ( ! e [ d ] || e [ d ] . getAttribute ( "data-uri" ) != f ) { var g = new Date ( 1E3 * a . data [ d ] . last _modified ) , h = document . createElement ( "tr" ) ; h . setAttribute ( "data-uri" , f ) ; h . setAttribute ( "data-type" , "plist" ) ; h . setAttribute ( "data-name" , a . data [ d ] . name ) ;
h . innerHTML = '<td><span class="material-icons">list</span></td><td>' + a . data [ d ] . name + "</td><td>" + g . toUTCString ( ) + '</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>' ; d < e . length ? e [ d ] . replaceWith ( h ) : c . append ( h ) } } for ( d = e . length - 1 ; d >= b ; d -- ) e [ d ] . remove ( ) ; setPagination ( a . totalEntities ) ; 0 == b && ( c . innerHTML = '<tr><td><span class="material-icons">error_outline</span></td><td colspan="5">No playlists found.</td></tr>' ) ; document . getElementById ( app . current . app + ( void 0 == app . current . tab ?
2018-07-05 22:02:14 +00:00
"" : app . current . tab ) + "List" ) . classList . remove ( "opacity05" ) } }
2018-07-03 21:46:07 +00:00
function parseListDBtags ( a ) { if ( "Browse" === app . current . app || "Database" === app . current . tab || "Artist" === app . current . view ) if ( "AlbumArtist" == a . tagtype ) { document . getElementById ( "BrowseDatabaseAlbumCards" ) . classList . add ( "hide" ) ; document . getElementById ( "BrowseDatabaseArtistList" ) . classList . remove ( "hide" ) ; document . getElementById ( "btnBrowseDatabaseArtist" ) . classList . add ( "hide" ) ; for ( var b = a . data . length , c = document . getElementById ( app . current . app + app . current . tab + app . current . view + "List" ) . getElementsByTagName ( "tbody" ) [ 0 ] ,
2018-07-09 19:20:09 +00:00
e = c . getElementsByTagName ( "tr" ) , d = 0 ; d < b ; d ++ ) { var f = encodeURI ( a . data [ d ] . value ) ; if ( ! e [ d ] || e [ d ] . getAttribute ( "data-uri" ) != f ) { var g = document . createElement ( "tr" ) ; g . setAttribute ( "data-uri" , f ) ; g . innerHTML = '<td><span class="material-icons">album</span></td><td>' + a . data [ d ] . value + "</td>" ; d < e . length ? e [ d ] . replaceWith ( g ) : c . append ( g ) } } for ( d = e . length - 1 ; d >= b ; d -- ) e [ d ] . remove ( ) ; setPagination ( a . totalEntities ) ; 0 == b && ( c . innerHTML = '<tr><td><span class="material-icons">error_outline</span></td><td colspan="5">No entries found.</td></tr>' ) ;
document . getElementById ( "BrowseDatabaseArtistList" ) . classList . remove ( "opacity05" ) } else if ( "Album" == a . tagtype ) { document . getElementById ( "BrowseDatabaseAlbumCards" ) . classList . remove ( "hide" ) ; document . getElementById ( "BrowseDatabaseArtistList" ) . classList . add ( "hide" ) ; document . getElementById ( "btnBrowseDatabaseArtist" ) . classList . remove ( "hide" ) ; b = a . data . length ; c = document . getElementById ( "BrowseDatabaseAlbumCards" ) ; e = c . querySelectorAll ( ".col-md" ) ; for ( d = 0 ; d < b ; d ++ ) f = genId ( a . data [ d ] . value ) , e [ d ] && e [ d ] . getAttribute ( "id" ) ==
f || ( g = document . createElement ( "div" ) , g . classList . add ( "col-md" ) , g . classList . add ( "mr-0" ) , g . setAttribute ( "id" , f ) , g . innerHTML = '<div class="card mb-4" id="card' + f + '"> <a href="#" class="card-img-top"><img class="card-img-top" src="" ></a> <div class="card-body"> <h5 class="card-title">' + a . searchstr + '</h5> <h4 class="card-title">' + a . data [ d ] . value + '</h4> <table class="table table-sm table-hover" id="tbl' + f + '"><tbody></tbody></table </div></div>' , d < e . length ? e [ d ] . replaceWith ( g ) : c . append ( g ) , sendAPI ( { cmd : "MPD_API_GET_ARTISTALBUMTITLES" ,
2018-07-05 22:02:14 +00:00
data : { albumartist : a . searchstr , album : a . data [ d ] . value } } , parseListTitles ) ) ; for ( d = e . length - 1 ; d >= b ; d -- ) e [ d ] . remove ( ) ; setPagination ( a . totalEntities ) ; document . getElementById ( "BrowseDatabaseAlbumCards" ) . classList . remove ( "opacity05" ) } }
2018-07-09 19:20:09 +00:00
function parseListTitles ( a ) { if ( "Browse" === app . current . app || "Database" === app . current . tab || "Album" === app . current . view ) { var b = genId ( a . album ) , c = document . getElementById ( "card" + b ) ; b = c . getElementsByTagName ( "tbody" ) [ 0 ] ; var e = c . getElementsByTagName ( "img" ) [ 0 ] ; c = e . parentNode ; e . setAttribute ( "src" , a . cover ) ; c . setAttribute ( "data-uri" , encodeURI ( a . data [ 0 ] . uri . replace ( /\/[^\/]+$/ , "" ) ) ) ; c . setAttribute ( "data-name" , a . album ) ; c . setAttribute ( "data-type" , "dir" ) ; e = "" ; for ( var d = a . data . length , f = 0 ; f < d ; f ++ ) e += '<tr data-type="song" data-name="' +
a . data [ f ] . title + '" data-uri="' + encodeURI ( a . data [ f ] . uri ) + '"><td>' + a . data [ f ] . track + "</td><td>" + a . data [ f ] . title + '</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td></tr>' ; b . innerHTML = e ; c . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ; showMenu ( this ) } , ! 1 ) ; b . parentNode . addEventListener ( "click" , function ( a ) { "TD" == a . target . nodeName ? appendQueue ( "song" , decodeURI ( a . target . parentNode . getAttribute ( "data-uri" ) ) , a . target . parentNode . getAttribute ( "data-name" ) ) : "A" == a . target . nodeName &&
2018-07-05 22:02:14 +00:00
( a . preventDefault ( ) , showMenu ( a . target ) ) } , ! 1 ) } }
2018-07-09 19:20:09 +00:00
function setPagination ( a ) { var b = Math . ceil ( a / settings . max _elements _per _page ) , c = app . current . app + ( void 0 == app . current . tab ? "" : app . current . tab ) ; 0 == b && ( b = 1 ) ; for ( var e = [ "PaginationTop" , "PaginationBottom" ] , d = 0 ; 2 > d ; d ++ ) { document . getElementById ( c + e [ d ] + "Page" ) . innerText = app . current . page / settings . max _elements _per _page + 1 + " / " + b ; if ( 1 < b ) { document . getElementById ( c + e [ d ] + "Page" ) . removeAttribute ( "disabled" ) ; for ( var f = "" , g = 0 ; g < b ; g ++ ) f += '<button data-page="' + g * settings . max _elements _per _page + '" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">' +
( g + 1 ) + "</button>" ; document . getElementById ( c + e [ d ] + "Pages" ) . innerHTML = f } else document . getElementById ( c + e [ d ] + "Page" ) . setAttribute ( "disabled" , "disabled" ) ; a > app . current . page + settings . max _elements _per _page ? ( document . getElementById ( c + e [ d ] + "Next" ) . removeAttribute ( "disabled" ) , document . getElementById ( c + "ButtonsBottom" ) . classList . remove ( "hide" ) ) : ( document . getElementById ( c + e [ d ] + "Next" ) . setAttribute ( "disabled" , "disabled" ) , document . getElementById ( c + "ButtonsBottom" ) . classList . add ( "hide" ) ) ; 0 < app . current . page ? ( document . getElementById ( c +
2018-07-05 20:23:44 +00:00
e [ d ] + "Prev" ) . removeAttribute ( "disabled" ) , document . getElementById ( c + "ButtonsBottom" ) . classList . remove ( "hide" ) ) : document . getElementById ( c + e [ d ] + "Prev" ) . setAttribute ( "disabled" , "disabled" ) } }
function appendQueue ( a , b , c ) { switch ( a ) { case "song" : sendAPI ( { cmd : "MPD_API_ADD_TRACK" , data : { uri : b } } ) ; showNotification ( '"' + c + '" added' , "" , "" , "success" ) ; break ; case "dir" : sendAPI ( { cmd : "MPD_API_ADD_TRACK" , data : { uri : b } } ) ; showNotification ( '"' + c + '" added' , "" , "" , "success" ) ; break ; case "plist" : sendAPI ( { cmd : "MPD_API_ADD_PLAYLIST" , data : { plist : b } } ) , showNotification ( '"' + c + '" added' , "" , "" , "success" ) } }
function appendAfterQueue ( a , b , c , e ) { switch ( a ) { case "song" : sendAPI ( { cmd : "MPD_API_ADD_TRACK_AFTER" , data : { uri : b , to : c } } ) ; showNotification ( '"' + e + '" added to pos ' + c , "" , "" , "success" ) ; break ; case "dir" : sendAPI ( { cmd : "MPD_API_ADD_TRACK_AFTER" , data : { uri : b , to : c } } ) , showNotification ( '"' + e + '" added to pos ' + c , "" , "" , "success" ) } }
function replaceQueue ( a , b , c ) { switch ( a ) { case "song" : sendAPI ( { cmd : "MPD_API_REPLACE_TRACK" , data : { uri : b } } ) ; showNotification ( '"' + c + '" replaced' , "" , "" , "success" ) ; break ; case "dir" : sendAPI ( { cmd : "MPD_API_REPLACE_TRACK" , data : { uri : b } } ) ; showNotification ( '"' + c + '" replaced' , "" , "" , "success" ) ; break ; case "plist" : sendAPI ( { cmd : "MPD_API_REPLACE_PLAYLIST" , data : { plist : b } } ) , showNotification ( '"' + c + '" replaced' , "" , "" , "success" ) } }
2018-07-09 19:20:09 +00:00
function songDetails ( a ) { sendAPI ( { cmd : "MPD_API_GET_SONGDETAILS" , data : { uri : a } } , parseSongDetails ) ; modalSongDetails . show ( ) }
function parseSongDetails ( a ) { var b = document . getElementById ( "modalSongDetails" ) ; b . querySelector ( ".album-cover" ) . style . backgroundImage = 'url("' + a . data . cover + '")' ; b . getElementsByTagName ( "h1" ) [ 0 ] . innerText = a . data . title ; b = b . getElementsByTagName ( "tr" ) ; for ( var c = b . length , e = 0 ; e < c ; e ++ ) { var d = b [ e ] . getAttribute ( "data-name" ) , f = a . data [ d ] ; "duration" == d ? ( d = Math . floor ( f / 60 ) , f -= 60 * d , f = d + ":" + ( 10 > f ? "0" : "" ) + f ) : "uri" == d && ( f = '<a class="text-success" href="/library/' + f + '">' + f + "</a>" ) ; b [ e ] . getElementsByTagName ( "td" ) [ 1 ] . innerHTML =
f } }
function showMenu ( a ) { var b = a . getAttribute ( "data-type" ) , c = decodeURI ( a . getAttribute ( "data-uri" ) ) , e = a . getAttribute ( "data-name" ) ; if ( null == b || null == c ) b = a . parentNode . parentNode . getAttribute ( "data-type" ) , c = decodeURI ( a . parentNode . parentNode . getAttribute ( "data-uri" ) ) , e = a . parentNode . parentNode . getAttribute ( "data-name" ) ; var d = "" ; "Browse" == app . current . app && "Filesystem" == app . current . tab || "Search" == app . current . app || "Browse" == app . current . app && "Database" == app . current . tab && "Album" == app . current . view ? d += "<a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'appendQueue', 'options': ['" + b +
2018-07-18 21:54:26 +00:00
"','" + c + "','" + e + "']}\">Append to queue</a>" + ( "song" == b ? "<a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'appendAfterQueue', 'options': ['" + b + "','" + c + "'," + last _state . data . nextsongpos + ",'" + e + "']}\">Add after current playing song</a>" : "" ) + "<a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'replaceQueue', 'options': ['" + b + "','" + c + "','" + e + "']}\">Replace queue</a>" + ( "dir" != b ? '<div class="dropdown-divider"></div>' : "" ) + ( "song" == b ? "<a class=\"dropdown-item\" data-href=\"{'cmd': 'songDetails', 'options': ['" +
2018-07-09 19:20:09 +00:00
c + '\']}" href="#">Songdetails</a>' : "" ) : "Browse" == app . current . app && "Playlists" == app . current . tab ? d += "<a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'appendQueue', 'options': ['" + b + "','" + c + "','" + e + "']}\">Append to queue</a><a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'replaceQueue', 'options': ['" + b + "','" + c + "','" + e + "']}\">Replace queue</a><div class=\"dropdown-divider\"></div><a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'delPlaylist', 'options': ['" + c + "','" + e + "']}\">Delete playlist</a>" :
"Queue" == app . current . app && ( d += "<a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'delQueueSong', 'options': ['single'," + a . parentNode . parentNode . getAttribute ( "data-trackid" ) + "]}\">Remove</a><a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'delQueueSong', 'options': ['range',0," + a . parentNode . parentNode . getAttribute ( "data-songpos" ) + "]}\">Remove all upwards</a><a class=\"dropdown-item\" href=\"#\" data-href=\"{'cmd': 'delQueueSong', 'options': ['range'," + ( parseInt ( a . parentNode . parentNode . getAttribute ( "data-songpos" ) ) -
1 ) + ",-1]}\">Remove all downwards</a><div class=\"dropdown-divider\"></div><a class=\"dropdown-item\" data-href=\"{'cmd': 'songDetails', 'options': ['" + c + '\']}" href="#">Songdetails</a>' ) ; void 0 == a . Popover && ( new Popover ( a , { trigger : "click" , template : '<div class="popover" role="tooltip"><div class="arrow"></div><div class="popover-content">' + d + "</div></div>" } ) , b = a . Popover , a . addEventListener ( "shown.bs.popover" , function ( a ) { document . querySelector ( ".popover-content" ) . addEventListener ( "click" , function ( a ) { a . preventDefault ( ) ;
a . stopPropagation ( ) ; a = JSON . parse ( a . target . getAttribute ( "data-href" ) . replace ( /'/g , '"' ) ) ; if ( "function" === typeof window [ a . cmd ] ) switch ( a . cmd ) { case "sendAPI" : sendAPI . apply ( null , $jscomp . arrayFromIterable ( a . options ) ) ; break ; default : window [ a . cmd ] . apply ( null , $jscomp . arrayFromIterable ( a . options ) ) } } , ! 1 ) } , ! 1 ) , b . show ( ) ) }
2018-07-05 22:02:14 +00:00
function sendAPI ( a , b ) { var c = new XMLHttpRequest ; c . open ( "POST" , "/api" , ! 0 ) ; c . setRequestHeader ( "Content-type" , "application/json" ) ; c . onreadystatechange = function ( ) { 4 == c . readyState && void 0 != b && "function" == typeof b && "" != c . responseText && b ( JSON . parse ( c . responseText ) ) } ; c . send ( JSON . stringify ( a ) ) } function openLocalPlayer ( ) { window . open ( "/player.html#" + settings . mpdstream , "LocalPlayer" ) } function updateDB ( ) { sendAPI ( { cmd : "MPD_API_UPDATE_DB" } ) ; showNotification ( "Updating MPD Database..." , "" , "" , "success" ) }
function clickPlay ( ) { "play" != playstate ? sendAPI ( { cmd : "MPD_API_SET_PLAY" } ) : sendAPI ( { cmd : "MPD_API_SET_PAUSE" } ) } function clickStop ( ) { sendAPI ( { cmd : "MPD_API_SET_STOP" } ) } function clickPrev ( ) { sendAPI ( { cmd : "MPD_API_SET_PREV" } ) } function clickNext ( ) { sendAPI ( { cmd : "MPD_API_SET_NEXT" } ) } function delQueueSong ( a , b , c ) { "range" == a ? sendAPI ( { cmd : "MPD_API_RM_RANGE" , data : { start : b , end : c } } ) : "single" == a && sendAPI ( { cmd : "MPD_API_RM_TRACK" , data : { track : b } } ) }
function delPlaylist ( a , b ) { sendAPI ( { cmd : "MPD_API_RM_PLAYLIST" , data : { plist : a } } ) ; document . getElementById ( "BrowsePlaylistsList" ) . querySelector ( "tr[data-uri=" + encodeURI ( a ) + "]" ) . remove ( ) }
2018-07-03 21:46:07 +00:00
function confirmSettings ( ) { var a = ! 0 , b = document . getElementById ( "inputCrossfade" ) ; if ( ! b . getAttribute ( "disabled" ) ) { var c = parseInt ( b . value ) ; isNaN ( c ) ? ( b . classList . add ( "is-invalid" ) , a = ! 1 ) : b . value = c } b = document . getElementById ( "inputMixrampdb" ) ; b . getAttribute ( "disabled" ) || ( c = parseFloat ( b . value ) , isNaN ( c ) ? ( b . classList . add ( "is-invalid" ) , a = ! 1 ) : b . value = c ) ; b = document . getElementById ( "inputMixrampdelay" ) ; b . getAttribute ( "disabled" ) || ( "nan" == b . value && ( b . value = "-1" ) , c = parseFloat ( b . value ) , isNaN ( c ) ? ( b . classList . add ( "is-invalid" ) ,
a = ! 1 ) : b . value = c ) ; 1 == a ? ( a = document . getElementById ( "selectReplaygain" ) , sendAPI ( { cmd : "MPD_API_SET_SETTINGS" , data : { consume : document . getElementById ( "btnConsume" ) . classList . contains ( "active" ) ? 1 : 0 , random : document . getElementById ( "btnRandom" ) . classList . contains ( "active" ) ? 1 : 0 , single : document . getElementById ( "btnSingle" ) . classList . contains ( "active" ) ? 1 : 0 , repeat : document . getElementById ( "btnRepeat" ) . classList . contains ( "active" ) ? 1 : 0 , replaygain : a . options [ a . selectedIndex ] . value , crossfade : document . getElementById ( "inputCrossfade" ) . value ,
mixrampdb : document . getElementById ( "inputMixrampdb" ) . value , mixrampdelay : document . getElementById ( "inputMixrampdelay" ) . vaue , notificationWeb : document . getElementById ( "btnnotifyWeb" ) . classList . contains ( "active" ) ? 1 : 0 , notificationPage : document . getElementById ( "btnnotifyPage" ) . classList . contains ( "active" ) ? 1 : 0 } } , getSettings ) , modalSettings . hide ( ) ) : document . getElementById ( "settingsFrm" ) . classList . add ( "was-validated" ) }
2018-07-05 20:23:44 +00:00
function addAllFromBrowse ( ) { sendAPI ( { cmd : "MPD_API_ADD_TRACK" , data : { uri : app . current . search } } ) ; showNotification ( "Added all songs" , "" , "" , "success" ) } function addAllFromSearch ( ) { 2 <= app . current . search . length && ( sendAPI ( { cmd : "MPD_API_SEARCH_ADD" , data : { filter : app . current . filter , searchstr : app . current . search } } ) , showNotification ( "Added " + parseInt ( document . getElementById ( "panel-heading-search" ) . innerText ) + " songs from search" , "" , "" , "success" ) ) }
2018-07-09 19:20:09 +00:00
function scrollTo ( a ) { document . body . scrollTop = a ; document . documentElement . scrollTop = a } function gotoPage ( a ) { switch ( a ) { case "next" : app . current . page += settings . max _elements _per _page ; break ; case "prev" : app . current . page -= settings . max _elements _per _page ; 0 >= app . current . page && ( app . current . page = 0 ) ; break ; default : app . current . page = a } appGoto ( app . current . app , app . current . tab , app . current . view , app . current . page + "/" + app . current . filter + "/" + app . current . search ) }
2018-07-03 21:46:07 +00:00
function addStream ( ) { var a = document . getElementById ( "streamurl" ) ; "" != a . value && sendAPI ( { cmd : "MPD_API_ADD_TRACK" , data : { uri : a . value } } ) ; a . value = "" ; modalAddstream . hide ( ) } function saveQueue ( ) { var a = document . getElementById ( "playlistname" ) ; "" != a . value && sendAPI ( { cmd : "MPD_API_SAVE_QUEUE" , data : { plist : a . value } } ) ; a . value = "" ; modalSavequeue . hide ( ) }
2018-07-15 22:26:59 +00:00
function showNotification ( a , b , c , e ) { 1 == settings . notificationWeb && ( b = new Notification ( a , { icon : "assets/favicon.ico" , body : b } ) , setTimeout ( function ( a ) { a . close ( ) } , 3E3 , b ) ) ; 1 == settings . notificationPage && ( document . getElementById ( "alertBox" ) ? b = document . getElementById ( "alertBox" ) : ( b = document . createElement ( "div" ) , b . setAttribute ( "id" , "alertBox" ) , b . addEventListener ( "click" , function ( ) { hideNotification ( ) } , ! 1 ) ) , b . classList . add ( "alert" , "alert-" + e ) , b . innerHTML = "<div><strong>" + a + "</strong>" + c + "</div>" , document . getElementsByTagName ( "main" ) [ 0 ] . append ( b ) ,
document . getElementById ( "alertBox" ) . classList . add ( "alertBoxActive" ) , alertTimeout && clearTimeout ( alertTimeout ) , alertTimeout = setTimeout ( function ( ) { hideNotification ( ) } , 3E3 ) ) } function hideNotification ( ) { document . getElementById ( "alertBox" ) && ( document . getElementById ( "alertBox" ) . classList . remove ( "alertBoxActive" ) , setTimeout ( function ( ) { document . getElementById ( "alertBox" ) . remove ( ) } , 600 ) ) } function notificationsSupported ( ) { return "Notification" in window }
2018-07-18 21:54:26 +00:00
function songChange ( a ) { if ( "error" != a . type ) { var b = a . data . title + a . data . artist + a . data . album + a . data . uri + a . data . currentsongid ; if ( last _song != b ) { var c = "" , e = "" , d = "myMPD: " ; document . getElementById ( "album-cover" ) . style . backgroundImage = 'url("' + a . data . cover + '")' ; "undefined" != typeof a . data . artist && 0 < a . data . artist . length && "-" != a . data . artist ? ( c += a . data . artist , e += "<br/>" + a . data . artist , d += a . data . artist + " - " , document . getElementById ( "artist" ) . innerText = a . data . artist ) : document . getElementById ( "artist" ) . innerText = "" ;
"undefined" != typeof a . data . album && 0 < a . data . album . length && "-" != a . data . album ? ( c += " - " + a . data . album , e += "<br/>" + a . data . album , document . getElementById ( "album" ) . innerText = a . data . album ) : document . getElementById ( "album" ) . innerText = "" ; "undefined" != typeof a . data . title && 0 < a . data . title . length ? ( d += a . data . title , document . getElementById ( "currenttrack" ) . innerText = a . data . title ) : document . getElementById ( "currenttrack" ) . innerText = "" ; document . title = d ; if ( d = document . getElementById ( "queueTrackId" + a . data . currentsongid ) ) d . getElementsByTagName ( "td" ) [ 1 ] . innerText =
a . data . title ; showNotification ( a . data . title , c , e , "success" ) ; last _song = b } } } function doSetFilterLetter ( a ) { var b = document . getElementById ( a + "Letters" ) . querySelector ( ".active" ) ; b && b . classList . remove ( "active" ) ; b = app . current . filter ; "0" == b && ( b = "#" ) ; document . getElementById ( a ) . innerText = "Filter" + ( "-" != b ? ": " + b : "" ) ; if ( "-" != b ) { a = document . getElementById ( a + "Letters" ) . getElementsByTagName ( "button" ) ; for ( var c = a . length , e = 0 ; e < c ; e ++ ) if ( a [ e ] . innerText == b ) { a [ e ] . classList . add ( "active" ) ; break } } }
2018-07-03 21:46:07 +00:00
function addFilterLetter ( a ) { var b = '<button class="mr-1 mb-1 btn btn-sm btn-secondary material-icons material-icons-small">delete</button><button class="mr-1 mb-1 btn btn-sm btn-secondary">#</button>' ; for ( i = 65 ; 90 >= i ; i ++ ) b += '<button class="mr-1 mb-1 btn-sm btn btn-secondary">' + String . fromCharCode ( i ) + "</button>" ; a = document . getElementById ( a ) ; a . innerHTML = b ; a . addEventListener ( "click" , function ( a ) { switch ( a . target . innerText ) { case "delete" : b = "-" ; break ; case "#" : b = "0" ; break ; default : b = a . target . innerText } appGoto ( app . current . app ,
app . current . tab , app . current . view , "0/" + b + "/" + app . current . search ) } , ! 1 ) } function chVolume ( a ) { a = parseInt ( domCache . volumeBar . value ) + a ; 0 > a ? a = 0 : 100 < a && ( a = 100 ) ; domCache . volumeBar . value = a ; sendAPI ( { cmd : "MPD_API_SET_VOLUME" , data : { volume : a } } ) } function beautifyDuration ( a ) { var b = Math . floor ( a / 86400 ) , c = Math . floor ( a / 3600 ) - 24 * b , e = Math . floor ( a / 60 ) - 60 * c - 1440 * b ; a = a - 86400 * b - 3600 * c - 60 * e ; return ( 0 < b ? b + "\u2009d " : "" ) + ( 0 < c ? c + "\u2009h " + ( 10 > e ? "0" : "" ) : "" ) + e + "\u2009m " + ( 10 > a ? "0" : "" ) + a + "\u2009s" }
function genId ( a ) { return "id" + a . replace ( /[^\w]/g , "" ) } appInit ( ) ;