Last active
February 18, 2016 13:28
-
-
Save DioVayne/bdee35b39b745a27d323 to your computer and use it in GitHub Desktop.
Randomize content and frustrate your design!
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
// ==UserScript== | |
// @name Randomize content | |
// @namespace https://www.blokblok.nl/ | |
// @version 0.4 | |
// @description Frustrate your design! | |
// @author Dio Vayne | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
if (document.URL.indexOf('random') > 0) { | |
if (!jQuery) { | |
addJQuery(main); | |
}else{ | |
main(); | |
} | |
} | |
})(); | |
function rand(min,max) | |
{ | |
return Math.floor(Math.random()*(max-min+1)+min); | |
} | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
function main(){ | |
$('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; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment