/*
* @title roach
* @description my bookmarklet
* @include http://*
* @license MIT License
* @require
*/
class Roach {
constructor() {
this.imgs = [
'http://jsrun.it/assets/k/Z/u/X/kZuXk.gif',
'http://jsrun.it/assets/M/f/M/z/MfMzs.gif',
'http://jsrun.it/assets/4/j/u/H/4juHK.gif',
'http://jsrun.it/assets/G/e/T/a/GeTaI.gif',
'http://jsrun.it/assets/A/i/o/Q/AioQG.gif',
'http://jsrun.it/assets/k/q/T/f/kqTfH.gif',
'http://jsrun.it/assets/k/T/E/G/kTEGu.gif',
'http://jsrun.it/assets/i/Y/T/i/iYTiH.gif'
];
this.pw = document.body.clientWidth - 16;
this.ph = Math.max.apply(null, [document.body.clientHeight, document.body.scrollHeight, document.documentElement.scrollHeight, document.documentElement.clientHeight]) - 16;
this.x = Number(this.pw * Math.random());
this.y = Number(this.ph * Math.random());
this.r = Number(360 * Math.random());
this.node = document.createElement('img');
this.node.style.position = 'fixed';
document.body.appendChild(this.node);
}
get file() {
return this.imgs[Number(Math.floor((Number(this.r + 22.5) % 360) / 45))];
}
update() {
this.r = (this.r + 360 + Number(10 * Math.random() - 5)) % 360;
this.x += Math.cos(this.r * Math.PI / 180) * 8;
this.y -= Math.sin(this.r * Math.PI / 180) * 8;
if (this.x < -16) this.x = this.pw;
if (this.x > this.pw) this.x = -16;
if (this.y < -16) this.y = this.ph;
if (this.y > this.ph) this.y = -16;
this.node.style.left = this.x + 'px';
this.node.style.top = this.y + 'px';
this.node.src = this.file;
setTimeout(this.update.bind(this), 10);
}
};
for (var n = 0; n < 10; n++)
new Roach().update();