Replace all characters in text nodes that are not spaces and then "shake" the body
Linked to from http://lukecod.es/2012/02/23/shake-n-bake-console-settimeout-bomb/
Replace all characters in text nodes that are not spaces and then "shake" the body
Linked to from http://lukecod.es/2012/02/23/shake-n-bake-console-settimeout-bomb/
(function(undefined) { | |
var | |
deviateMin = 1, | |
deviateMax = 10, | |
marginSeed = 20, | |
paddingSeed = 20, | |
madnessInterval = 20, | |
findRegex = new RegExp(/[^ ]/g), | |
replaceText = (typeof __word !== 'undefined') ? __word : "CONNOR", | |
timeoutTime = (typeof __time !== 'undefined') ? __time : 0, | |
random = function(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
}, | |
deviate = function(num, dmin, dmax) { | |
var d_min = dmin || deviateMin, | |
d_max = dmax || deviateMax; | |
return (((random(1, 2) === 1) ? 1 : -1) * random(d_min, d_max)) + num; | |
}, | |
madness = function() { | |
document.body.style.backgroundPosition = deviate(10, 1, 10) + "px " + deviate(10, 1, 10) + "px"; | |
document.body.style['-webkit-transform'] = "rotate("+deviate(1, 1, 3)+"deg)"; | |
document.body.style.margin = deviate(marginSeed) + 'px ' + deviate(marginSeed) + 'px ' + deviate(marginSeed) + 'px ' + deviate(marginSeed) + 'px'; | |
document.body.style.padding = deviate(paddingSeed) + 'px ' + deviate(paddingSeed) + 'px ' + deviate(paddingSeed) + 'px ' + deviate(paddingSeed) + 'px'; | |
}, | |
/* Walk function is licensed to - Ben Alman | |
* v0.1.1 - 5/5/2011 | |
* http://benalman.com/ | |
* | |
* Copyright (c) 2011 "Cowboy" Ben Alman | |
* Dual licensed under the MIT and GPL licenses. | |
* http://benalman.com/about/license/ | |
*/ | |
walk = function(node, callback) { | |
var skip, tmp, depth = 0; | |
do { | |
if ( !skip ) { | |
skip = callback.call(node, depth) === false; | |
} | |
if ( !skip && (tmp = node.firstChild) ) { | |
depth++; | |
} else if ( tmp = node.nextSibling ) { | |
skip = false; | |
} else { | |
tmp = node.parentNode; | |
depth--; | |
skip = true; | |
} | |
node = tmp; | |
} while ( depth > 0 ); | |
}, | |
walkCb = function() { | |
if (this.nodeType == 3) { | |
this.nodeValue = this.nodeValue.replace(findRegex, replaceText); | |
} | |
}; | |
replaceText = replaceText + ' '; | |
timeoutTime = parseInt(timeoutTime, 10) || 0; | |
setTimeout(function() { | |
walk(document.documentElement, walkCb); | |
setInterval(madness, madnessInterval); | |
}, timeoutTime); | |
})(); |