',a+='
",r?$(e).append(a):$("#commands-list").append(a)}})),n.commands.forEach((function(t){$("[cmdname="+t.name+"]:input").val(""),$("[cmdname="+t.name+"]:checkbox").prop("checked",!1),t.argtable&&t.argtable.forEach((function(o){var r="#"+t.name+"-"+o.longopts,e=pn(n,t.name,o.longopts);o.checkbox?$(r)[0].checked=e:(void 0!==e&&$(r).val(e).trigger("change"),0===$(r)[0].value.length&&(o.datatype||"").includes("|")&&($(r)[0].value="--"))}))}))})).fail((function(n,t,o){I(n,0,o),$("#commands-list").empty(),L=!1}))}function gn(){$.getJSON("/config.json",(function(n){$("#nvsTable tr").remove();var t=n.config?n.config:n;Y=t,Object.keys(t).sort().forEach((function(n){var o=t[n].value;if("autoexec"===n)"0"===t.autoexec.value?$("#disable-squeezelite")[0].checked=!0:$("#disable-squeezelite")[0].checked=!1;else if("autoexec1"===n){var r=/-o\s?(["][^"]*["]|[^-]+)/g.exec(o);r[1].toUpperCase().startsWith("I2S")?C("i2s"):r[1].toUpperCase().startsWith("SPDIF")?C("spdif"):r[1].toUpperCase().startsWith('"BT')&&C("bt")}else"host_name"===n&&(o=o.replaceAll('"',""),$("input#dhcp-name1").val(o),$("input#dhcp-name2").val(o),$("#player").val(o),document.title=o,Q=o);$("tbody#nvsTable").append("
"+n+" | |
"),$("input#"+n).val(t[n].value)})),$("tbody#nvsTable").append("
| |
"),n.gpio&&($("tbody#gpiotable tr").remove(),n.gpio.forEach((function(n){$("tbody#gpiotable").append("
'+n.group+" | "+n.name+" | "+n.gpio+" | "+(n.fixed?"Fixed":"Configuration")+" |
---|
")})))})).fail((function(n,t,o){I(n,0,o),L=!1}))}function fn(n,t){un({message:n,type:t},new Date)}function un(n,t){var o="table-success";"MESSAGING_WARNING"===n.type?(o="table-warning","MESSAGING_INFO"===D&&(D="MESSAGING_WARNING")):"MESSAGING_ERROR"===n.type&&("MESSAGING_INFO"!==D&&"MESSAGING_WARNING"!==D||(D="MESSAGING_ERROR"),o="table-danger"),++B>0&&($("#msgcnt").removeClass("badge-success"),$("#msgcnt").removeClass("badge-warning"),$("#msgcnt").removeClass("badge-danger"),$("#msgcnt").addClass(k[D]),$("#msgcnt").text(B)),$("#syslogTable").append("
"+t.toLocalShort()+" | "+n.message.encodeHTML()+" |
")}function hn(n,t,o){return(n-t)*(n-o)<=0}function xn(n){return new m.Promise((function(t){return setTimeout(t,n)}))}m.Promise.prototype.delay=function(n){return this.then((function(t){return new m.Promise((function(o){setTimeout((function(){o(t)}),n)}))}),(function(t){return new m.Promise((function(o,r){setTimeout((function(){r(t)}),n)}))}))},window.saveAutoexec1=function(n){N("cfg-audio-tmpl","MESSAGING_INFO","Saving.\n",!1);var t='squeezelite -b 500:2000 -d all=info -C 30 -W -n "'+$("#player").val()+'"';"bt"===P?(t+=' -o "BT" -R -Z 192000',N("cfg-audio-tmpl","MESSAGING_INFO","Remember to configure the Bluetooth audio device name.\n",!0)):t+="spdif"===P?" -o SPDIF -Z 192000":" -o I2S",""!==$("#optional").val()&&(t+=" "+$("#optional").val());var o={timestamp:Date.now()};o.config={autoexec1:{value:t,type:33},autoexec:{value:$("#disable-squeezelite").prop("checked")?"0":"1",type:33}},$.ajax({url:"/config.json",dataType:"text",method:"POST",cache:!1,contentType:"application/json; charset=utf-8",data:JSON.stringify(o),error:I,complete:function(t){t.responseText.result&&"OK"===JSON.parse(t.responseText).result?(N("cfg-audio-tmpl","MESSAGING_INFO","Done.\n",!0),n&&on(1500,"cfg-audio-tmpl")):t.responseText.result?N("cfg-audio-tmpl","MESSAGING_WARNING",JSON.parse(t.responseText).Result+"\n",!0):N("cfg-audio-tmpl","MESSAGING_ERROR",t.statusText+"\n"),console.log(t.responseText)}}),console.log("sent data:",JSON.stringify(o))},window.handleDisconnect=function(){$.ajax({url:"/connect.json",dataType:"text",method:"DELETE",cache:!1,contentType:"application/json; charset=utf-8",data:JSON.stringify({timestamp:Date.now()})})},window.handleConnect=function(){W.ssid=$("#manual_ssid").val(),W.pwd=$("#manual_pwd").val(),W.dhcpname=$("#dhcp-name2").val(),$("*[class*='connecting']").hide(),$("#ssid-wait").text(W.ssid),$(".connecting").show(),$.ajax({url:"/connect.json",dataType:"text",method:"POST",cache:!1,contentType:"application/json; charset=utf-8",data:JSON.stringify({timestamp:Date.now(),ssid:W.ssid,pwd:W.pwd}),error:I}),nn()},$(document).ready((function(){setTimeout(en,1500),$("#WifiConnectDialog").on("shown.bs.modal",(function(){$("*[class*='connecting']").hide(),W.Action!==X?($(".connecting-init").show(),$("#manual_ssid").trigger("focus")):mn()})),$("#WifiConnectDialog").on("hidden.bs.modal",(function(){$("#WifiConnectDialog input").val("")})),$("input#show-commands")[0].checked=1===J,$('a[href^="#tab-commands"]').hide(),$("#load-nvs").on("click",(function(){$("#nvsfilename").trigger("click")})),$("#clear-syslog").on("click",(function(){B=0,D="MESSAGING_INFO",$("#msgcnt").text(""),$("#syslogTable").html("")})),$("#wifiTable").on("click","tr",(function(){W.Action=q,$(this).children("td:eq(1)").text()!=Z.ssid?$(this).is(":last-child")?(W.Action=K,W.ssid="",$("#manual_ssid").val(W.ssid)):(W.ssid=$(this).children("td:eq(1)").text(),$("#manual_ssid").val(W.ssid)):W.Action=X})),$("#ok-credits").on("click",(function(){$("#credits").slideUp("fast",(function(){})),$("#app").slideDown("fast",(function(){}))})),$("#acredits").on("click",(function(n){n.preventDefault(),$("#app").slideUp("fast",(function(){})),$("#credits").slideDown("fast",(function(){}))})),$("input#show-commands").on("click",(function(){this.checked=this.checked?1:0,this.checked?($('a[href^="#tab-commands"]').show(),J=1):(J=0,$('a[href^="#tab-commands"]').hide())})),$("input#show-nvs").on("click",(function(){this.checked=this.checked?1:0,this.checked?$('*[href*="-nvs"]').show():$('*[href*="-nvs"]').hide()})),$("#save-as-nvs").on("click",(function(){var n=tn(!0),t=document.createElement("a");t.href=URL.createObjectURL(new Blob([JSON.stringify(n,null,2)],{type:"text/plain"})),t.setAttribute("download","nvs_config_"+Q+"_"+Date.now()+"json"),document.body.appendChild(t),t.click(),document.body.removeChild(t)})),$("#save-nvs").on("click",(function(){var n={},t={timestamp:Date.now()},o=tn(!1);t.config=o,$.ajax({url:"/config.json",dataType:"text",method:"POST",cache:!1,headers:n,contentType:"application/json; charset=utf-8",data:JSON.stringify(t),error:I}),console.log("sent config JSON with headers:",JSON.stringify(n)),console.log("sent config JSON with data:",JSON.stringify(t))})),$("#fwUpload").on("click",(function(){T||($("#flash-status").text("Rebooting to recovery. Please try again"),window.handleReboot(!1));var n=document.getElementById("flashfilename").files;if(0===n.length)alert("No file selected!");else{var t=n[0],o=new XMLHttpRequest;o.onreadystatechange=function(){4===o.readyState&&(200===o.status?fn(o.responseText,"MESSAGING_INFO"):0===o.status?fn("Upload connection was closed abruptly!","MESSAGING_ERROR"):fn(o.status+" Error!\n"+o.responseText,"MESSAGING_ERROR"))},o.open("POST","/flash.json",!0),o.send(t)}_=!0})),$("#flash").on("click",(function(){var n={timestamp:Date.now()};if(!O){O=!0;var t=$("#fwurl").val();n.config={fwurl:{value:t,type:33}},$.ajax({url:"/config.json",dataType:"text",method:"POST",cache:!1,contentType:"application/json; charset=utf-8",data:JSON.stringify(n),error:I}),_=!0}})),$("[name=output-tmpl]").on("click",(function(){C(this.id)})),$("#fwcheck").on("click",(function(){$("#releaseTable").html(""),$("#fwbranch").empty(),$.getJSON("https://api.github.com/repos/sle118/squeezelite-esp32/releases",(function(n){var t,o=0,r=[];n.forEach((function(n){var t=n.name.split("#")[3];r.includes(t)||r.push(t)})),r.forEach((function(n){t+='
"})),$("#fwbranch").append(t),n.forEach((function(n){var t="";n.assets.forEach((function(n){n.name.match(/\.bin$/)&&(t=n.browser_download_url)}));var r=n.name.split("#"),e=r[0],a=r[1],i=r[2],l=r[3],d=n.body;d=(d=(d=d.replace(/'/gi,'"')).replace(/[\s\S]+(### Revision Log[\s\S]+)### ESP-IDF Version Used[\s\S]+/,"$1")).replace(/- \(.+?\) /g,"- ");var m=o++>6?" hide":"";$("#releaseTable").append("
"+e+" | "+new Date(n.created_at).toLocalShort()+" | "+i+" | "+a+" | "+l+" | |
")})),o>7&&($("#releaseTable").append("
|
"),$("#showallbutton").on("click",(function(){$("tr.hide").removeClass("hide"),$("tr#showall").addClass("hide")}))),$("#searchfw").css("display","inline")})).fail((function(){alert("failed to fetch release history!")}))})),$("input#searchinput").on("input",(function(){var n=$("input#searchinput").val(),t=new RegExp(n,"gi");0===n.length?$("tr.release").removeClass("hide"):n.length<3?$("tr.release").addClass("hide"):($("tr.release").addClass("hide"),$("tr.release").each((function(){$(this).find("td").each((function(){$(this).html().match(t)&&$(this).parent().removeClass("hide")}))})))})),$("#fwbranch").on("change",(function(){var n=this.value,t=new RegExp("^"+n+"$","gi");$("tr.release").addClass("hide"),$("tr.release").each((function(){$(this).find("td").each((function(){console.log($(this).html()),$(this).html().match(t)&&$(this).parent().removeClass("hide")}))}))})),$("#boot-button").on("click",(function(){_=!0})),$("#reboot-button").on("click",(function(){_=!0})),$("#updateAP").on("click",(function(){en(),console.log("refresh AP")})),gn(),bn(),nn()})),window.setURL=function(n){var t=n.dataset.url;$("#fwurl").val(t),$('[data-url^="http"]').addClass("btn-success").removeClass("btn-danger"),$('[data-url="'+t+'"]').addClass("btn-danger").removeClass("btn-success")},window.runCommand=function(n,t){var o=n.attributes.cmdname.value;N(n.attributes.cmdname.value,"MESSAGING_INFO","Executing.",!1);var r=document.getElementById("flds-"+o);if(o+=" ",r)for(var e=r.querySelectorAll("select,input"),a=0;a