Cursor hijacking
by mkdizajn
HTML
<div style="width:100%;height:400px">
resources:
<img id="myCursor" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABzUlEQVR4XpWTT2iSYRzHP4Y6t7JLw4NCXRYrZl2adJ+jUVTEDuHuQUHsFgRBEEGNLalwM3UrijG0Fv1Z9Mc61CUiWKbnbeYke41OQk1998731+tlaLje7QNfntP3w4/f8zyIyHoeTM9omNPU2UYDtVrNOj0Tl6l79z1sjmaBpmmcPHEcp9NZiMTuBrYuWFujo6OdY0cH6OzclbgTnUxsSaDXdKqVCsvLeQaO+Nnb1RUYD0cKmxeIoKqr/P6zwsJiFq+3B19vr+d2aELCkZjHVIDoqKsqbXYbiFAsFnG5XPT3+wEK4+Fo4P8T6IZArQvs2I3YbDaq1TLtDgf+vr76chOhicizDQUiGAKNNqNQqZRxGOfbd+958vQ5r14nKZVKAKdowPrvDupTKMovvmYynB4cxNuznzfJZOxmcGwKAGD4/LmNdiCslMuk0hm9+EOZzeXz7Ovuxu12DwGphrQWWCwwP/+Fz58+nr0xNnIhnc7g3LGdgwe8O0dGg0OmtyBiQVGUucezjx4C37PfspMLi0sc9vnqzzxu+jGAQ8Ae1sEdCkdl7sVLuXT5yodWHSvNpGhGyeVy8Z+Ksvv6tatnaIEVE24FRy8CDiBLC/4C3kjgJkXCw9gAAAAASUVORK5CYII=">
<img id="bomb"...
JavaScript
$(function () {
"use strict";
var ns = {};
ns.myCursor = $('#myCursor').attr('src');
ns.bomb = $('#bomb').attr('src');
ns.blueflag = $('#blueflag').attr('src');
ns.greenflag = $('#greenflag').attr('src');
ns.gold = $('#gold').attr('src');
ns.flame = $('#flame').attr('src');
ns.cursorRep = $('<img src="' + ns.myCursor + '" style="position:absolute;top:0;left:0;z-index:102;display:none;">');
ns.overlay = $('<div style="position:fixed;top:0;left:0;width:100%;height:100%;background:transparent;z-index:100;">');
$('body').append(ns.cursorRep);
ns.cursorX = 0;
ns.cursorY = 0;
ns.locked = false;
document.body.style.cursor = 'url(' + ns.myCursor + '), auto';
function getRandomInt(from, to) {
return Math.floor(Math.random() * (to - from + 1) + from);
}
$('body').mousemove(function (event) {
if (!ns.locked) {
ns.cursorX = event.clientX;
ns.cursorY = event.clientY;
}
});
(function () {
var flag = '<img src="' + ns.blueflag + '" class="iamagame" style="position:absolute;top:0;left:0;z-index:101;">',
flag_count = getRandomInt(5, 10),
i,
max_h = $(window).height() - 68,
max_w = $(window).width() - 68,
f,
bomb = getRandomInt(1, flag_count);
for (i = 1; i <= flag_count; i++) {
f = $(flag);
$.data(f[0], 'isChecked', false);
$.data(f[0], 'isBomb', (i === bomb));
f.click(function () {
var cache = $(this);
if ($.data(this, 'isBomb')) {
$('body').append(ns.overlay);
$(this).attr('src', ns.bomb);
ns.locked = true;
ns.cursorRep.css('top', ns.cursorY);
ns.cursorRep.css('left', ns.cursorX);
ns.cursorRep.show();
document.body.style.cursor = 'none';
...