-
-
Save indysigner/971829525d01a7e72c5c to your computer and use it in GitHub Desktop.
Randomize content and frustrate your design!
This file contains hidden or 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
// ==UserScript== | |
// @name Randomize content | |
// @namespace https://www.blokblok.nl/ | |
// @version 0.3 | |
// @description Frustrate your design! | |
// @author Dio Vayne | |
// @match *://*/* | |
// @grant none | |
// @require http://code.jquery.com/jquery-latest.js | |
// ==/UserScript== | |
(function() { | |
if (document.URL.indexOf('random') > 0) { | |
$('body').append('<a href="#" id="random" style="background-color:#000;color:#FFF;padding:5px 10px; position:fixed;bottom:0;right:0;display:block;">random</a>'); | |
var vSpread = 200; //replace images with version x pixels higher/lower and wider/smaller | |
var vImgBreakpoint = 150; //images wider than this get replaced | |
var vTheme = 'weird'; //what kind of images do you want for replacement | |
$('#random').bind('click',function(){ | |
$('img').each(function(){ | |
var vT = $(this); | |
var vW = vT.width(); | |
if(vW > vImgBreakpoint){ | |
var vH = vT.height(); | |
var vWmin = vW-vSpread; | |
if(vWmin < 100) vWmin = 100; | |
var vWmax = vW+vSpread; | |
var vHmin = vH-vSpread; | |
if(vHmin < 100) vHmin = 100; | |
var vHmax = vH+vSpread; | |
vT.attr('src','http://loremflickr.com/'+rand(vWmin,vWmax)+'/'+rand(vHmin,vHmax)+'/'+vTheme+'/all'); | |
} | |
}); | |
$('p').each(function(){ | |
var vT = $(this); | |
var vRandom = rand(1,3); | |
var vLen = vT.text().length; | |
if(vLen > 30){ | |
if(vRandom === 1){ | |
vT.text(vT.text().substr(0,Math.round(vLen/2))); | |
}else if(vRandom === 2){ | |
vT.text(vT.text() + vT.text().substr(0,Math.round(vLen/2))); | |
}else{ | |
vT.text(vT.text() + vT.text()); | |
} | |
} | |
}); | |
$('a, h1, h2, h3, h4, label').not('[href^="mailto"]').not('[href^="tel"]').not('#random').each(function(){ | |
var vT = $(this); | |
var vRandom = rand(1,3); | |
var vLen = vT.text().length; | |
if(vLen > 5){ | |
if(vRandom === 1){ | |
vT.text(vT.text().substr(0,Math.round(vLen/2))); | |
}else if(vRandom === 2){ | |
vT.text(vT.text() + vT.text().substr(0,Math.round(vLen/2))); | |
}else{ | |
vT.text(vT.text() + vT.text()); | |
} | |
} | |
}); | |
return false; | |
}); | |
} | |
function rand(min,max) | |
{ | |
return Math.floor(Math.random()*(max-min+1)+min); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment