mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-25 07:17:16 +00:00

Applied to main menu and Console menu. Fixes times when commands are issued from Web Console, but get the XHR gets cancelled after the default 2.345s webrefresh time.
48 lines
1.6 KiB
C
48 lines
1.6 KiB
C
const char HTTP_SCRIPT_ROOT[] PROGMEM =
|
|
"let rfsh=1,ft;"
|
|
"function la(p){"
|
|
"a=p||'';"
|
|
"clearTimeout(ft);clearTimeout(lt);"
|
|
"if(x!=null){x.abort();}" // Abort if no response within 2 seconds (happens on restart 1)
|
|
"x=new XMLHttpRequest();"
|
|
"x.onreadystatechange=function(){"
|
|
"if(x.readyState==4&&x.status==200){"
|
|
"var s=x.responseText.replace(/{t}/g,\"<table style='width:100%%'>\")"
|
|
".replace(/{s}/g,\"<tr><th>\")"
|
|
// ".replace(/{m}/g,\"</th><td>\")"
|
|
".replace(/{m}/g,\"</th><td style='width:20px;white-space:nowrap'>\")" // I want a right justified column with left justified text
|
|
".replace(/{e}/g,\"</td></tr>\")"
|
|
".replace(/{c}/g,\"%%'><div style='text-align:center;font-weight:\");"
|
|
"eb('l1').innerHTML=s;"
|
|
"clearTimeout(ft);clearTimeout(lt);"
|
|
"if(rfsh){"
|
|
"lt=setTimeout(la,%d);" // Settings.web_refresh
|
|
"}"
|
|
"}"
|
|
"};"
|
|
"if(rfsh){"
|
|
"x.open('GET','.?m=1'+a,true);" // ?m related to Webserver->hasArg("m")
|
|
"x.send();"
|
|
"ft=setTimeout(la,20000);" // 20s failure timeout
|
|
"}"
|
|
"}"
|
|
"function seva(par,ivar){"
|
|
"la('&sv='+ivar+'_'+par);"
|
|
"}"
|
|
"function siva(par,ivar){"
|
|
"rfsh=1;"
|
|
"la('&sv='+ivar+'_'+par);"
|
|
"rfsh=0;"
|
|
"}"
|
|
"function pr(f){"
|
|
"if(f){"
|
|
"clearTimeout(lt);clearTimeout(ft);"
|
|
"lt=setTimeout(la,%d);"
|
|
"rfsh=1;"
|
|
"}else{"
|
|
"clearTimeout(lt);clearTimeout(ft);"
|
|
"rfsh=0;"
|
|
"}"
|
|
"}"
|
|
;
|