Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //<script type="text/javascript">
- /*
- * pack_js_footer (put this in same folder as parent html)
- *
- *
- * Changes:
- * v241010c - Refeshtime : added olohmero :breakrefresh7ol 13:20,14:"00",15:"00"
- * v240117b - refreshtimeXXYY : Now I can put refreshtime09:15 to reload at 09:15 ,fixed to "09","47"
- * v240110 - addHashLabels: Add hash prefix in all links loaded inside probeserver (for olohmero mainly)
- * v231031 - breakrefresh# fix error in IF checks
- * v231011 - breakrefresh# reload at specific times start
- * v201025b - eval (pack_refresh_browser.txt) execute commands dynamic (requires probeserver activated) (not implemented yet)
- * v201020c -norightclick -disable right click : eg http://192.168.1.200/tinymce_class/tinymce_template_form.html?file=temp_test01&norightclick
- * v190411 -noopengame (initial ver) (removes opengame -in case we run a plain Http server with no PHP)
- * v190410 -opengame (initial ver)
- * v190404 -showdiv
- * v190402 -all scripts are now in footer
- *
- * example : index.html?showdiv5\&timer3\&probeserver ,
- */
- var first_click=true;
- var addhashlabellinks=true; // allows auto hash numbering (maybe not used)
- var url_time_param=location.search.substring(1).indexOf("time");
- // ((((((((((((((((((( preset timers (((((((((((((((((((
- var additional_wait_time=0;
- var url_timer2=location.search.substring(1).indexOf("timer2");
- var url_timer3=location.search.substring(1).indexOf("timer3");
- var url_timer4=location.search.substring(1).indexOf("timer4");
- var url_timer5=location.search.substring(1).indexOf("timer5");
- var url_timer6=location.search.substring(1).indexOf("timer6");
- var url_timer7=location.search.substring(1).indexOf("timer7");
- if (url_timer2!==-1)additional_wait_time= -3;
- if (url_timer3!==-1)additional_wait_time= -2;
- if (url_timer4!==-1)additional_wait_time= -1;
- if (url_timer5!==-1)additional_wait_time= 0;
- if (url_timer6!==-1)additional_wait_time= 1;
- if (url_timer7!==-1)additional_wait_time= 2;
- var additional_wait_minutes=additional_wait_time*1000*60;
- // )))))))))))))))) preset timers )))))))))))))))))))))))
- // ((((((((((((((((((( option to show only specific DIV (((((((((((((((((((
- var url_showdiv_param=location.search.substring(1).indexOf("showdiv");// != to -1 if we have this param
- var url_showdiv1=location.search.substring(1).indexOf("showdiv1");
- var url_showdiv2=location.search.substring(1).indexOf("showdiv2");
- var url_showdiv3=location.search.substring(1).indexOf("showdiv3");
- var url_showdiv4=location.search.substring(1).indexOf("showdiv4");
- var url_showdiv5=location.search.substring(1).indexOf("showdiv5");
- var url_showdiv6=location.search.substring(1).indexOf("showdiv6");
- var url_showdiv7=location.search.substring(1).indexOf("showdiv7");
- // )))))))))))))))) option to show only specific DIV )))))))))))))))))))))))
- var url_opengame=location.search.substring(1).indexOf("opengame"); //check if we want opengame as prefix to all urls
- 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)
- //if we find a parameter that contains word "time" (eg packA01.html?timer) then we hide all the other links
- function init_links(){
- if((url_showdiv_param!==-1 ) && (url_time_param==-1 ) ){ //disable show_url IF we have set timer
- //if((url_showdiv1==-1) && (url_time_param==-1 )) document.getElementById("div1").style.visibility = "hidden";
- if(url_showdiv1==-1) document.getElementById("div1").style.visibility = "hidden";
- if(url_showdiv2==-1) document.getElementById("div2").style.visibility = "hidden";
- if(url_showdiv3==-1) document.getElementById("div3").style.visibility = "hidden";
- if(url_showdiv4==-1) document.getElementById("div4").style.visibility = "hidden";
- if(url_showdiv5==-1) document.getElementById("div5").style.visibility = "hidden";
- if(url_showdiv6==-1) document.getElementById("div6").style.visibility = "hidden";
- if(url_showdiv7==-1) document.getElementById("div7").style.visibility = "hidden";
- }
- //If we have a timer URL param then HIDE divs
- if(url_time_param!==-1 ) {
- document.getElementById("div2").style.visibility = "hidden";
- document.getElementById("div3").style.visibility = "hidden";
- document.getElementById("div4").style.visibility = "hidden";
- document.getElementById("div5").style.visibility = "hidden";
- document.getElementById("div6").style.visibility = "hidden";
- document.getElementById("div7").style.visibility = "hidden";
- //document.getElementById("div6").style.visibility = "hidden";
- }
- // (((((((((((((((((((((((((( option to disable right click v201020c ((((((((((
- var url_norightclick=location.search.substring(1).indexOf("norightclick");// != to -1 if we have this param
- if(url_norightclick!==-1) {
- document.oncontextmenu=new Function("console.log('main page: right-click-context menu -STOPPED');return false") ; //OK normal page Works
- setInterval(function(){window.frames["sideframe1"].document.oncontextmenu = function(){console.log("setInterval sideframe1 :right click-DISABLED"); return false;}; }, 5000);
- }
- // )))))))))))))))))))))))))) option to disable right click ))))))))
- } // end of function init_links(){
- function showItTimer() {
- //enable if its 1st click AND we have a timer UTL param
- if(first_click && url_time_param !==-1 ) {
- //alert("first_timer=true , "+"location.search.substring(1)="+location.search.substring(1));
- //if(location.search.substring(1)>0) alert("location.search.substring(1)="+location.search.substring(1));
- var minute=1000*60;
- console.log("first click , timers set every :");
- console.log((5*minute + additional_wait_minutes)/60/1000);
- //############ TEST ###################
- setTimeout(function(){document.getElementById("div2").style.visibility = "visible"}, 2000);//test
- setTimeout(function(){document.getElementById("div2").style.visibility = "hidden"}, 5000);//test
- setTimeout(function(){document.getElementById("div4").style.visibility = "visible"}, minute/60);//test
- setTimeout(function(){document.getElementById("div4").style.visibility = "hidden"}, 3000);//test
- // ########### TEST #####################
- setTimeout(function(){document.getElementById("div2").style.visibility = "visible"}, 5*minute+additional_wait_minutes);
- setTimeout(function(){document.getElementById("div3").style.visibility = "visible"}, 10*minute+additional_wait_minutes);
- setTimeout(function(){document.getElementById("div4").style.visibility = "visible"}, 15*minute+additional_wait_minutes);
- setTimeout(function(){document.getElementById("div5").style.visibility = "visible"}, 20*minute+additional_wait_minutes);
- setTimeout(function(){document.getElementById("div6").style.visibility = "visible"}, 25*minute+additional_wait_minutes);
- setTimeout(function(){document.getElementById("div7").style.visibility = "visible"}, 26*minute+additional_wait_minutes);
- }
- first_click=false;
- return false;
- } // end of showItTimer()
- // ((((((((((((((((addHashLabels addhashlabellinks 240110(((((((((((((((((
- function addHashLabels() {
- const divprobesrv = document.getElementById('probeserver');//get probeserver contents
- //const links = document.getElementsByTagName('a');
- const links = divprobesrv.getElementsByTagName('a'); //get all href entries
- const hashRange = 99 - 1 + 1; // 01 to 99
- for (let i = 0; i < links.length; i++) {
- const url = links[i].getAttribute('href');
- const hash = getHash(url);
- // Generate prefix based on hash number
- const prefixletter=links[i].innerHTML.charAt(0);
- //console.log("InnetHTML="+prefixletter+ " , innerHTML="+links[i].innerHTML)
- const prefix = prefixletter+('0' + (hash % hashRange + 1)).slice(-2);
- // Add prefix to link description
- links[i].innerHTML = prefix + '- ' + links[i].innerHTML;
- }
- };
- // Function to generate hash from URL
- function getHash(url) {
- let hash = 0;
- for (let i = 0; i < url.length; i++) {
- hash = ((hash << 5) - hash) + url.charCodeAt(i);
- hash = hash & hash; // Convert to 32bit integer
- }
- return Math.abs(hash);
- }
- // )))))))))))))))End Of addHashLabels addhashlabellinks)))))))))))))))))))
- function refreshAt(hh, mm, seconds) {
- var btime = hh.toString() + mm.toString();
- refreshAtHHMM(btime);
- }
- //-------------------reload at specific times 231011a --START-------------
- //https://stackoverflow.com/questions/1217929/how-to-automatically-reload-a-web-page-at-a-certain-time
- /*
- *
- * refreshAt(15,35,0); //Will refresh the page at 3:35pm
- *
- * To do: add refreshAt() for all breaks and execute them if activated from pack_refresh_browser().
- * The check can be done inside probeserver. It might need a global variable for break1 ,break2 etc "activated" of "completed"
- *
- */
- var refreshbreak1set=false;
- var refreshbreak2set=false;
- refreshbreak3set=false;
- var refreshbreak4set=false;
- var refreshbreak5set=false;
- var refreshbreak6set=false;
- var refreshbreak7olset=false;
- function refreshAtHHMM(breaktime) {
- // Remove colons from breaktime
- breaktime = breaktime.replace(/:/g, '');
- var hours = breaktime.substring(0, 2);
- var minutes = breaktime.substring(2, 4);
- var seconds = "00";
- var now = new Date();
- var then = new Date();
- if(now.getHours() > hours ||
- (now.getHours() == hours && now.getMinutes() > minutes) ||
- now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
- then.setDate(now.getDate() + 1);
- }
- then.setHours(hours);
- then.setMinutes(minutes);
- then.setSeconds(seconds);
- console.log("refreshAt:"+hours+minutes+seconds)
- var timeout = (then.getTime() - now.getTime());
- setTimeout(function() { window.location.reload(true); }, timeout);
- }
- //-------------------reload at specific times --END-------------
- //+++++++++++++++++++ probeserver v03 201025+++++++++++++++++
- var server_probing_enabled=false;
- var server_eval_first_run=true; //to avoid running remote probeserver eval multipletimes
- var url_probeserver=location.search.substring(1).indexOf("probeserver");
- if (url_probeserver!==-1)server_probing_enabled=true;
- var timer_server_probe = 30000; //probe every 30 seconds
- var server_probe_file="pack_refresh_browser.txt";
- var jsonrequestInterval = function () {
- console.log("The request was send");
- // <hr><div id="probeserver"></div><hr>
- var jsonrequestIntervaled = new XMLHttpRequest();
- var random_number=Math.random(); // OLD was=Date.prototype.getTime;
- jsonrequestIntervaled.open("GET", server_probe_file+"?"+random_number, true); // Date.prototype.getTime is used to avoid caching
- jsonrequestIntervaled.send();
- jsonrequestIntervaled.onreadystatechange = function () {
- if (jsonrequestIntervaled.readyState == 4) {
- console.log("The request was made and returned results (with random number="+random_number);
- var response_string =jsonrequestIntervaled.responseText;
- //console.log("DEBUG response_string="+s);
- //always add our extra text
- document.getElementById("probeserver").innerHTML = response_string;
- //in case we put the word reload, refresh browser
- if (response_string.indexOf("reload") !== -1) {
- console.log("refreshing browser");
- //document.getElementById("probeserver").innerHTML = response_string;
- window.location.reload(true);
- }
- //v201025b -evel - pack_refresh_browser.txt execute commands dynamic (requires probeserver activated) (not implemented yet)
- //in case we put the word "execute", run/eval() command
- if (response_string.indexOf("execute") !== -1) {
- var s=response_string;
- //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
- //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
- //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line
- var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line
- //console.log("DEBUG +++++++++execute found3="+result[1]+"-----------------------");
- eval(result[1]);
- }
- // +++++++++++++++++++=refreshtimeXXYY++++++++++++++++++++++
- if (response_string.indexOf("refreshtime") !== -1) {
- var startIndex = response_string.indexOf("refreshtime") + 11; // Start index after "refreshtime"
- var endIndex = response_string.indexOf(":", startIndex); // Index of ":" after XX
- var refreshTime;
- if (endIndex !== -1) {
- // Case: refreshtimeXX:YY
- refreshTime = response_string.substring(startIndex, endIndex) + response_string.substring(endIndex + 1);
- } else {
- // Case: refreshtimeXXYY
- refreshTime = response_string.substring(startIndex);
- }
- //console.log("RefreshTime="+refreshTime);
- refreshAtHHMM(refreshTime);
- }
- //-----------------------refreshtimeXX:YY END----------------------
- if (response_string.indexOf("breakrefresh") !== -1) {
- var s=response_string;
- //pack_refresh_browser = execute EVAL:console.log("eval-command-console.log--hello");:EVAL
- //var result = s.match(/AAAA:(.*?):BBBB/i); //OLD - ONLY for single line
- //var result = s.match(/AAAA:([\s\S]*?):BBBB/); //multi line
- //var result = s.match(/EVAL:([\s\S]*?):EVAL/); //multi line
- console.log("refreshbreak---");
- if ((response_string.indexOf("breakrefresh2")!== -1) && !refreshbreak2set ) {console.log("refreshbreak2"); refreshAt("09","02",0); refreshbreak2set=true; }
- if ((response_string.indexOf("breakrefresh3")!== -1) && !refreshbreak3set ) {console.log("refreshbreak3"); refreshAt("09","42",0); refreshbreak3set=true; }
- if ((response_string.indexOf("breakrefresh4")!== -1) && !refreshbreak4set ) {console.log("refreshbreak4"); refreshAt(10,47,0); refreshbreak4set=true; }
- if ((response_string.indexOf("breakrefresh5")!== -1) && !refreshbreak5set ) {console.log("refreshbreak5"); refreshAt(11,33,0); refreshbreak5set=true; }
- if ((response_string.indexOf("breakrefresh6")!== -1) && !refreshbreak6set ) {console.log("refreshbreak6"); refreshAt(12,27,0); refreshbreak6set=true; }
- //olohmero
- if ((response_string.indexOf("breakrefresh7ol")!== -1) && !refreshbreak7olset ) {
- console.log("refreshbreak7"); refreshAt(13,20,"01");
- console.log("refreshbreak8"); refreshAt(14,"00","01");
- console.log("refreshbreak9"); refreshAt(15,"00","01");
- //console.log("refreshbreak10TEST"); refreshAt(14,"12","01");
- refreshbreak7olset=true;
- }
- //console.log("DEBUG +++++++++execute found3="+result[1]+"-----------------------");
- //eval(result[1]);
- }
- //in case we put the word reload, refresh browser
- if (response_string.indexOf("addhashlabellinks") !== -1) {
- console.log("addhashlabellinks in div probsrv(for olohmero mostly)");
- addHashLabels();
- }
- }
- };
- };
- if(server_probing_enabled) setInterval(jsonrequestInterval, timer_server_probe);
- //-------------------probeserver ---------------
- // ((((((((((((((((((((((replace_url v01 190410 opengame , noopengame ((((((((((((((((((((((
- //source https://stackoverflow.com/questions/4939805/change-all-links-hrefs-urls-with-vanilla-javascript-regex
- function prefix_url(elem, attr) {
- var elems = document.getElementsByTagName(elem);
- for (var i = 0; i < elems.length; i++)
- //elems[i][attr] = elems[i][attr].replace('./', 'opengame.php?file=./');
- elems[i][attr] = 'opengame.php?file=' + elems[i][attr];
- }
- if(url_opengame!==-1) {
- prefix_url('a', 'href');
- //replace_url('img', 'src');
- }
- function prefix_remove_url(elem, attr) {
- var elems = document.getElementsByTagName(elem);
- for (var i = 0; i < elems.length; i++)
- elems[i][attr] = elems[i][attr].replace('opengame.php?file=', '');
- //elems[i][attr] = 'opengame.php?file=' + elems[i][attr];
- }
- if(url_opengame!==-1) {
- prefix_remove_url('a', 'href');
- //replace_url('img', 'src');
- }
- // )))))))))))))))))))))) replace_url ))))))))))))))))))))))
- /*
- // Load Javascript dynamically
- if (addhashlabellinks) {
- var secondScript = document.createElement('script');
- secondScript.type = 'text/javascript';
- secondScript.src = 'test_hash.js';
- console.log("addhashlabellinks INSIDE");
- secondScript.onload = function() {
- // code to execute after the second script is loaded and executed
- addHashLabels();
- };
- document.head.appendChild(secondScript);
- }
- */
- //</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement