Advertisement
plirof2

pack_js_footer231031b.js refreshbreak002

Oct 12th, 2023 (edited)
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //<script type="text/javascript">
  2. /*
  3. * pack_js_footer  (put this in same folder as parent html)
  4. *
  5. *
  6. * Changes:
  7. * ver231031 - breakrefresh# fix error in IF checks
  8. * ver231011 - breakrefresh# reload at specific times start
  9. * ver201025b - eval (pack_refresh_browser.txt) execute commands dynamic (requires probeserver activated) (not implemented yet)
  10. * ver201020c -norightclick -disable right click : eg http://192.168.1.200/tinymce_class/tinymce_template_form.html?file=temp_test01&norightclick
  11. * ver190411 -noopengame (initial ver) (removes opengame -in case we run a plain Http server with no PHP)
  12. * ver190410 -opengame (initial ver)
  13. * ver190404 -showdiv
  14. * ver190402 -all scripts are now in footer
  15. *
  16. * example : index.html?showdiv5\&timer3\&probeserver ,
  17. */
  18.  
  19.     var first_click=true;
  20.     var url_time_param=location.search.substring(1).indexOf("time");
  21.     // (((((((((((((((((((  preset timers (((((((((((((((((((
  22.     var additional_wait_time=0;
  23.     var url_timer2=location.search.substring(1).indexOf("timer2");
  24.     var url_timer3=location.search.substring(1).indexOf("timer3");
  25.     var url_timer4=location.search.substring(1).indexOf("timer4");
  26.     var url_timer5=location.search.substring(1).indexOf("timer5");
  27.     var url_timer6=location.search.substring(1).indexOf("timer6");
  28.     var url_timer7=location.search.substring(1).indexOf("timer7");
  29.  
  30.     if (url_timer2!==-1)additional_wait_time= -3;
  31.     if (url_timer3!==-1)additional_wait_time= -2;
  32.     if (url_timer4!==-1)additional_wait_time= -1;
  33.     if (url_timer5!==-1)additional_wait_time= 0;
  34.     if (url_timer6!==-1)additional_wait_time= 1;
  35.     if (url_timer7!==-1)additional_wait_time= 2;
  36.     var additional_wait_minutes=additional_wait_time*1000*60;
  37.     // ))))))))))))))))  preset timers )))))))))))))))))))))))
  38.  
  39.     // (((((((((((((((((((  option to show only specific DIV (((((((((((((((((((
  40.     var url_showdiv_param=location.search.substring(1).indexOf("showdiv");// != to -1 if we have this param
  41.     var url_showdiv1=location.search.substring(1).indexOf("showdiv1");
  42.     var url_showdiv2=location.search.substring(1).indexOf("showdiv2");
  43.     var url_showdiv3=location.search.substring(1).indexOf("showdiv3");
  44.     var url_showdiv4=location.search.substring(1).indexOf("showdiv4");
  45.     var url_showdiv5=location.search.substring(1).indexOf("showdiv5");
  46.     var url_showdiv6=location.search.substring(1).indexOf("showdiv6");
  47.     var url_showdiv7=location.search.substring(1).indexOf("showdiv7");
  48.     // ))))))))))))))))  option to show only specific DIV  )))))))))))))))))))))))
  49.  
  50.     var url_opengame=location.search.substring(1).indexOf("opengame"); //check if we want opengame as prefix to all urls
  51.     var url_noopengame=location.search.substring(1).indexOf("noopengame"); //check if we DO NOT want opengame as prefix to all urls (for PHPless web servers)
  52.  
  53.  
  54. //if we find a parameter that contains word "time" (eg packA01.html?timer) then we hide all the other links
  55. function init_links(){
  56.  
  57.     if((url_showdiv_param!==-1 ) && (url_time_param==-1 ) ){  //disable show_url IF we have set timer
  58.         //if((url_showdiv1==-1) && (url_time_param==-1 )) document.getElementById("div1").style.visibility = "hidden";
  59.         if(url_showdiv1==-1) document.getElementById("div1").style.visibility = "hidden";
  60.         if(url_showdiv2==-1) document.getElementById("div2").style.visibility = "hidden";
  61.         if(url_showdiv3==-1) document.getElementById("div3").style.visibility = "hidden";
  62.         if(url_showdiv4==-1) document.getElementById("div4").style.visibility = "hidden";
  63.         if(url_showdiv5==-1) document.getElementById("div5").style.visibility = "hidden";
  64.         if(url_showdiv6==-1) document.getElementById("div6").style.visibility = "hidden";
  65.         if(url_showdiv7==-1) document.getElementById("div7").style.visibility = "hidden";    
  66.     }    
  67.  
  68.     //If we have a timer URL param then HIDE divs
  69.     if(url_time_param!==-1 ) {
  70.         document.getElementById("div2").style.visibility = "hidden";
  71.         document.getElementById("div3").style.visibility = "hidden";
  72.         document.getElementById("div4").style.visibility = "hidden";
  73.         document.getElementById("div5").style.visibility = "hidden";
  74.         document.getElementById("div6").style.visibility = "hidden";
  75.         document.getElementById("div7").style.visibility = "hidden";
  76.         //document.getElementById("div6").style.visibility = "hidden";        
  77.     }
  78.  
  79.  
  80. // (((((((((((((((((((((((((( option to disable right click v201020c ((((((((((
  81.     var url_norightclick=location.search.substring(1).indexOf("norightclick");// != to -1 if we have this param
  82.     if(url_norightclick!==-1) {
  83.         document.oncontextmenu=new Function("console.log('main page: right-click-context menu -STOPPED');return false") ; //OK normal page Works  
  84.         setInterval(function(){window.frames["sideframe1"].document.oncontextmenu = function(){console.log("setInterval sideframe1 :right click-DISABLED"); return false;}; }, 5000);
  85.     }
  86. // )))))))))))))))))))))))))) option to disable right click ))))))))
  87.  
  88. } // end of function init_links(){
  89.  
  90. function showItTimer() {
  91.     //enable if its 1st click AND we have a timer UTL param
  92.     if(first_click && url_time_param !==-1 ) {
  93.         //alert("first_timer=true   , "+"location.search.substring(1)="+location.search.substring(1));
  94.         //if(location.search.substring(1)>0)  alert("location.search.substring(1)="+location.search.substring(1));
  95.         var minute=1000*60;
  96.         console.log("first click , timers set every :");
  97.         console.log((5*minute + additional_wait_minutes)/60/1000);
  98.             //############ TEST ###################
  99.             setTimeout(function(){document.getElementById("div2").style.visibility = "visible"}, 2000);//test
  100.             setTimeout(function(){document.getElementById("div2").style.visibility = "hidden"}, 5000);//test
  101.  
  102.             setTimeout(function(){document.getElementById("div4").style.visibility = "visible"}, minute/60);//test
  103.             setTimeout(function(){document.getElementById("div4").style.visibility = "hidden"}, 3000);//test
  104.             // ########### TEST #####################
  105.         setTimeout(function(){document.getElementById("div2").style.visibility = "visible"}, 5*minute+additional_wait_minutes);
  106.         setTimeout(function(){document.getElementById("div3").style.visibility = "visible"}, 10*minute+additional_wait_minutes);
  107.         setTimeout(function(){document.getElementById("div4").style.visibility = "visible"}, 15*minute+additional_wait_minutes);
  108.         setTimeout(function(){document.getElementById("div5").style.visibility = "visible"}, 20*minute+additional_wait_minutes);
  109.         setTimeout(function(){document.getElementById("div6").style.visibility = "visible"}, 25*minute+additional_wait_minutes);
  110.         setTimeout(function(){document.getElementById("div7").style.visibility = "visible"}, 26*minute+additional_wait_minutes);
  111.  
  112.        
  113.     }
  114.     first_click=false;
  115.  
  116.     return false;
  117. } // end of showItTimer()
  118.  
  119.  
  120. //-------------------reload at specific times 231011a --START-------------
  121. //https://stackoverflow.com/questions/1217929/how-to-automatically-reload-a-web-page-at-a-certain-time
  122. /*
  123. *
  124. * refreshAt(15,35,0); //Will refresh the page at 3:35pm
  125. *
  126. * To do: add refreshAt() for all breaks and execute them if activated from pack_refresh_browser().
  127. * The check can be done inside probeserver. It might need a global variable for break1 ,break2 etc "activated" of "completed"
  128. *
  129. */
  130. var refreshbreak1set=false;
  131. var refreshbreak2set=false;
  132. refreshbreak3set=false;
  133. var refreshbreak4set=false;
  134. var refreshbreak5set=false;
  135. var refreshbreak6set=false;
  136. function refreshAt(hours, minutes, seconds) {
  137.     var now = new Date();
  138.     var then = new Date();
  139.  
  140.     if(now.getHours() > hours ||
  141.        (now.getHours() == hours && now.getMinutes() > minutes) ||
  142.         now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
  143.         then.setDate(now.getDate() + 1);
  144.     }
  145.     then.setHours(hours);
  146.     then.setMinutes(minutes);
  147.     then.setSeconds(seconds);
  148.  
  149.     var timeout = (then.getTime() - now.getTime());
  150.     setTimeout(function() { window.location.reload(true); }, timeout);
  151. }
  152.  
  153. //-------------------reload at specific times --END-------------
  154.  
  155.  
  156.  
  157. //+++++++++++++++++++ probeserver v03 201025+++++++++++++++++
  158. var server_probing_enabled=false;
  159. var server_eval_first_run=true; //to avoid running remote probeserver eval multipletimes
  160. var url_probeserver=location.search.substring(1).indexOf("probeserver");
  161. if (url_probeserver!==-1)server_probing_enabled=true;
  162.  
  163. var timer_server_probe = 30000; //probe every 30 seconds
  164. var server_probe_file="pack_refresh_browser.txt";
  165. var jsonrequestInterval = function () {
  166.     console.log("The request was send");
  167.     // <hr><div id="probeserver"></div><hr>
  168.     var jsonrequestIntervaled = new XMLHttpRequest();
  169.     var random_number=Math.random(); // OLD was=Date.prototype.getTime;
  170.     jsonrequestIntervaled.open("GET", server_probe_file+"?"+random_number, true); // Date.prototype.getTime is used to avoid caching
  171.     jsonrequestIntervaled.send();
  172.     jsonrequestIntervaled.onreadystatechange = function () {
  173.         if (jsonrequestIntervaled.readyState == 4) {
  174.             console.log("The request was made and returned results (with random number="+random_number);
  175.             var response_string =jsonrequestIntervaled.responseText;
  176.             //console.log("DEBUG response_string="+s);
  177.             //always add our extra text
  178.             document.getElementById("probeserver").innerHTML = response_string;
  179.            
  180.             //in case we put the word reload, refresh browser
  181.             if (response_string.indexOf("reload") !== -1) {
  182.                 console.log("refreshing browser");
  183.                 //document.getElementById("probeserver").innerHTML = response_string;
  184.                 window.location.reload(true);
  185.             }
  186.  
  187.             //v201025b -evel - pack_refresh_browser.txt execute commands dynamic (requires probeserver activated) (not implemented yet)
  188.             //in case we put the word "execute", run/eval() command
  189.             if (response_string.indexOf("execute") !== -1) {
  190.                 var s=response_string;              
  191.                 //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
  192.                 //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
  193.                 //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line                
  194.                 var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line                
  195.                 //console.log("DEBUG +++++++++execute found3="+result[1]+"-----------------------");
  196.                 eval(result[1]);
  197.             }
  198.  
  199.             if (response_string.indexOf("breakrefresh") !== -1) {
  200.                 var s=response_string;              
  201.                 //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
  202.                 //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
  203.                 //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line                
  204.                 //var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line    
  205.                 console.log("refreshbreak---");    
  206.                 if ((response_string.indexOf("breakrefresh2")!== -1) && !refreshbreak2set ) {console.log("refreshbreak2");  /*refreshAt(9,2,0);*/ refreshbreak2set=true; }      
  207.                 if ((response_string.indexOf("breakrefresh3")!== -1) && !refreshbreak3set ) {console.log("refreshbreak3");  /*refreshAt(9,42,0);*/ refreshbreak3set=true; }      
  208.                 if ((response_string.indexOf("breakrefresh4")!== -1) && !refreshbreak4set ) {console.log("refreshbreak4");  /*refreshAt(10,47,0);*/ refreshbreak4set=true; }      
  209.                 if ((response_string.indexOf("breakrefresh5")!== -1) && !refreshbreak5set ) {console.log("refreshbreak5");  /*refreshAt(11,33,0);*/ refreshbreak5set=true; }
  210.                 if ((response_string.indexOf("breakrefresh6")!== -1) && !refreshbreak6set ) {console.log("refreshbreak6");  /*refreshAt(12,27,0);*/ refreshbreak6set=true; }
  211.                 //console.log("DEBUG +++++++++execute found3="+result[1]+"-----------------------");
  212.                 //eval(result[1]);
  213.             }            
  214.  
  215.            
  216.         }
  217.     };
  218.    
  219. };
  220.  
  221. if(server_probing_enabled) setInterval(jsonrequestInterval, timer_server_probe);
  222.  
  223. //-------------------probeserver ---------------
  224.  
  225.  
  226. // ((((((((((((((((((((((replace_url v01 190410 opengame , noopengame ((((((((((((((((((((((
  227. //source https://stackoverflow.com/questions/4939805/change-all-links-hrefs-urls-with-vanilla-javascript-regex
  228. function prefix_url(elem, attr) {
  229.     var elems = document.getElementsByTagName(elem);
  230.     for (var i = 0; i < elems.length; i++)
  231.         //elems[i][attr] = elems[i][attr].replace('./', 'opengame.php?file=./');
  232.         elems[i][attr] = 'opengame.php?file=' + elems[i][attr];
  233. }
  234.  
  235. if(url_opengame!==-1) {  
  236.     prefix_url('a', 'href');
  237.     //replace_url('img', 'src');    
  238. }
  239.  
  240. function prefix_remove_url(elem, attr) {
  241.     var elems = document.getElementsByTagName(elem);
  242.     for (var i = 0; i < elems.length; i++)
  243.         elems[i][attr] = elems[i][attr].replace('opengame.php?file=', '');
  244.         //elems[i][attr] = 'opengame.php?file=' + elems[i][attr];
  245. }
  246.  
  247. if(url_opengame!==-1) {  
  248.     prefix_remove_url('a', 'href');
  249.     //replace_url('img', 'src');    
  250. }
  251.  
  252. // )))))))))))))))))))))) replace_url ))))))))))))))))))))))
  253.  
  254.  
  255.  
  256.  
  257. //</script>
  258.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement