',a+='
",e?$(r).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 e="#"+t.name+"-"+o.longopts,r=bn(n,t.name,o.longopts);o.checkbox?$(e)[0].checked=r:(void 0!==r&&$(e).val(r).trigger("change"),0===$(e)[0].value.length&&(o.datatype||"").includes("|")&&($(e)[0].value="--"))}))}))})).fail((function(n,t,o){I(n,0,o),$("#commands-list").empty(),O=!1}))}function fn(){$.getJSON("/config.json",(function(n){$("#nvsTable tr").remove();var t=n.config?n.config:n;P=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 e=/-o\s?(["][^"]*["]|[^-]+)/g.exec(o);e[1].toUpperCase().startsWith("I2S")?C("i2s"):e[1].toUpperCase().startsWith("SPDIF")?C("spdif"):e[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,V=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),O=!1}))}function un(n,t){hn({message:n,type:t},new Date)}function hn(n,t){var o="table-success";"MESSAGING_WARNING"===n.type?(o="table-warning","MESSAGING_INFO"===U&&(U="MESSAGING_WARNING")):"MESSAGING_ERROR"===n.type&&("MESSAGING_INFO"!==U&&"MESSAGING_WARNING"!==U||(U="MESSAGING_ERROR"),o="table-danger"),++D>0&&($("#msgcnt").removeClass("badge-success"),$("#msgcnt").removeClass("badge-warning"),$("#msgcnt").removeClass("badge-danger"),$("#msgcnt").addClass(k[U]),$("#msgcnt").text(D)),$("#syslogTable").append("
"+t.toLocalShort()+" | "+n.message.encodeHTML()+" |
")}function xn(n,t,o){return(n-t)*(n-o)<=0}function vn(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,e){setTimeout((function(){e(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"===Q?(t+=' -o "BT" -R -Z 192000',N("cfg-audio-tmpl","MESSAGING_INFO","Remember to configure the Bluetooth audio device name.\n",!0)):t+="spdif"===Q?" -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&&en(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}),tn()},$(document).ready((function(){setTimeout(an,1500),$("#WifiConnectDialog").on("shown.bs.modal",(function(){$("*[class*='connecting']").hide(),W.Action!==nn?($(".connecting-init").show(),$("#manual_ssid").trigger("focus")):cn()})),$("#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(){D=0,U="MESSAGING_INFO",$("#msgcnt").text(""),$("#syslogTable").html("")})),$("#wifiTable").on("click","tr",(function(){W.Action=K,$(this).children("td:eq(1)").text()!=q.ssid?$(this).is(":last-child")?(W.Action=X,W.ssid="",$("#manual_ssid").val(W.ssid)):(W.ssid=$(this).children("td:eq(1)").text(),$("#manual_ssid").val(W.ssid)):W.Action=nn})),$("#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=on(!0),t=document.createElement("a");t.href=URL.createObjectURL(new Blob([JSON.stringify(n,null,2)],{type:"text/plain"})),t.setAttribute("download","nvs_config_"+V+"_"+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=on(!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?un(o.responseText,"MESSAGING_INFO"):0===o.status?un("Upload connection was closed abruptly!","MESSAGING_ERROR"):un(o.status+" Error!\n"+o.responseText,"MESSAGING_ERROR"))},o.open("POST","/flash.json",!0),o.send(t)}L=!0})),$("#flash").on("click",(function(){var n={timestamp:Date.now()};if(!B){B=!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}),L=!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,e=[];n.forEach((function(n){var t=n.name.split("#")[3];e.includes(t)||e.push(t)})),e.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 e=n.name.split("#"),r=e[0],a=e[1],i=e[2],l=e[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("
"+r+" | "+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(){L=!0})),$("#reboot-button").on("click",(function(){L=!0})),$("#updateAP").on("click",(function(){an(),console.log("refresh AP")})),fn(),gn(),tn()})),window.setURL=function(n){var t=n.dataset.url;$('[data-url^="http"]').addClass("btn-success").removeClass("btn-danger"),$('[data-url="'+t+'"]').addClass("btn-danger").removeClass("btn-success"),_&&(t=t.replace(/.*\/download\//,_+"/plugins/SqueezeESP32/firmware/")),$("#fwurl").val(t)},window.runCommand=function(n,t){var o=n.attributes.cmdname.value;N(n.attributes.cmdname.value,"MESSAGING_INFO","Executing.",!1);var e=document.getElementById("flds-"+o);if(o+=" ",e)for(var r=e.querySelectorAll("select,input"),a=0;a