2020-12-29 09:53:15 +00:00
|
|
|
const char HTTP_SCRIPT_CONSOL[] PROGMEM =
|
2021-02-23 18:07:56 +00:00
|
|
|
"var sn=0,id=0,ft,ltm=%d;" // Scroll position, Get most of weblog initially
|
2020-12-31 10:47:37 +00:00
|
|
|
"function l(p){" // Console log and command service
|
2020-12-31 12:31:22 +00:00
|
|
|
"var c,o='';"
|
2020-12-31 10:47:37 +00:00
|
|
|
"clearTimeout(lt);"
|
2020-12-31 12:31:22 +00:00
|
|
|
"clearTimeout(ft);"
|
2020-12-31 10:47:37 +00:00
|
|
|
"t=eb('t1');"
|
|
|
|
"if(p==1){"
|
|
|
|
"c=eb('c1');" // Console command id
|
|
|
|
"o='&c1='+encodeURIComponent(c.value);"
|
|
|
|
"c.value='';"
|
2022-04-03 11:34:43 +01:00
|
|
|
"t.scrollTop=1e8;"
|
2020-12-31 10:47:37 +00:00
|
|
|
"sn=t.scrollTop;"
|
2020-12-29 09:53:15 +00:00
|
|
|
"}"
|
2020-12-31 10:47:37 +00:00
|
|
|
"if(t.scrollTop>=sn){" // User scrolled back so no updates
|
|
|
|
"if(x!=null){x.abort();}" // Abort if no response within 2 seconds (happens on restart 1)
|
|
|
|
"x=new XMLHttpRequest();"
|
2022-04-03 11:30:07 +01:00
|
|
|
"x.onreadystatechange=()=>{"
|
2020-12-31 10:47:37 +00:00
|
|
|
"if(x.readyState==4&&x.status==200){"
|
|
|
|
"var z,d;"
|
|
|
|
"d=x.responseText.split(/}1/);" // Field separator
|
|
|
|
"id=d.shift();"
|
|
|
|
"if(d.shift()==0){t.value='';}"
|
|
|
|
"z=d.shift();"
|
|
|
|
"if(z.length>0){t.value+=z;}"
|
2022-04-03 11:34:43 +01:00
|
|
|
"t.scrollTop=1e8;"
|
2020-12-31 10:47:37 +00:00
|
|
|
"sn=t.scrollTop;"
|
2020-12-31 12:31:22 +00:00
|
|
|
"clearTimeout(ft);"
|
2021-02-23 18:07:56 +00:00
|
|
|
"lt=setTimeout(l,ltm);" // webrefresh timer....
|
2020-12-31 10:47:37 +00:00
|
|
|
"}"
|
|
|
|
"};"
|
|
|
|
"x.open('GET','cs?c2='+id+o,true);" // Related to Webserver->hasArg("c2") and WebGetArg("c2", stmp, sizeof(stmp))
|
|
|
|
"x.send();"
|
2022-04-03 11:34:43 +01:00
|
|
|
"ft=setTimeout(l,2e4);" // fail timeout, triggered 20s after asking for XHR
|
2021-02-23 18:07:56 +00:00
|
|
|
"}else{"
|
|
|
|
"lt=setTimeout(l,ltm);" // webrefresh timer....
|
2020-12-30 12:52:16 +00:00
|
|
|
"}"
|
2020-12-31 10:47:37 +00:00
|
|
|
"return false;"
|
|
|
|
"}"
|
|
|
|
"wl(l);" // Load initial console text
|
|
|
|
|
|
|
|
// Console command history
|
|
|
|
"var hc=[],cn=0;" // hc = History commands, cn = Number of history being shown
|
|
|
|
"function h(){"
|
|
|
|
// "if(!(navigator.maxTouchPoints||'ontouchstart'in document.documentElement)){eb('c1').autocomplete='off';}" // No touch so stop browser autocomplete
|
2022-04-03 11:30:07 +01:00
|
|
|
"eb('c1').addEventListener('keydown',e=>{"
|
2020-12-31 10:47:37 +00:00
|
|
|
"var b=eb('c1'),c=e.keyCode;" // c1 = Console command id
|
2022-04-03 05:22:00 +01:00
|
|
|
"if(38==c||40==c){" // ArrowUp or ArrowDown
|
|
|
|
"b.autocomplete='off';" // ArrowUp or ArrowDown must be a keyboard so stop browser autocomplete
|
2022-04-03 09:16:55 +01:00
|
|
|
"setTimeout(b=>{" // for best compatibility (chrome) we need to schedule this function
|
2022-04-03 05:22:00 +01:00
|
|
|
"b.focus();" // for best compatibility (chrome) we need to (re)focus the input element
|
2022-04-03 09:56:54 +01:00
|
|
|
"b.setSelectionRange(1e9,1e9)" // move cursor to the end (hopefully) of the command inserted from history
|
|
|
|
"},0,b)"
|
2022-04-03 05:22:00 +01:00
|
|
|
"}"
|
2020-12-31 10:47:37 +00:00
|
|
|
"38==c?(++cn>hc.length&&(cn=hc.length),b.value=hc[cn-1]||''):" // ArrowUp
|
|
|
|
"40==c?(0>--cn&&(cn=0),b.value=hc[cn-1]||''):" // ArrowDown
|
|
|
|
"13==c&&(hc.length>19&&hc.pop(),hc.unshift(b.value),cn=0)" // Enter, 19 = Max number -1 of commands in history
|
|
|
|
"});"
|
|
|
|
"}"
|
|
|
|
"wl(h);"; // Add console command key eventlistener after name has been synced with id (= wl(jd))
|
2022-03-09 09:32:47 +00:00
|
|
|
|