Last active
June 8, 2018 01:49
-
-
Save kwoktung/be61e974ff947c3eb59346961e6e09a2 to your computer and use it in GitHub Desktop.
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
;(function() { | |
var canvas = document.getElementsByClassName('runner-canvas')[0]; | |
var ctx = canvas.getContext('2d'); | |
function run(){ | |
var hit = false; | |
var data = ctx.getImageData(150,180,175,50).data | |
for(var i=3, len = data.length; i < len; i += 8) { | |
if (data[i] > 0) { | |
hit = true; | |
break; | |
} | |
} | |
if(hit) { | |
var event = new KeyboardEvent('keydown', { key: 'ArrowUp', keyCode: 38, location: 0 }); | |
document.dispatchEvent(event) | |
} | |
requestAnimationFrame(run) | |
} | |
run() | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
不同版本浏览器像素提取范围不一样,部分浏览器可能需要 (100, 100, 50, 10),脚本只是提供一个基本的思路