based on Martin Büttner's code

JavaScript by ouuan