Monday, 7 January 2013

Seizure.js - a Colourful bookmarklet.

A while ago a few associates and myself were throwing around little garbage scripts joking with some 'not malicious but malicious' client side js. One of the scripts ( I called seizure.js ) interested @loktar00 enough for him to make a bookmarklet out of it and post it on his blog: Rainbow bright bookmarklet.

His script is changed a bit, and takes away from the original 'effect' a bit in my opinion so here is the original on all of it's twitchy glory.


/* Changes background and foreground colours  for all elements on the page */
function r() {
    return Math.floor(Math.random() * 255);
}
 
function lemon() {
    with(this.style) {
        color = ['rgb(', [r(), r(), r()].join(','), ')'].join('');
        backgroundColor = ['rgb(', [r(), r(), r()].join(','), ')'].join('');
    }
}
 
function rocks() {
    Array.prototype.forEach.call(document.all, function(item) {
        setTimeout(function() {
            lemon.call(item);
        }, Math.random() * 100 + 100);
    });
    setTimeout(rocks, Math.random() * 500 + 100);
}
 
rocks();

I have setup a small demo page on codepen.io or you can install the bookmarklet by dragging the link below into your bookmarks bar:
Seizure.js

You can browser some more of the fun snippets I came up with as well as this one on github: https://gist.github.com/4444273


No comments:

Post a Comment