Created
February 8, 2017 18:28
-
-
Save nicolehe/4527e629c1b90d5f14e30fcff7364be4 to your computer and use it in GitHub Desktop.
pre-minified code for http://nicole.pizza/itp/hacking-the-browser/scrambler/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shuffle | |
function shuffle(array) { | |
var currentIndex = array.length, | |
temporaryValue, randomIndex; | |
while (0 !== currentIndex) { | |
randomIndex = Math.floor(Math.random() * currentIndex); | |
currentIndex -= 1; | |
temporaryValue = array[currentIndex]; | |
array[currentIndex] = array[randomIndex]; | |
array[randomIndex] = temporaryValue; | |
} | |
return array; | |
} | |
// get all image urls | |
var imageUrls = []; | |
$('img').each(function() { | |
image = $(this)[0].src; | |
imageUrls.push(image); | |
}); | |
// replace each image url with a random one from the page | |
$('img').each(function() { | |
randomImage = imageUrls[Math.floor(Math.random() * imageUrls.length)]; | |
$(this)[0].src = randomImage; | |
}); | |
// shuffle text | |
$('p, h1, h2, h3, li').each(function() { | |
var text = $(this).text().trim(); | |
if (text !== "") { | |
var splitted = text.split(" "); | |
var shuffled = shuffle(splitted).join(" "); | |
$(this).text(shuffled); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment