Skip to content

Instantly share code, notes, and snippets.

@lukekarrys
Last active December 7, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukekarrys/1718831 to your computer and use it in GitHub Desktop.
Save lukekarrys/1718831 to your computer and use it in GitHub Desktop.
Replace all characters in text nodes that are not spaces and then "shake" the body
(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);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment