mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-11 21:55:48 +00:00
fix that strange bug where reefreshing on config page was moving back to index... very annoying, it should be fixed sooner. Also fix statusOK test for Windows
This commit is contained in:
@ -721,7 +721,7 @@ const char htmlHeadStyle[] = "<style>div,fieldset,input,select{padding:5px;font-
|
||||
//region_end htmlHeadStyle
|
||||
|
||||
//region_start pageScript
|
||||
const char pageScript[] = "<script type='text/javascript'>var firstTime,lastTime,onlineFor,req=null,onlineForEl=null,getElement=e=>document.getElementById(e);function showState(){clearTimeout(firstTime),clearTimeout(lastTime),null!=req&&req.abort(),(req=new XMLHttpRequest).onreadystatechange=()=>{var e;4==req.readyState&&200==req.status&&((\"INPUT\"!=document.activeElement.tagName||\"number\"!=document.activeElement.type&&\"color\"!=document.activeElement.type)&&(e=getElement(\"state\"))&&(e.innerHTML=req.responseText),clearTimeout(firstTime),clearTimeout(lastTime),lastTime=setTimeout(showState,3e3))},req.open(\"GET\",\"index?state=1\",!0),req.send(),firstTime=setTimeout(showState,3e3)}function fmtUpTime(e){var t,n,o=Math.floor(e/86400);return e%=86400,t=Math.floor(e/3600),e%=3600,n=Math.floor(e/60),e=e%60,0<o?o+` days, ${t} hours, ${n} minutes and ${e} seconds`:0<t?t+` hours, ${n} minutes and ${e} seconds`:0<n?n+` minutes and ${e} seconds`:`just ${e} seconds`}function updateOnlineFor(){onlineForEl.textContent=fmtUpTime(++onlineFor)}function onLoad(){(onlineForEl=getElement(\"onlineFor\"))&&(onlineFor=parseInt(onlineForEl.dataset.initial,10))&&setInterval(updateOnlineFor,1e3),showState()}function submitTemperature(e){var t=getElement(\"form132\");getElement(\"kelvin132\").value=Math.round(1e6/parseInt(e.value)),t.submit()}window.addEventListener(\"load\",onLoad),history.pushState(null,\"\",\"index\"),setTimeout(()=>{var e=getElement(\"changed\");e&&(e.innerHTML=\"\")},5e3);</script>";
|
||||
const char pageScript[] = "<script type='text/javascript'>var firstTime,lastTime,onlineFor,req=null,onlineForEl=null,getElement=e=>document.getElementById(e);function showState(){clearTimeout(firstTime),clearTimeout(lastTime),null!=req&&req.abort(),(req=new XMLHttpRequest).onreadystatechange=()=>{var e; 4==req.readyState&&'OK'==req.statusText&&((\"INPUT\"!=document.activeElement.tagName||\"number\"!=document.activeElement.type&&\"color\"!=document.activeElement.type)&&(e=getElement(\"state\"))&&(e.innerHTML=req.responseText),clearTimeout(firstTime),clearTimeout(lastTime),lastTime=setTimeout(showState,3e3))},req.open(\"GET\",\"index?state=1\",!0),req.send(),firstTime=setTimeout(showState,3e3)}function fmtUpTime(e){var t,n,o=Math.floor(e/86400);return e%=86400,t=Math.floor(e/3600),e%=3600,n=Math.floor(e/60),e=e%60,0<o?o+` days, ${t} hours, ${n} minutes and ${e} seconds`:0<t?t+` hours, ${n} minutes and ${e} seconds`:0<n?n+` minutes and ${e} seconds`:`just ${e} seconds`}function updateOnlineFor(){onlineForEl.textContent=fmtUpTime(++onlineFor)}function onLoad(){(onlineForEl=getElement(\"onlineFor\"))&&(onlineFor=parseInt(onlineForEl.dataset.initial,10))&&setInterval(updateOnlineFor,1e3),showState()}function submitTemperature(e){var t=getElement(\"form132\");getElement(\"kelvin132\").value=Math.round(1e6/parseInt(e.value)),t.submit()}window.addEventListener(\"load\",onLoad),history.pushState(null,\"\",window.location.pathname.slice(1)),setTimeout(()=>{var e=getElement(\"changed\");e&&(e.innerHTML=\"\")},5e3);</script>";
|
||||
//region_end pageScript
|
||||
|
||||
//region_start ha_discovery_script
|
||||
|
||||
@ -17,7 +17,8 @@ function showState() {
|
||||
}
|
||||
req = new XMLHttpRequest();
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState == 4 && req.status == 200) {
|
||||
// somehow status was 0 on Windows, but "OK" works on both Beken and Windows
|
||||
if (req.readyState == 4 && req.statusText == "OK") {
|
||||
if (
|
||||
!(
|
||||
document.activeElement.tagName == "INPUT" &&
|
||||
@ -85,7 +86,8 @@ function submitTemperature(slider) {
|
||||
}
|
||||
|
||||
window.addEventListener("load", onLoad);
|
||||
history.pushState(null, "", "index"); // drop actions like 'toggle' from URL
|
||||
// I have modified below to use slice on window.location instead of hardcoded index because it was breaking "back" function of web page
|
||||
history.pushState(null, "", window.location.pathname.slice(1)); // drop actions like 'toggle' from URL
|
||||
|
||||
setTimeout(() => {
|
||||
var changedEl = getElement("changed");
|
||||
|
||||
Reference in New Issue
Block a user