Created
April 6, 2020 19:38
-
-
Save huysentruitw/5db8c653f344a901872d7e39830e0af2 to your computer and use it in GitHub Desktop.
chrome-offline-game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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