public
Created

Random reloader

  • Download Gist
example.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<html>
<head>
<script type="text/javascript" src="randomreload.js"></script>
</head>
<body>
<h2>Currently implemented:
<script type="text/javascript">
reloading = new reloader(1);
document.write(reloading.r.length);
</script>
ways to reload the page.
</h2>
<button id="abutton">I'm a button!</button>
<script type="text/javascript">
document.getElementById('abutton').onclick = function() {
reloading.reload();
};
</script>
</body>
</html>
randomreload.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
/*
randomreload.js -- reload using a random method
based on this list: http://www.phpied.com/files/location-location/location-location.html
 
USE:
 
...
<script type="text/javascript" src="randomreload.js"></script>
...
<script type="text/javascript">
rl = new reloader();
rl.reload();
</script>
...
 
Protip: Use reloader.reload as a callback!
 
LICENSE: http://sam.zoy.org/wtfpl
 
*/
 
function reloader(recurse) {
recurse = recurse || 1;
var smp = ["location",
"location.href",
"location['href']"];
var smf = ["location.assign(%)",
"location.replace(%)",
"location['assign'](%)",
"location['replace'](%)"];
var smo = ["location.reload()",
"location['reload']()"]
 
var p = ["location",
"location.href",
"window.location",
"window.location.href",
"self.location",
"self.location.href",
"location['href']",
"window['location']",
"window['location'].href",
"window['location']['href']",
"window.location['href']",
"self['location']",
"self['location'].href",
"self['location']['href']",
"self.location['href']"];
var f = ["location.assign(%)",
"location.replace(%)",
"window.location.assign(%)",
"window.location.replace(%)",
"self.location.assign(%)",
"self.location.replace(%)",
"location['assign'](%)",
"location['replace'](%)",
"window.location['assign'](%)",
"window.location['replace'](%)",
"window['location'].assign(%)",
"window['location'].replace(%)",
"window['location']['assign'](%)",
"window['location']['replace'](%)",
"self.location['assign'](%)",
"self.location['replace'](%)",
"self['location'].assign(%)",
"self['location'].replace(%)",
"self['location']['assign'](%)",
"self['location']['replace'](%)"];
this.r = [];
for(var i in p) {
for(var j in p) {
this.r[this.r.length] = p[i] + ' = ' + p[j];
}
 
for(var k in f) {
var tpl = f[k];
this.r[this.r.length] = tpl.replace('%', p[i]);
}
}
 
var o = ["location.reload()",
"location['reload']()",
"window.location.reload()",
"window['location'].reload()",
"window.location['reload']()",
"window['location']['reload']()",
"self.location.reload()",
"self['location'].reload()",
"self.location['reload']()",
"self['location']['reload']()"];
for (var i in o) {
this.r[this.r.length] = o[i];
}
 
var d = this.r.slice(0);
 
for (var i in d) {
this.r[this.r.length] = 'eval(\"' + d[i] + '\")';
}
 
for (var i in d) {
this.r[this.r.length] = 'new Function(\"' + d[i] + '\")()';
}
 
var ix = 2;
while (ix <= recurse) {
var tar = '';
for (var ixx=0; ixx < ix; ixx++)
tar += 'self.';
 
for (var i in smp) {
for (var j in p) {
this.r[this.r.length] = tar + smp[i] + ' = ' + p[j];
}
for (var k in f) {
var tpl = f[k];
this.r[this.r.length] = tpl.replace('%', tar + smp);
}
}
 
for (var i in smo) {
this.r[this.r.length] = tar + smo[i];
}
ix++;
}
 
this.reload = function() {
var i = Math.floor(Math.random() * this.r.length);
eval(this.r[i]);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.