Skip to content

Instantly share code, notes, and snippets.

@huysentruitw
Created April 6, 2020 19:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huysentruitw/5db8c653f344a901872d7e39830e0af2 to your computer and use it in GitHub Desktop.
Save huysentruitw/5db8c653f344a901872d7e39830e0af2 to your computer and use it in GitHub Desktop.
chrome-offline-game
jump = () => {
const space = { bubbles: true, key: 'Space', keyCode: 32, charCode: 0 };
document.activeElement.dispatchEvent(new window.KeyboardEvent('keydown', space));
document.activeElement.dispatchEvent(new window.KeyboardEvent('keyup', space));
};
ctx = document.getElementsByClassName('runner-canvas')[0].getContext('2d');
detect = () => {
const data = ctx.getImageData(105, 125, 1, 1).data;
if (data[0] > 0) jump();
window.requestAnimationFrame(detect);
};
window.requestAnimationFrame(detect);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment