Advertisement
plirof2

pack_js_footer - breaktime mod03 240117c

Jan 18th, 2024 (edited)
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //pack_js_footer : get as parameter string like "HHMM"
  2.  
  3. * v240117 - refreshtimeXXYY : Now I can put refreshtime09:15 to reload at 09:15
  4.  
  5. //-------------------reload at specific times 240117 + 231011a --START-------------
  6.     var btime = hh + mm;
  7.     refreshAt(btime);
  8. }
  9.  
  10.  
  11. //https://stackoverflow.com/questions/1217929/how-to-automatically-reload-a-web-page-at-a-certain-time
  12. /*
  13. *
  14. * refreshAtHHMM("0335"); //Will refresh the page at 3:35pm
  15. *
  16. * To do: add refreshAt() for all breaks and execute them if activated from pack_refresh_browser().
  17. * The check can be done inside probeserver. It might need a global variable for break1 ,break2 etc "activated" of "completed"
  18. *
  19. */
  20. var refreshbreak1set=false;
  21. var refreshbreak2set=false;
  22. refreshbreak3set=false;
  23. var refreshbreak4set=false;
  24. var refreshbreak5set=false;
  25. var refreshbreak6set=false;
  26. function refreshAtHHMM(breaktime) {
  27.       // Remove colons from breaktime
  28.     breaktime = breaktime.replace(/:/g, '');
  29.     var hours = breaktime.substring(0, 2);
  30.     var minutes = breaktime.substring(2, 4);
  31.     var seconds = "00";
  32.  
  33.  
  34.     var now = new Date();
  35.     var then = new Date();
  36.  
  37.     if(now.getHours() > hours ||
  38.        (now.getHours() == hours && now.getMinutes() > minutes) ||
  39.         now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
  40.         then.setDate(now.getDate() + 1);
  41.     }
  42.     then.setHours(hours);
  43.     then.setMinutes(minutes);
  44.     then.setSeconds(seconds);
  45.     console.log("refreshAt:"+hours+minutes+seconds)
  46.     var timeout = (then.getTime() - now.getTime());
  47.     setTimeout(function() { window.location.reload(true); }, timeout);
  48. }
  49.  
  50. //-------------------reload at specific times --END-------------
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. >>>>>>>>>inside probeserver code :
  58.  
  59.             // +++++++++++++++++++=refreshtimeXXYY++++++++++++++++++++++
  60.             if (response_string.indexOf("refreshtime") !== -1) {
  61.               var startIndex = response_string.indexOf("refreshtime") + 11; // Start index after "refreshtime"
  62.               var endIndex = response_string.indexOf(":", startIndex); // Index of ":" after XX
  63.               var refreshTime;
  64.              
  65.               if (endIndex !== -1) {
  66.                 // Case: refreshtimeXX:YY
  67.                 refreshTime = response_string.substring(startIndex, endIndex) + response_string.substring(endIndex + 1);
  68.               } else {
  69.                 // Case: refreshtimeXXYY
  70.                 refreshTime = response_string.substring(startIndex);
  71.               }
  72.               //console.log("RefreshTime="+refreshTime);
  73.               refreshAtHHMM(refreshTime);
  74.             }
  75.             //-----------------------refreshtimeXX:YY END----------------------
  76.  
  77.             if (response_string.indexOf("breakrefresh") !== -1) {
  78.                 var s=response_string;              
  79.                 //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
  80.                 //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
  81.                 //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line                
  82.                 //var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line    
  83.                 console.log("refreshbreak---");    
  84.                 if ((response_string.indexOf("breakrefresh2")!== -1) && !refreshbreak2set ) {console.log("refreshbreak2");  refreshAt(9,"02",0); refreshbreak2set=true; }      
  85.                 if ((response_string.indexOf("breakrefresh3")!== -1) && !refreshbreak3set ) {console.log("refreshbreak3");  refreshAt(9,42,0); refreshbreak3set=true; }      
  86.                 if ((response_string.indexOf("breakrefresh4")!== -1) && !refreshbreak4set ) {console.log("refreshbreak4");  refreshAt(10,47,0); refreshbreak4set=true; }      
  87.                 if ((response_string.indexOf("breakrefresh5")!== -1) && !refreshbreak5set ) {console.log("refreshbreak5");  refreshAt(11,33,0); refreshbreak5set=true; }
  88.        
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement