Note that there are some explanatory texts on larger screens.

plurals
  1. POBackup Bookmarklet Code
    text
    copied!<p>Hi i have bookmarklet code to load a scripts from a mirrored backup location if my main hosting goes down, it works but i want to know the best way to do this as i know the current way i am doing it is probably not the best way. </p> <p>(<strong>this is a example of my backup bookmarlet code expanded</strong>) </p> <pre class="lang-js prettyprint-override"><code>javascript: (function () { var scriptname = 'testscript'; function checkServerStatus() { var v = setTimeout(function () { loadscript('backupserver.hardiman.co.nz') }, 4500); var a = document.body.appendChild(document.createElement('img')); a.onload = function () { clearTimeout(v); loadscript('screepts.com') }; a.src = 'http://screepts.com/ping.gif?' + Math.random(); } checkServerStatus(); function loadscript(b) { var a = document.createElement('script'); a.type = 'text/javascript'; a.src = 'http://' + b + '/bm/' + scriptname + '.js?' + Math.random(); document.getElementsByTagName('head')[0].appendChild(a) } })();` </code></pre> <p>And this is it wrapped up as a bookmarklet : </p> <pre class="lang-html prettyprint-override"><code>&lt;a href="javascript:%28function%28%29%7Bvar c%3D'testscript'%3Bfunction checkServerStatus%28%29%7Bvar v%3DsetTimeout%28function%28%29%7Bloadscript%28'backupserver.hardiman.co.nz'%29%7D,4500%29%3Bvar a%3Ddocument.body.appendChild%28document.createElement%28'img'%29%29%3Ba.onload%3Dfunction%28%29%7BclearTimeout%28v%29%3Bloadscript%28'screepts.com'%29%7D%3Ba.src%3D'http://screepts.com/ping.gif%3F'%2BMath.random%28%29%3B%7DcheckServerStatus%28%29%3Bfunction loadscript%28b%29%7Bvar a%3Ddocument.createElement%28'script'%29%3Ba.type%3D'text/javascript'%3Ba.src%3D'http://'%2Bb%2B'/bm/'%2Bc%2B'.js%3F'%2BMath.random%28%29%3Bdocument.getElementsByTagName%28'head'%29%5B0%5D.appendChild%28a%29%7D%7D%29%28%29%3B"&gt;Test Script&lt;/a&gt; </code></pre> <p>Any help or advice on loading a script from a backup server would be greatly appreciated..</p> <hr> <p>Okay sorry i should have been more specific on the question. Since my hosting went down i was able to test the above code properly. I think the only thing i need to do is parse what server was loaded to the script. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload