Advertisement
plirof2

pack_js_footer - breaktime mod04 v241010c

Oct 18th, 2024
49
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. * v241010c - Refeshtime : added olohmero :breakrefresh7ol 13:20,14:"00",15:"00"
  8. * v240117b - refreshtimeXXYY : Now I can put refreshtime09:15 to reload at 09:15 ,fixed to "09","47"
  9. * v240110 - addHashLabels: Add hash prefix in all links loaded inside probeserver (for olohmero mainly)
  10. * v231031 - breakrefresh# fix error in IF checks
  11. * v231011 - breakrefresh# reload at specific times start
  12. * v201025b - eval (pack_refresh_browser.txt) execute commands dynamic (requires probeserver activated) (not implemented yet)
  13. * v201020c -norightclick -disable right click : eg http://192.168.1.200/tinymce_class/tinymce_template_form.html?file=temp_test01&norightclick
  14. * v190411 -noopengame (initial ver) (removes opengame -in case we run a plain Http server with no PHP)
  15. * v190410 -opengame (initial ver)
  16. * v190404 -showdiv
  17. * v190402 -all scripts are now in footer
  18. *
  19. * example : index.html?showdiv5\&timer3\&probeserver ,
  20. */
  21.  
  22.     var first_click=true;
  23.     var addhashlabellinks=true; // allows auto hash numbering (maybe not used)
  24.     var url_time_param=location.search.substring(1).indexOf("time");
  25.     // (((((((((((((((((((  preset timers (((((((((((((((((((
  26.     var additional_wait_time=0;
  27.     var url_timer2=location.search.substring(1).indexOf("timer2");
  28.     var url_timer3=location.search.substring(1).indexOf("timer3");
  29.     var url_timer4=location.search.substring(1).indexOf("timer4");
  30.     var url_timer5=location.search.substring(1).indexOf("timer5");
  31.     var url_timer6=location.search.substring(1).indexOf("timer6");
  32.     var url_timer7=location.search.substring(1).indexOf("timer7");
  33.  
  34.     if (url_timer2!==-1)additional_wait_time= -3;
  35.     if (url_timer3!==-1)additional_wait_time= -2;
  36.     if (url_timer4!==-1)additional_wait_time= -1;
  37.     if (url_timer5!==-1)additional_wait_time= 0;
  38.     if (url_timer6!==-1)additional_wait_time= 1;
  39.     if (url_timer7!==-1)additional_wait_time= 2;
  40.     var additional_wait_minutes=additional_wait_time*1000*60;
  41.     // ))))))))))))))))  preset timers )))))))))))))))))))))))
  42.  
  43.     // (((((((((((((((((((  option to show only specific DIV (((((((((((((((((((
  44.     var url_showdiv_param=location.search.substring(1).indexOf("showdiv");// != to -1 if we have this param
  45.     var url_showdiv1=location.search.substring(1).indexOf("showdiv1");
  46.     var url_showdiv2=location.search.substring(1).indexOf("showdiv2");
  47.     var url_showdiv3=location.search.substring(1).indexOf("showdiv3");
  48.     var url_showdiv4=location.search.substring(1).indexOf("showdiv4");
  49.     var url_showdiv5=location.search.substring(1).indexOf("showdiv5");
  50.     var url_showdiv6=location.search.substring(1).indexOf("showdiv6");
  51.     var url_showdiv7=location.search.substring(1).indexOf("showdiv7");
  52.     // ))))))))))))))))  option to show only specific DIV  )))))))))))))))))))))))
  53.  
  54.     var url_opengame=location.search.substring(1).indexOf("opengame"); //check if we want opengame as prefix to all urls
  55.     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)
  56.  
  57.  
  58. //if we find a parameter that contains word "time" (eg packA01.html?timer) then we hide all the other links
  59. function init_links(){
  60.  
  61.     if((url_showdiv_param!==-1 ) && (url_time_param==-1 ) ){  //disable show_url IF we have set timer
  62.         //if((url_showdiv1==-1) && (url_time_param==-1 )) document.getElementById("div1").style.visibility = "hidden";
  63.         if(url_showdiv1==-1) document.getElementById("div1").style.visibility = "hidden";
  64.         if(url_showdiv2==-1) document.getElementById("div2").style.visibility = "hidden";
  65.         if(url_showdiv3==-1) document.getElementById("div3").style.visibility = "hidden";
  66.         if(url_showdiv4==-1) document.getElementById("div4").style.visibility = "hidden";
  67.         if(url_showdiv5==-1) document.getElementById("div5").style.visibility = "hidden";
  68.         if(url_showdiv6==-1) document.getElementById("div6").style.visibility = "hidden";
  69.         if(url_showdiv7==-1) document.getElementById("div7").style.visibility = "hidden";    
  70.     }    
  71.  
  72.     //If we have a timer URL param then HIDE divs
  73.     if(url_time_param!==-1 ) {
  74.         document.getElementById("div2").style.visibility = "hidden";
  75.         document.getElementById("div3").style.visibility = "hidden";
  76.         document.getElementById("div4").style.visibility = "hidden";
  77.         document.getElementById("div5").style.visibility = "hidden";
  78.         document.getElementById("div6").style.visibility = "hidden";
  79.         document.getElementById("div7").style.visibility = "hidden";
  80.         //document.getElementById("div6").style.visibility = "hidden";        
  81.     }
  82.  
  83.  
  84. // (((((((((((((((((((((((((( option to disable right click v201020c ((((((((((
  85.     var url_norightclick=location.search.substring(1).indexOf("norightclick");// != to -1 if we have this param
  86.     if(url_norightclick!==-1) {
  87.         document.oncontextmenu=new Function("console.log('main page: right-click-context menu -STOPPED');return false") ; //OK normal page Works  
  88.         setInterval(function(){window.frames["sideframe1"].document.oncontextmenu = function(){console.log("setInterval sideframe1 :right click-DISABLED"); return false;}; }, 5000);
  89.     }
  90. // )))))))))))))))))))))))))) option to disable right click ))))))))
  91.  
  92. } // end of function init_links(){
  93.  
  94. function showItTimer() {
  95.     //enable if its 1st click AND we have a timer UTL param
  96.     if(first_click && url_time_param !==-1 ) {
  97.         //alert("first_timer=true   , "+"location.search.substring(1)="+location.search.substring(1));
  98.         //if(location.search.substring(1)>0)  alert("location.search.substring(1)="+location.search.substring(1));
  99.         var minute=1000*60;
  100.         console.log("first click , timers set every :");
  101.         console.log((5*minute + additional_wait_minutes)/60/1000);
  102.             //############ TEST ###################
  103.             setTimeout(function(){document.getElementById("div2").style.visibility = "visible"}, 2000);//test
  104.             setTimeout(function(){document.getElementById("div2").style.visibility = "hidden"}, 5000);//test
  105.  
  106.             setTimeout(function(){document.getElementById("div4").style.visibility = "visible"}, minute/60);//test
  107.             setTimeout(function(){document.getElementById("div4").style.visibility = "hidden"}, 3000);//test
  108.             // ########### TEST #####################
  109.         setTimeout(function(){document.getElementById("div2").style.visibility = "visible"}, 5*minute+additional_wait_minutes);
  110.         setTimeout(function(){document.getElementById("div3").style.visibility = "visible"}, 10*minute+additional_wait_minutes);
  111.         setTimeout(function(){document.getElementById("div4").style.visibility = "visible"}, 15*minute+additional_wait_minutes);
  112.         setTimeout(function(){document.getElementById("div5").style.visibility = "visible"}, 20*minute+additional_wait_minutes);
  113.         setTimeout(function(){document.getElementById("div6").style.visibility = "visible"}, 25*minute+additional_wait_minutes);
  114.         setTimeout(function(){document.getElementById("div7").style.visibility = "visible"}, 26*minute+additional_wait_minutes);
  115.  
  116.        
  117.     }
  118.     first_click=false;
  119.  
  120.     return false;
  121. } // end of showItTimer()
  122.  
  123. // ((((((((((((((((addHashLabels addhashlabellinks 240110(((((((((((((((((
  124. function addHashLabels() {
  125.   const divprobesrv = document.getElementById('probeserver');//get probeserver contents
  126.   //const links = document.getElementsByTagName('a');
  127.   const links = divprobesrv.getElementsByTagName('a'); //get all href entries
  128.   const hashRange = 99 - 1 + 1; // 01 to 99
  129.   for (let i = 0; i < links.length; i++) {
  130.     const url = links[i].getAttribute('href');
  131.     const hash = getHash(url);
  132.     // Generate prefix based on hash number
  133.     const prefixletter=links[i].innerHTML.charAt(0);
  134.     //console.log("InnetHTML="+prefixletter+ " , innerHTML="+links[i].innerHTML)
  135.     const prefix = prefixletter+('0' + (hash % hashRange + 1)).slice(-2);
  136.    
  137.     // Add prefix to link description
  138.     links[i].innerHTML = prefix + '- ' + links[i].innerHTML;
  139.   }
  140. };
  141.  
  142. // Function to generate hash from URL
  143. function getHash(url) {
  144.   let hash = 0;
  145.   for (let i = 0; i < url.length; i++) {
  146.     hash = ((hash << 5) - hash) + url.charCodeAt(i);
  147.     hash = hash & hash; // Convert to 32bit integer
  148.   }
  149.   return Math.abs(hash);
  150. }
  151. // )))))))))))))))End Of addHashLabels addhashlabellinks)))))))))))))))))))
  152.  
  153.  
  154. function refreshAt(hh, mm, seconds) {
  155.     var btime = hh.toString() + mm.toString();
  156.     refreshAtHHMM(btime);
  157. }
  158.  
  159. //-------------------reload at specific times 231011a --START-------------
  160. //https://stackoverflow.com/questions/1217929/how-to-automatically-reload-a-web-page-at-a-certain-time
  161. /*
  162. *
  163. * refreshAt(15,35,0); //Will refresh the page at 3:35pm
  164. *
  165. * To do: add refreshAt() for all breaks and execute them if activated from pack_refresh_browser().
  166. * The check can be done inside probeserver. It might need a global variable for break1 ,break2 etc "activated" of "completed"
  167. *
  168. */
  169. var refreshbreak1set=false;
  170. var refreshbreak2set=false;
  171. refreshbreak3set=false;
  172. var refreshbreak4set=false;
  173. var refreshbreak5set=false;
  174. var refreshbreak6set=false;
  175. var refreshbreak7olset=false;
  176. function refreshAtHHMM(breaktime) {
  177.       // Remove colons from breaktime
  178.     breaktime = breaktime.replace(/:/g, '');
  179.     var hours = breaktime.substring(0, 2);
  180.     var minutes = breaktime.substring(2, 4);
  181.     var seconds = "00";
  182.  
  183.  
  184.     var now = new Date();
  185.     var then = new Date();
  186.  
  187.     if(now.getHours() > hours ||
  188.        (now.getHours() == hours && now.getMinutes() > minutes) ||
  189.         now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
  190.         then.setDate(now.getDate() + 1);
  191.     }
  192.     then.setHours(hours);
  193.     then.setMinutes(minutes);
  194.     then.setSeconds(seconds);
  195.     console.log("refreshAt:"+hours+minutes+seconds)
  196.     var timeout = (then.getTime() - now.getTime());
  197.     setTimeout(function() { window.location.reload(true); }, timeout);
  198. }
  199.  
  200. //-------------------reload at specific times --END-------------
  201.  
  202.  
  203.  
  204. //+++++++++++++++++++ probeserver v03 201025+++++++++++++++++
  205. var server_probing_enabled=false;
  206. var server_eval_first_run=true; //to avoid running remote probeserver eval multipletimes
  207. var url_probeserver=location.search.substring(1).indexOf("probeserver");
  208. if (url_probeserver!==-1)server_probing_enabled=true;
  209.  
  210. var timer_server_probe = 30000; //probe every 30 seconds
  211. var server_probe_file="pack_refresh_browser.txt";
  212. var jsonrequestInterval = function () {
  213.     console.log("The request was send");
  214.     // <hr><div id="probeserver"></div><hr>
  215.     var jsonrequestIntervaled = new XMLHttpRequest();
  216.     var random_number=Math.random(); // OLD was=Date.prototype.getTime;
  217.     jsonrequestIntervaled.open("GET", server_probe_file+"?"+random_number, true); // Date.prototype.getTime is used to avoid caching
  218.     jsonrequestIntervaled.send();
  219.     jsonrequestIntervaled.onreadystatechange = function () {
  220.         if (jsonrequestIntervaled.readyState == 4) {
  221.             console.log("The request was made and returned results (with random number="+random_number);
  222.             var response_string =jsonrequestIntervaled.responseText;
  223.             //console.log("DEBUG response_string="+s);
  224.             //always add our extra text
  225.             document.getElementById("probeserver").innerHTML = response_string;
  226.            
  227.             //in case we put the word reload, refresh browser
  228.             if (response_string.indexOf("reload") !== -1) {
  229.                 console.log("refreshing browser");
  230.                 //document.getElementById("probeserver").innerHTML = response_string;
  231.                 window.location.reload(true);
  232.             }
  233.  
  234.             //v201025b -evel - pack_refresh_browser.txt execute commands dynamic (requires probeserver activated) (not implemented yet)
  235.             //in case we put the word "execute", run/eval() command
  236.             if (response_string.indexOf("execute") !== -1) {
  237.                 var s=response_string;              
  238.                 //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
  239.                 //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
  240.                 //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line                
  241.                 var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line                
  242.                 //console.log("DEBUG +++++++++execute found3="+result[1]+"-----------------------");
  243.                 eval(result[1]);
  244.             }
  245.  
  246.             // +++++++++++++++++++=refreshtimeXXYY++++++++++++++++++++++
  247.             if (response_string.indexOf("refreshtime") !== -1) {
  248.               var startIndex = response_string.indexOf("refreshtime") + 11; // Start index after "refreshtime"
  249.               var endIndex = response_string.indexOf(":", startIndex); // Index of ":" after XX
  250.               var refreshTime;
  251.              
  252.               if (endIndex !== -1) {
  253.                 // Case: refreshtimeXX:YY
  254.                 refreshTime = response_string.substring(startIndex, endIndex) + response_string.substring(endIndex + 1);
  255.               } else {
  256.                 // Case: refreshtimeXXYY
  257.                 refreshTime = response_string.substring(startIndex);
  258.               }
  259.               //console.log("RefreshTime="+refreshTime);
  260.               refreshAtHHMM(refreshTime);
  261.             }
  262.             //-----------------------refreshtimeXX:YY END----------------------
  263.  
  264.             if (response_string.indexOf("breakrefresh") !== -1) {
  265.                 var s=response_string;              
  266.                 //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
  267.                 //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
  268.                 //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line                
  269.                 //var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line    
  270.                 console.log("refreshbreak---");    
  271.                 if ((response_string.indexOf("breakrefresh2")!== -1) && !refreshbreak2set ) {console.log("refreshbreak2");  refreshAt("09","02",0); refreshbreak2set=true; }      
  272.                 if ((response_string.indexOf("breakrefresh3")!== -1) && !refreshbreak3set ) {console.log("refreshbreak3");  refreshAt("09","42",0); refreshbreak3set=true; }      
  273.                 if ((response_string.indexOf("breakrefresh4")!== -1) && !refreshbreak4set ) {console.log("refreshbreak4");  refreshAt(10,47,0); refreshbreak4set=true; }      
  274.                 if ((response_string.indexOf("breakrefresh5")!== -1) && !refreshbreak5set ) {console.log("refreshbreak5");  refreshAt(11,33,0); refreshbreak5set=true; }
  275.                 if ((response_string.indexOf("breakrefresh6")!== -1) && !refreshbreak6set ) {console.log("refreshbreak6");  refreshAt(12,27,0); refreshbreak6set=true; }
  276.                 //olohmero
  277.                 if ((response_string.indexOf("breakrefresh7ol")!== -1) && !refreshbreak7olset ) {
  278.                         console.log("refreshbreak7");  refreshAt(13,20,"01");
  279.                         console.log("refreshbreak8");  refreshAt(14,"00","01");
  280.                         console.log("refreshbreak9");  refreshAt(15,"00","01");
  281.                         //console.log("refreshbreak10TEST");  refreshAt(14,"12","01");
  282.                         refreshbreak7olset=true;
  283.                     }
  284.                 //console.log("DEBUG +++++++++execute found3="+result[1]+"-----------------------");
  285.                 //eval(result[1]);
  286.             }
  287.  
  288.             //in case we put the word reload, refresh browser
  289.             if (response_string.indexOf("addhashlabellinks") !== -1) {
  290.                 console.log("addhashlabellinks in div probsrv(for olohmero mostly)");
  291.                 addHashLabels();
  292.             }
  293.  
  294.  
  295.            
  296.         }
  297.     };
  298.    
  299. };
  300.  
  301. if(server_probing_enabled) setInterval(jsonrequestInterval, timer_server_probe);
  302.  
  303. //-------------------probeserver ---------------
  304.  
  305.  
  306. // ((((((((((((((((((((((replace_url v01 190410 opengame , noopengame ((((((((((((((((((((((
  307. //source https://stackoverflow.com/questions/4939805/change-all-links-hrefs-urls-with-vanilla-javascript-regex
  308. function prefix_url(elem, attr) {
  309.     var elems = document.getElementsByTagName(elem);
  310.     for (var i = 0; i < elems.length; i++)
  311.         //elems[i][attr] = elems[i][attr].replace('./', 'opengame.php?file=./');
  312.         elems[i][attr] = 'opengame.php?file=' + elems[i][attr];
  313. }
  314.  
  315. if(url_opengame!==-1) {  
  316.     prefix_url('a', 'href');
  317.     //replace_url('img', 'src');    
  318. }
  319.  
  320. function prefix_remove_url(elem, attr) {
  321.     var elems = document.getElementsByTagName(elem);
  322.     for (var i = 0; i < elems.length; i++)
  323.         elems[i][attr] = elems[i][attr].replace('opengame.php?file=', '');
  324.         //elems[i][attr] = 'opengame.php?file=' + elems[i][attr];
  325. }
  326.  
  327. if(url_opengame!==-1) {  
  328.     prefix_remove_url('a', 'href');
  329.     //replace_url('img', 'src');    
  330. }
  331.  
  332. // )))))))))))))))))))))) replace_url ))))))))))))))))))))))
  333.  
  334.             /*
  335.             // Load Javascript dynamically
  336.             if (addhashlabellinks) {
  337.               var secondScript = document.createElement('script');
  338.               secondScript.type = 'text/javascript';
  339.               secondScript.src = 'test_hash.js';
  340.               console.log("addhashlabellinks INSIDE");
  341.               secondScript.onload = function() {
  342.                 // code to execute after the second script is loaded and executed
  343.                 addHashLabels();
  344.               };
  345.               document.head.appendChild(secondScript);
  346.             }                        
  347.             */
  348.  
  349.  
  350.  
  351.  
  352. //</script>
  353.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement