Skip to content

Instantly share code, notes, and snippets.

@kwoktung
Last active June 8, 2018 01:49
Show Gist options
  • Select an option

  • Save kwoktung/be61e974ff947c3eb59346961e6e09a2 to your computer and use it in GitHub Desktop.

Select an option

Save kwoktung/be61e974ff947c3eb59346961e6e09a2 to your computer and use it in GitHub Desktop.
;(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()
})()
@kwoktung

kwoktung commented Jun 8, 2018

Copy link
Copy Markdown
Author

不同版本浏览器像素提取范围不一样,部分浏览器可能需要 (100, 100, 50, 10),脚本只是提供一个基本的思路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment