Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active December 29, 2015 00:49
Show Gist options
  • Save joshuakfarrar/7588558 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/7588558 to your computer and use it in GitHub Desktop.
// Click the Invisible Cow hacks
// CTIC doesn't use jQuery, so selectors and triggering events are dirty funky native
// I initially tried simply $('#cow').click(); to no avail
// Instead, I wrote a function to simulate clicks and then we can click on the cow by passing its position to the function
function simulateClick(x, y) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent(
'click', true, true, window, 0,
0, 0, x, y, false, false,
false, false, 0, null
);
document.elementFromPoint(x, y).dispatchEvent(clickEvent);
}
// tada, you've hacked the cow. now go do other things.
simulateClick(find.cow.pos.x, find.cow.pos.y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment